From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDA1AA00C2; Wed, 22 Apr 2020 10:37:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B11DC1D16D; Wed, 22 Apr 2020 10:37:07 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id F3F6D4C98 for ; Wed, 22 Apr 2020 10:37:04 +0200 (CEST) IronPort-SDR: Y9uU+Q0bQhByMcM44D0Ev82qiJA81ZaW3L4B+r3ZIyz9D36bfqBiZr1ijsPYiztE1tvCFwB0ry lxCgfsqcvKZQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 01:37:03 -0700 IronPort-SDR: EmhbX13oPX5rlIrXXaQ/fEDE5tmN7PFjIz4Khsa8xFxMc6OUQqvREZB+QLBIg8mJcj0DqTmVoP exQ3CjWIoi6g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,413,1580803200"; d="scan'208";a="300860042" Received: from orsmsx110.amr.corp.intel.com ([10.22.240.8]) by FMSMGA003.fm.intel.com with ESMTP; 22 Apr 2020 01:37:03 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX110.amr.corp.intel.com (10.22.240.8) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 22 Apr 2020 01:37:03 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 22 Apr 2020 01:37:03 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 22 Apr 2020 01:37:02 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.173) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 22 Apr 2020 01:37:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=btOqRlwbG8cGrDFnT/si+PNSg2n9xIhtHJNKx28AmZ8aDi3FEk3yyTMIEurpwspYJiEJxiWS/INSIhendSdyUyc2BD4l3JQwMRtGfOqT0YCWviLdBt0UHZi/LVa/Xf6zd2e0s7D3HYwO3k9kqIacafb60hpblUNHTIzh+gw/C7gQmc0GfIlqdMBNYO9LBktlytDaEBJTNbnYDLRMw/DOTPKG6TS4DTHoyeJyh8I8TEaJzN9hFFhQ6VbSxBRzHjOgHNXX5/o/XfoqDgLeBUtFSXg9ZwHo0A6g59WoPXOFRPAD99Z4Q2T0dLuYmNtcjk4W40wiaQVQyWDCLOqxuek+dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7/k+Da2v81p4w/DtfGVdnvabz+twUUV7SLSeAliW31k=; b=XwR3hph6KKz7JBl4GOhqdiCB6YEo/QId0RecteRWv6V1BSQUVehiffi3WuRbNiU2D/rWMz3WKvzEdAzRyLixpZfZJzhT4IeSZ1RWCHBKom/33YWg2oqCIhFEACpATETsOovdIEekfybJ99HjSKvZ+amkK1a4xTnD5geHDUk/n2orI5TNgNUfsrXBZENW6eN/Dt5fck8E9l74Q0chc8ClDuK4EI+0m2LwSPl71P+m4buInflqQJDVzlTJtJsXvSGKhJxmz5iFPZWdvt/ETeDi0x3i1A63qJdtUK1iuNa8f7CLNmFjmkcWeD8n7WT8IzKWWFLL1xZOWdyI/oTjong1Dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7/k+Da2v81p4w/DtfGVdnvabz+twUUV7SLSeAliW31k=; b=rGlOmyW/202B4p0eMhjOklg/roNdeKT/12g77R37vEFPsCw3xXSKlsKbEnRS0pJ6QQvpbPvjTKkA5g21D4Ri7EQFY71yv06AxAW6twf9u4naQ7p7JdRzFDHmFBxVvvV++lc5akhw+gCb0vwHU57cOqcWbFBD1lyhiw9gJB3l6jA= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BYAPR11MB2903.namprd11.prod.outlook.com (2603:10b6:a03:89::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.26; Wed, 22 Apr 2020 08:36:59 +0000 Received: from BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f8cb:58cd:e958:fff4]) by BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f8cb:58cd:e958:fff4%6]) with mapi id 15.20.2937.012; Wed, 22 Apr 2020 08:36:59 +0000 From: "Ananyev, Konstantin" To: Honnappa Nagarahalli , "stephen@networkplumber.org" , "Medvedkin, Vladimir" , "dev@dpdk.org" CC: "david.marchand@redhat.com" , "ruifeng.wang@arm.com" , "dharmik.thakkar@arm.com" , "nd@arm.com" Thread-Topic: [PATCH v5 1/4] lib/rcu: add resource reclamation APIs Thread-Index: AQHWGFZ7f4xlrNcRz0OR9mekekxVqqiEzvLA Date: Wed, 22 Apr 2020 08:36:59 +0000 Message-ID: References: <20191001062917.35578-1-honnappa.nagarahalli@arm.com> <20200422033006.1124-1-honnappa.nagarahalli@arm.com> <20200422033006.1124-2-honnappa.nagarahalli@arm.com> In-Reply-To: <20200422033006.1124-2-honnappa.nagarahalli@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: spf=none (sender IP is ) smtp.mailfrom=konstantin.ananyev@intel.com; x-originating-ip: [192.198.151.168] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c543874d-c556-42d3-6298-08d7e69852f7 x-ms-traffictypediagnostic: BYAPR11MB2903: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-forefront-prvs: 03818C953D x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10019020)(39860400002)(376002)(136003)(396003)(366004)(346002)(76116006)(52536014)(64756008)(8936002)(66556008)(9686003)(66946007)(55016002)(86362001)(6506007)(66476007)(5660300002)(478600001)(81156014)(966005)(30864003)(8676002)(71200400001)(186003)(2906002)(66446008)(316002)(26005)(54906003)(7696005)(110136005)(33656002)(4326008)(579004); DIR:OUT; SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: n0ssj7JDFxcawerXUCXVPmtM1+5VA11Lidov+CvmlbqtCfI5LeupFYAIypoS3tuVmAxeC8P80jCtSo2LdpXWcoMB49m+yXEn1Rukv7OM2XRRAncDl3O2VWjYqJKRbFApp4V0kCByh4NIWKEjDGjVsipTUNIWKZCrs2OzuKWsnsSEqLEe+IlCFWvg4K83wIqkLlgWWQY4R72YgHXkQUvMyvvfqXHkV9blMuHKvsjAazdxNi6G8SFzvEsZOm1BqdaPgAb/Xb2RyH1u4Lb/J4J7klIHkTh99daT27PRpW8TekNyxtSortChgk27rPNQD6zzp1i4wRAaYRD7Ji/oMSkD2XY7K/42aA8g5NnM/0JcMR0nTDDMC5KKEtBqJ+YjXut7qFlWbnipSrjCSzWNXh8to4Zqb+FeiGpu8PdJHRfvWSqUcQiEC5sx/a5AjSEoRKEFC49uLOcQnbW9Ue3p6+IRZCWIn7D4fejgKaTwDarU+ssjgUPQC8sKlO4hQyNDogy31/ei5Ade3Mp0PvJ9Nc0SnQ== x-ms-exchange-antispam-messagedata: IHOy8bwhJjot+P2Ji3iBAypcpdQd3zkfXDNHtjEZl26LLgHrM5qPTrfL/yuorXmwfGQ16OZjsWeOclkPyOrELmtwPRRTNbqWIGoJvhmdh8fgpQ/5uPWETfHMAT8lpEFUNYAo9wc5FN/FIdhkSS0UXw== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c543874d-c556-42d3-6298-08d7e69852f7 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Apr 2020 08:36:59.3198 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ltSFZB5QxhM/HCz3WzUgLdBudldei5YtViLbQOAuybf/WR5lSzqHJ0zuuwb6X96M+o+KfKdk6PzbhS0OsNVscNFYJLRaxT5XatXrEiLDB8k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB2903 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v5 1/4] lib/rcu: add resource reclamation APIs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > Add resource reclamation APIs to make it simple for applications > and libraries to integrate rte_rcu library. >=20 > Signed-off-by: Honnappa Nagarahalli > Reviewed-by: Ola Liljedhal > Reviewed-by: Ruifeng Wang > Acked-by: Konstantin Ananyev > --- > lib/librte_rcu/Makefile | 2 +- > lib/librte_rcu/meson.build | 7 + > lib/librte_rcu/rcu_qsbr_pvt.h | 66 +++++++++ > lib/librte_rcu/rte_rcu_qsbr.c | 227 ++++++++++++++++++++++++++++- > lib/librte_rcu/rte_rcu_qsbr.h | 194 +++++++++++++++++++++++- > lib/librte_rcu/rte_rcu_version.map | 4 + > lib/meson.build | 6 +- > 7 files changed, 501 insertions(+), 5 deletions(-) > create mode 100644 lib/librte_rcu/rcu_qsbr_pvt.h >=20 > diff --git a/lib/librte_rcu/Makefile b/lib/librte_rcu/Makefile > index 728669975..553bca2ef 100644 > --- a/lib/librte_rcu/Makefile > +++ b/lib/librte_rcu/Makefile > @@ -7,7 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk > LIB =3D librte_rcu.a >=20 > CFLAGS +=3D $(WERROR_FLAGS) -I$(SRCDIR) -O3 > -LDLIBS +=3D -lrte_eal > +LDLIBS +=3D -lrte_eal -lrte_ring >=20 > EXPORT_MAP :=3D rte_rcu_version.map >=20 > diff --git a/lib/librte_rcu/meson.build b/lib/librte_rcu/meson.build > index c009ae4b7..3eb2ace17 100644 > --- a/lib/librte_rcu/meson.build > +++ b/lib/librte_rcu/meson.build > @@ -3,3 +3,10 @@ >=20 > sources =3D files('rte_rcu_qsbr.c') > headers =3D files('rte_rcu_qsbr.h') > + > +# for clang 32-bit compiles we need libatomic for 64-bit atomic ops > +if cc.get_id() =3D=3D 'clang' and dpdk_conf.get('RTE_ARCH_64') =3D=3D fa= lse > + ext_deps +=3D cc.find_library('atomic') > +endif > + As a nit - as Pavan patch is already integrated into mainline, this is not necessary any more, I think. Also noticed that most of make builds failed due to dependency problem: http://mails.dpdk.org/archives/test-report/2020-April/127765.html I can't reproduce it locally, but my guess that we need to move rcu above ring in this mk file: mk/rte.app.mk Probably something like that: diff --git a/mk/rte.app.mk b/mk/rte.app.mk index da12b9eec..8e5d023de 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -91,13 +91,13 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL) +=3D -lrte_= mempool _LDLIBS-$(CONFIG_RTE_LIBRTE_STACK) +=3D -lrte_stack _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING) +=3D -lrte_mempool_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_OCTEONTX2_MEMPOOL) +=3D -lrte_mempool_octeontx= 2 +_LDLIBS-$(CONFIG_RTE_LIBRTE_RCU) +=3D -lrte_rcu _LDLIBS-$(CONFIG_RTE_LIBRTE_RING) +=3D -lrte_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_PCI) +=3D -lrte_pci _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) +=3D -lrte_eal _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) +=3D -lrte_cmdline _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER) +=3D -lrte_reorder _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) +=3D -lrte_sched -_LDLIBS-$(CONFIG_RTE_LIBRTE_RCU) +=3D -lrte_rcu Apart from that - LGTM Acked-by: Konstantin Ananyev > +deps +=3D ['ring'] > diff --git a/lib/librte_rcu/rcu_qsbr_pvt.h b/lib/librte_rcu/rcu_qsbr_pvt.= h > new file mode 100644 > index 000000000..63f7a5fff > --- /dev/null > +++ b/lib/librte_rcu/rcu_qsbr_pvt.h > @@ -0,0 +1,66 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (c) 2020 Arm Limited > + */ > + > +#ifndef _RTE_RCU_QSBR_PVT_H_ > +#define _RTE_RCU_QSBR_PVT_H_ > + > +/** > + * This file is private to the RCU library. It should not be included > + * by the user of this library. > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > +#include > + > +#include "rte_rcu_qsbr.h" > + > +/* Defer queue structure. > + * This structure holds the defer queue. The defer queue is used to > + * hold the deleted entries from the data structure that are not > + * yet freed. > + */ > +struct rte_rcu_qsbr_dq { > + struct rte_rcu_qsbr *v; /**< RCU QSBR variable used by this queue.*/ > + struct rte_ring *r; /**< RCU QSBR defer queue. */ > + uint32_t size; > + /**< Number of elements in the defer queue */ > + uint32_t esize; > + /**< Size (in bytes) of data, including the token, stored on the > + * defer queue. > + */ > + uint32_t trigger_reclaim_limit; > + /**< Trigger automatic reclamation after the defer queue > + * has atleast these many resources waiting. > + */ > + uint32_t max_reclaim_size; > + /**< Reclaim at the max these many resources during auto > + * reclamation. > + */ > + rte_rcu_qsbr_free_resource_t free_fn; > + /**< Function to call to free the resource. */ > + void *p; > + /**< Pointer passed to the free function. Typically, this is the > + * pointer to the data structure to which the resource to free > + * belongs. > + */ > +}; > + > +/* Internal structure to represent the element on the defer queue. > + * Use alias as a character array is type casted to a variable > + * of this structure type. > + */ > +typedef struct { > + uint64_t token; /**< Token */ > + uint8_t elem[0]; /**< Pointer to user element */ > +} __attribute__((__may_alias__)) __rte_rcu_qsbr_dq_elem_t; > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_RCU_QSBR_PVT_H_ */ > diff --git a/lib/librte_rcu/rte_rcu_qsbr.c b/lib/librte_rcu/rte_rcu_qsbr.= c > index 2f3fad776..6a429d8b3 100644 > --- a/lib/librte_rcu/rte_rcu_qsbr.c > +++ b/lib/librte_rcu/rte_rcu_qsbr.c > @@ -1,6 +1,6 @@ > /* SPDX-License-Identifier: BSD-3-Clause > * > - * Copyright (c) 2018 Arm Limited > + * Copyright (c) 2018-2020 Arm Limited > */ >=20 > #include > @@ -18,8 +18,10 @@ > #include > #include > #include > +#include >=20 > #include "rte_rcu_qsbr.h" > +#include "rcu_qsbr_pvt.h" >=20 > /* Get the memory size of QSBR variable */ > size_t > @@ -270,6 +272,229 @@ rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v) > return 0; > } >=20 > +/* Create a queue used to store the data structure elements that can > + * be freed later. This queue is referred to as 'defer queue'. > + */ > +struct rte_rcu_qsbr_dq * > +rte_rcu_qsbr_dq_create(const struct rte_rcu_qsbr_dq_parameters *params) > +{ > + struct rte_rcu_qsbr_dq *dq; > + uint32_t qs_fifo_size; > + unsigned int flags; > + > + if (params =3D=3D NULL || params->free_fn =3D=3D NULL || > + params->v =3D=3D NULL || params->name =3D=3D NULL || > + params->size =3D=3D 0 || params->esize =3D=3D 0 || > + (params->esize % 4 !=3D 0)) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): Invalid input parameter\n", __func__); > + rte_errno =3D EINVAL; > + > + return NULL; > + } > + /* If auto reclamation is configured, reclaim limit > + * should be a valid value. > + */ > + if ((params->trigger_reclaim_limit <=3D params->size) && > + (params->max_reclaim_size =3D=3D 0)) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): Invalid input parameter, size =3D %u, trigger_reclaim_limit = =3D %u, max_reclaim_size =3D %u\n", > + __func__, params->size, params->trigger_reclaim_limit, > + params->max_reclaim_size); > + rte_errno =3D EINVAL; > + > + return NULL; > + } > + > + dq =3D rte_zmalloc(NULL, sizeof(struct rte_rcu_qsbr_dq), > + RTE_CACHE_LINE_SIZE); > + if (dq =3D=3D NULL) { > + rte_errno =3D ENOMEM; > + > + return NULL; > + } > + > + /* Decide the flags for the ring. > + * If MT safety is requested, use RTS for ring enqueue as most > + * use cases involve dq-enqueue happening on the control plane. > + * Ring dequeue is always HTS due to the possibility of revert. > + */ > + flags =3D RING_F_MP_RTS_ENQ; > + if (params->flags & RTE_RCU_QSBR_DQ_MT_UNSAFE) > + flags =3D RING_F_SP_ENQ; > + flags |=3D RING_F_MC_HTS_DEQ; > + /* round up qs_fifo_size to next power of two that is not less than > + * max_size. > + */ > + qs_fifo_size =3D rte_align32pow2(params->size + 1); > + /* Add token size to ring element size */ > + dq->r =3D rte_ring_create_elem(params->name, > + __RTE_QSBR_TOKEN_SIZE + params->esize, > + qs_fifo_size, SOCKET_ID_ANY, flags); > + if (dq->r =3D=3D NULL) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): defer queue create failed\n", __func__); > + rte_free(dq); > + return NULL; > + } > + > + dq->v =3D params->v; > + dq->size =3D params->size; > + dq->esize =3D __RTE_QSBR_TOKEN_SIZE + params->esize; > + dq->trigger_reclaim_limit =3D params->trigger_reclaim_limit; > + dq->max_reclaim_size =3D params->max_reclaim_size; > + dq->free_fn =3D params->free_fn; > + dq->p =3D params->p; > + > + return dq; > +} > + > +/* Enqueue one resource to the defer queue to free after the grace > + * period is over. > + */ > +int rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e) > +{ > + __rte_rcu_qsbr_dq_elem_t *dq_elem; > + uint32_t cur_size; > + > + if (dq =3D=3D NULL || e =3D=3D NULL) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): Invalid input parameter\n", __func__); > + rte_errno =3D EINVAL; > + > + return 1; > + } > + > + char data[dq->esize]; > + dq_elem =3D (__rte_rcu_qsbr_dq_elem_t *)data; > + /* Start the grace period */ > + dq_elem->token =3D rte_rcu_qsbr_start(dq->v); > + > + /* Reclaim resources if the queue size has hit the reclaim > + * limit. This helps the queue from growing too large and > + * allows time for reader threads to report their quiescent state. > + */ > + cur_size =3D rte_ring_count(dq->r); > + if (cur_size > dq->trigger_reclaim_limit) { > + rte_log(RTE_LOG_INFO, rte_rcu_log_type, > + "%s(): Triggering reclamation\n", __func__); > + rte_rcu_qsbr_dq_reclaim(dq, dq->max_reclaim_size, > + NULL, NULL, NULL); > + } > + > + /* Enqueue the token and resource. Generating the token and > + * enqueuing (token + resource) on the queue is not an > + * atomic operation. When the defer queue is shared by multiple > + * writers, this might result in tokens enqueued out of order > + * on the queue. So, some tokens might wait longer than they > + * are required to be reclaimed. > + */ > + memcpy(dq_elem->elem, e, dq->esize - __RTE_QSBR_TOKEN_SIZE); > + /* Check the status as enqueue might fail since the other threads > + * might have used up the freed space. > + * Enqueue uses the configured flags when the DQ was created. > + */ > + if (rte_ring_enqueue_elem(dq->r, data, dq->esize) !=3D 0) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): Enqueue failed\n", __func__); > + /* Note that the token generated above is not used. > + * Other than wasting tokens, it should not cause any > + * other issues. > + */ > + rte_log(RTE_LOG_INFO, rte_rcu_log_type, > + "%s(): Skipped enqueuing token =3D %"PRIu64"\n", > + __func__, dq_elem->token); > + > + rte_errno =3D ENOSPC; > + return 1; > + } > + > + rte_log(RTE_LOG_INFO, rte_rcu_log_type, > + "%s(): Enqueued token =3D %"PRIu64"\n", __func__, dq_elem->token); > + > + return 0; > +} > + > +/* Reclaim resources from the defer queue. */ > +int > +rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, > + unsigned int *freed, unsigned int *pending, > + unsigned int *available) > +{ > + uint32_t cnt; > + __rte_rcu_qsbr_dq_elem_t *dq_elem; > + > + if (dq =3D=3D NULL || n =3D=3D 0) { > + rte_log(RTE_LOG_ERR, rte_rcu_log_type, > + "%s(): Invalid input parameter\n", __func__); > + rte_errno =3D EINVAL; > + > + return 1; > + } > + > + cnt =3D 0; > + > + char data[dq->esize]; > + /* Check reader threads quiescent state and reclaim resources */ > + while (cnt < n && > + rte_ring_dequeue_bulk_elem_start(dq->r, &data, > + dq->esize, 1, available) !=3D 0) { > + dq_elem =3D (__rte_rcu_qsbr_dq_elem_t *)data; > + > + /* Reclaim the resource */ > + if (rte_rcu_qsbr_check(dq->v, dq_elem->token, false) !=3D 1) { > + rte_ring_dequeue_elem_finish(dq->r, 0); > + break; > + } > + rte_ring_dequeue_elem_finish(dq->r, 1); > + > + rte_log(RTE_LOG_INFO, rte_rcu_log_type, > + "%s(): Reclaimed token =3D %"PRIu64"\n", > + __func__, dq_elem->token); > + > + dq->free_fn(dq->p, dq_elem->elem, 1); > + > + cnt++; > + } > + > + rte_log(RTE_LOG_INFO, rte_rcu_log_type, > + "%s(): Reclaimed %u resources\n", __func__, cnt); > + > + if (freed !=3D NULL) > + *freed =3D cnt; > + if (pending !=3D NULL) > + *pending =3D rte_ring_count(dq->r); > + > + return 0; > +} > + > +/* Delete a defer queue. */ > +int > +rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq) > +{ > + unsigned int pending; > + > + if (dq =3D=3D NULL) { > + rte_log(RTE_LOG_DEBUG, rte_rcu_log_type, > + "%s(): Invalid input parameter\n", __func__); > + > + return 0; > + } > + > + /* Reclaim all the resources */ > + rte_rcu_qsbr_dq_reclaim(dq, ~0, NULL, &pending, NULL); > + if (pending !=3D 0) { > + rte_errno =3D EAGAIN; > + > + return 1; > + } > + > + rte_ring_free(dq->r); > + rte_free(dq); > + > + return 0; > +} > + > int rte_rcu_log_type; >=20 > RTE_INIT(rte_rcu_register) > diff --git a/lib/librte_rcu/rte_rcu_qsbr.h b/lib/librte_rcu/rte_rcu_qsbr.= h > index 0b5585925..e2fc7f83e 100644 > --- a/lib/librte_rcu/rte_rcu_qsbr.h > +++ b/lib/librte_rcu/rte_rcu_qsbr.h > @@ -1,5 +1,5 @@ > /* SPDX-License-Identifier: BSD-3-Clause > - * Copyright (c) 2018 Arm Limited > + * Copyright (c) 2018-2020 Arm Limited > */ >=20 > #ifndef _RTE_RCU_QSBR_H_ > @@ -34,6 +34,7 @@ extern "C" { > #include > #include > #include > +#include >=20 > extern int rte_rcu_log_type; >=20 > @@ -84,6 +85,7 @@ struct rte_rcu_qsbr_cnt { > #define __RTE_QSBR_CNT_THR_OFFLINE 0 > #define __RTE_QSBR_CNT_INIT 1 > #define __RTE_QSBR_CNT_MAX ((uint64_t)~0) > +#define __RTE_QSBR_TOKEN_SIZE sizeof(uint64_t) >=20 > /* RTE Quiescent State variable structure. > * This structure has two elements that vary in size based on the > @@ -114,6 +116,86 @@ struct rte_rcu_qsbr { > */ > } __rte_cache_aligned; >=20 > +/** > + * Call back function called to free the resources. > + * > + * @param p > + * Pointer provided while creating the defer queue > + * @param e > + * Pointer to the resource data stored on the defer queue > + * @param n > + * Number of resources to free. Currently, this is set to 1. > + * > + * @return > + * None > + */ > +typedef void (*rte_rcu_qsbr_free_resource_t)(void *p, void *e, unsigned = int n); > + > +#define RTE_RCU_QSBR_DQ_NAMESIZE RTE_RING_NAMESIZE > + > +/** > + * Various flags supported. > + */ > +/**< Enqueue and reclaim operations are multi-thread safe by default. > + * The call back functions registered to free the resources are > + * assumed to be multi-thread safe. > + * Set this flag is multi-thread safety is not required. > + */ > +#define RTE_RCU_QSBR_DQ_MT_UNSAFE 1 > + > +/** > + * Parameters used when creating the defer queue. > + */ > +struct rte_rcu_qsbr_dq_parameters { > + const char *name; > + /**< Name of the queue. */ > + uint32_t flags; > + /**< Flags to control API behaviors */ > + uint32_t size; > + /**< Number of entries in queue. Typically, this will be > + * the same as the maximum number of entries supported in the > + * lock free data structure. > + * Data structures with unbounded number of entries is not > + * supported currently. > + */ > + uint32_t esize; > + /**< Size (in bytes) of each element in the defer queue. > + * This has to be multiple of 4B. > + */ > + uint32_t trigger_reclaim_limit; > + /**< Trigger automatic reclamation after the defer queue > + * has atleast these many resources waiting. This auto > + * reclamation is triggered in rte_rcu_qsbr_dq_enqueue API > + * call. > + * If this is greater than 'size', auto reclamation is > + * not triggered. > + * If this is set to 0, auto reclamation is triggered > + * in every call to rte_rcu_qsbr_dq_enqueue API. > + */ > + uint32_t max_reclaim_size; > + /**< When automatic reclamation is enabled, reclaim at the max > + * these many resources. This should contain a valid value, if > + * auto reclamation is on. Setting this to 'size' or greater will > + * reclaim all possible resources currently on the defer queue. > + */ > + rte_rcu_qsbr_free_resource_t free_fn; > + /**< Function to call to free the resource. */ > + void *p; > + /**< Pointer passed to the free function. Typically, this is the > + * pointer to the data structure to which the resource to free > + * belongs. This can be NULL. > + */ > + struct rte_rcu_qsbr *v; > + /**< RCU QSBR variable to use for this defer queue */ > +}; > + > +/* RTE defer queue structure. > + * This structure holds the defer queue. The defer queue is used to > + * hold the deleted entries from the data structure that are not > + * yet freed. > + */ > +struct rte_rcu_qsbr_dq; > + > /** > * @warning > * @b EXPERIMENTAL: this API may change without prior notice > @@ -692,6 +774,116 @@ __rte_experimental > int > rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v); >=20 > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Create a queue used to store the data structure elements that can > + * be freed later. This queue is referred to as 'defer queue'. > + * > + * @param params > + * Parameters to create a defer queue. > + * @return > + * On success - Valid pointer to defer queue > + * On error - NULL > + * Possible rte_errno codes are: > + * - EINVAL - NULL parameters are passed > + * - ENOMEM - Not enough memory > + */ > +__rte_experimental > +struct rte_rcu_qsbr_dq * > +rte_rcu_qsbr_dq_create(const struct rte_rcu_qsbr_dq_parameters *params); > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Enqueue one resource to the defer queue and start the grace period. > + * The resource will be freed later after at least one grace period > + * is over. > + * > + * If the defer queue is full, it will attempt to reclaim resources. > + * It will also reclaim resources at regular intervals to avoid > + * the defer queue from growing too big. > + * > + * Multi-thread safety is provided as the defer queue configuration. > + * When multi-thread safety is requested, it is possible that the > + * resources are not stored in their order of deletion. This results > + * in resources being held in the defer queue longer than they should. > + * > + * @param dq > + * Defer queue to allocate an entry from. > + * @param e > + * Pointer to resource data to copy to the defer queue. The size of > + * the data to copy is equal to the element size provided when the > + * defer queue was created. > + * @return > + * On success - 0 > + * On error - 1 with rte_errno set to > + * - EINVAL - NULL parameters are passed > + * - ENOSPC - Defer queue is full. This condition can not happen > + * if the defer queue size is equal (or larger) than the > + * number of elements in the data structure. > + */ > +__rte_experimental > +int > +rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e); > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Free quesed resources from the defer queue. > + * > + * This API is multi-thread safe. > + * > + * @param dq > + * Defer queue to free an entry from. > + * @param n > + * Maximum number of resources to free. > + * @param freed > + * Number of resources that were freed. > + * @param pending > + * Number of resources pending on the defer queue. This number might n= ot > + * be acurate if multi-thread safety is configured. > + * @param available > + * Number of resources that can be added to the defer queue. > + * This number might not be acurate if multi-thread safety is configur= ed. > + * @return > + * On successful reclamation of at least 1 resource - 0 > + * On error - 1 with rte_errno set to > + * - EINVAL - NULL parameters are passed > + */ > +__rte_experimental > +int > +rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, > + unsigned int *freed, unsigned int *pending, unsigned int *available); > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + * > + * Delete a defer queue. > + * > + * It tries to reclaim all the resources on the defer queue. > + * If any of the resources have not completed the grace period > + * the reclamation stops and returns immediately. The rest of > + * the resources are not reclaimed and the defer queue is not > + * freed. > + * > + * @param dq > + * Defer queue to delete. > + * @return > + * On success - 0 > + * On error - 1 > + * Possible rte_errno codes are: > + * - EAGAIN - Some of the resources have not completed at least 1 grac= e > + * period, try again. > + */ > +__rte_experimental > +int > +rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_rcu/rte_rcu_version.map b/lib/librte_rcu/rte_rcu_= version.map > index f8b9ef2ab..dfac88a37 100644 > --- a/lib/librte_rcu/rte_rcu_version.map > +++ b/lib/librte_rcu/rte_rcu_version.map > @@ -8,6 +8,10 @@ EXPERIMENTAL { > rte_rcu_qsbr_synchronize; > rte_rcu_qsbr_thread_register; > rte_rcu_qsbr_thread_unregister; > + rte_rcu_qsbr_dq_create; > + rte_rcu_qsbr_dq_enqueue; > + rte_rcu_qsbr_dq_reclaim; > + rte_rcu_qsbr_dq_delete; >=20 > local: *; > }; > diff --git a/lib/meson.build b/lib/meson.build > index 63c17ee75..c28b8df83 100644 > --- a/lib/meson.build > +++ b/lib/meson.build > @@ -11,7 +11,9 @@ > libraries =3D [ > 'kvargs', # eal depends on kvargs > 'eal', # everything depends on eal > - 'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core > + 'ring', > + 'rcu', # rcu depends on ring > + 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core > 'cmdline', > 'metrics', # bitrate/latency stats depends on this > 'hash', # efd depends on this > @@ -22,7 +24,7 @@ libraries =3D [ > 'gro', 'gso', 'ip_frag', 'jobstats', > 'kni', 'latencystats', 'lpm', 'member', > 'power', 'pdump', 'rawdev', > - 'rcu', 'rib', 'reorder', 'sched', 'security', 'stack', 'vhost', > + 'rib', 'reorder', 'sched', 'security', 'stack', 'vhost', > # ipsec lib depends on net, crypto and security > 'ipsec', > #fib lib depends on rib > -- > 2.17.1