From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0054.outbound.protection.outlook.com [157.56.110.54]) by dpdk.org (Postfix) with ESMTP id 42DFE530F for ; Tue, 24 May 2016 17:35:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Qs98qisdvW/vSEEkSz2iJQtMUjyYkPT85AolVcErm44=; b=iwnRheA77XFa9vMyU1EgMRwc+TAt6oXS8ITd3rzd/rrdsf/53qRyvgF1fxhYWdd7OcvMyr2qJDThCaGfOcqFt2XZvQGXpc8iGCDAY4/JBAkeyvRFkkKLyJ5A89+YgAY+uMGnBfzs2OmdIOWBdpEZQOUEwJQPXwNPDxOytP9PYHc= Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost.localdomain (111.93.218.67) by CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) with Microsoft SMTP Server (TLS) id 15.1.497.12; Tue, 24 May 2016 15:35:33 +0000 Date: Tue, 24 May 2016 21:05:12 +0530 From: Jerin Jacob To: David Hunt CC: , , , Message-ID: <20160524153509.GA11249@localhost.localdomain> References: <1460642270-8803-1-git-send-email-olivier.matz@6wind.com> <1463665501-18325-1-git-send-email-david.hunt@intel.com> <1463665501-18325-2-git-send-email-david.hunt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1463665501-18325-2-git-send-email-david.hunt@intel.com> User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: PN1PR01CA0050.INDPRD01.PROD.OUTLOOK.COM (10.164.136.150) To CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) X-MS-Office365-Filtering-Correlation-Id: c9404ffc-ef2c-4cb6-1bcf-08d383e90d08 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 2:oB45SuOVv9sVJyIBJ92+SGVkCdm61XQ7Oc9dHjHc6uH7N18SUXblfMShgk4LUCYGSqPZSH2cs0Of2YFbkRHT8mAFVIuhPcvLMdhKS07Ln5khuj6WdR+KFF2VhRFdkrH0oPnDXqFG4+QbvX60mp+IRP/Y0faSejcaTvp5U20Go8VYz7JiO6k6V8QG5ay3YLpW; 3:D/H3rTClFvrZ8rK6TuJO6YeMRN3FQqYX0JwNXmQPnZcbkuyf9edF94Cr3RZqCHZJofBI6fOBYKXVDVHzsTPf9PS8usbKViIF0roDFL46SZgDKf9haP2wSGjdF0AKY4hY; 25:EEqMTROrME6orfCtsDTeJaGWbndWDXvvur2rKJR1hO7OUE9bbL+fI78xuaxOZK028qLoOoV6xLX7SDSEUKakkGF1L0Vt6i1Xi+/zs9NHco2NYSzOD5S7FoBq2GIVmYCDSxN77jZVdwVWlCQNOofi3iWCjv2mnWF4TSY61QT2dfxXBh1UzSTByWdeM9/Jp6nG/TZ+jcPJEOuarDgwPOlHUNXkE+OqrBs/e4Xj32iYn0dXjdLMQagXPC4CK4RH7gEvb1cKLNrzOWQZNgTcmLuGzTfk+SIxS8b0A6th3h96LWfYNHjmjpuOapS6WaPh2MW7JI596bRfd7UFodqrx6craRCHtjgZhUPy3ClT4IBxr3afm+rXIY/PA5WI12pTR7w/vPsrj15LnO0EJnvQOD/jJuFsS9c5xveAMT88np4WxqU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 20:r8LaEMRmgKzAx6kBmptPElgqyCydk6Bc1sKW+Y1gwUVOj7mj6FQ9AgSvwSlyTOKR88w2tkYGAQVexa/ok0x7Q7wx4WGYKAsWEdIHZAl0GDcxI/Ok9YgCgyVBsV0Pcw8wbZb7dc60gxXHQIMX21x9VTZsiai1QgUcgCiwfithD+m3/bujavmHvrJ822Dtgj4RBnrnMTacHdPcKHg4Ns2i3bYUd/m0JqEcFJMca3ESvgqcoHK57wGAsGUeAlOYGVagtPNgyMVn/LY3vbPHUvTJflWN/wdoRvfl3fxzbKuyFRn5/OwnzvDrP3swLZ5zPa42Knn9lwgyHGB7VzhQv6Iv6bjRDZYg6yky7ckDIpI7n8qvvL8ePf/+tyf560U8vLeDh6z1+DPVGuAC1FY5SEvuWTI3veYLfGy+KzpJ4RNI27Nv2D4qzd9QNv9msnWbnUbJ1q4VA4zJxVB1ey21/OStxohdLDwHyK5p0ta8O/EO0jcocbwDmt9uFSs0Xlkkm3IcQlfov7/7OHFX43cVrK2SxfUaQ5Z/500Fno8i5QlObcW5g087MUKObAHx8RwX1oxz4zHp5IIB4E+Xis52sX0ZWZglMp6Gx8i549dcEgGU9XQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:CY1PR0701MB1725; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 4:tLZvoSny6SqLbac2YuoKKrmav82wMG2Hfl0L2ZgDANH0Gw/M3mt0pesQgZdqqlRD2D43utMBOikraS6/ZJNOocoz/TP9g4lXEXrzhXgQI5pB6o2CuRdFPPuK8kiG4XL5gS2547MFoFBohzZRBrklNEpTrdMmnzl66a4y0IoQ5zLCmivIxsz8bl773l9TwKumBn0oHpY9Gep3mGKnZeV+HTKsC3/e3NIqXa7D9ilafgGQd06c4xA/TWnfqfxn3pw5YgQFNV9L5+XUGzZAKBzrRpewd2EbVPbloh4V+xF/Sl+1EoIho4SY/pm9Fjt6Tqz2S0+noTxFe6VclWhXaK+Enkmow30a/yndvoyKZMwpE8Bl+fQOQU/bFKKP6AMvCidy X-Forefront-PRVS: 09525C61DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(24454002)(51234002)(5008740100001)(42186005)(15395725005)(189998001)(4001350100001)(92566002)(5009440100003)(19580395003)(83506001)(19580405001)(81166006)(5004730100002)(110136002)(2950100001)(586003)(15975445007)(23726003)(1076002)(77096005)(66066001)(6116002)(3846002)(33656002)(8676002)(47776003)(61506002)(575784001)(54356999)(9686002)(46406003)(76176999)(50986999)(2906002)(97756001)(4326007)(50466002)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0701MB1725; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0701MB1725; 23:Hak6ZFiOiygoWKIIvj5YQ+jJhXQwNywIvwjcP0g?= =?us-ascii?Q?GZHMLUVDrm04IHdlkqeasgJ0RtLvsEVAKopoA33Q9hFuK+OAeyIHcX+5/zIg?= =?us-ascii?Q?qDPL2DbLan2/K2kSm6vwwJkomzr3IasCPyvW8OhPbjWcHUw7lCNE3R86BMB6?= =?us-ascii?Q?QQnkyNjb4OK8BzA5DqIt9iqtKAWRvtqhz1QRGGJbAjy5WFgRxlPDNEiVgOzV?= =?us-ascii?Q?n12gnNj7gOR4PhKk+2Y0oIjb8jCRtsbRyPdi/f+Va9ZLn/8tMcJ31w5jahLH?= =?us-ascii?Q?NBUuYDxQ6aurrRuaqNGH6Qsd2jmYYiwFbki4uWxVTX2Qj28G6lLq8ITZQ/x1?= =?us-ascii?Q?kl5iaN4lw/QadMsyWD9cC2P1Fao25sLOm1/pRy38Y/AurL/Laay3Oyish3Mp?= =?us-ascii?Q?wV9ina1SGcIBTItSrbda+C2X8RaEW6oFrwZnAnPz4Co4uarpG4u9t3HWv/8J?= =?us-ascii?Q?cUOJSLGuofkh1kVxB00dXImk+qckR9VIrF6SWNT1QwC0qpLiywA8z1rMDI2E?= =?us-ascii?Q?vKnYG7czZ+rbQVBEfItj17nbcPrSgWg670X+PZchI2IoW5BZwik9KloNXB5i?= =?us-ascii?Q?3+3eCDfnENnk0UhmvpxJWiv/xayzbPA9mSZ4hiHIKvXidLTfII7z7bCeEOmZ?= =?us-ascii?Q?+5GDwJfFSnv0Zll5eAcgWeaKxrGEGCvXbLUltH4vbq1t8dqCGcG8jfqjmlm3?= =?us-ascii?Q?1VIXr+P3nLZmgkUBHb94pCSD/1lOyq7hLG0TRp7/3aeAyUnzHx8uX18wdscX?= =?us-ascii?Q?b2a7MUW3mwDHvdn3wSEgdjcnhv3j2aixuQCl9z5JufMBNXgQTY3FUNbJxz3A?= =?us-ascii?Q?Q+H0/dTZ+2rJs8qqSrNzMunl17Pc0IksOhaSbKGr1kZMvSFl+fSgZSOSpRuF?= =?us-ascii?Q?vy8kGQX27kLQoa27vIuYEQMQfg9wCFgXo2xlFypo7jr+b5ETGyxfWTJq6Gdm?= =?us-ascii?Q?i8vPVrLQuyz603mFqCKMDc+/Zt3N570NhZnmiX6/+Rj1YSCZS7K8xJInUgts?= =?us-ascii?Q?3luqsKVlY62mcFr6i/fOb/aXBKCfjY0SQnL2LHHsEOQq2C6L52u7BUMsSwA7?= =?us-ascii?Q?qOc2Pd1mW/yWs4Pv2i19zHPPIolFtC0mYg2hO0zn/zoAn5x/lwTB4IEFSoX5?= =?us-ascii?Q?OI8pxWa9W40c=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 5:ox6P7XiIhigM4acIpHGpB9qJuJKXulJwgNVM1Vlj0erKsE05nd/HtA6Wh6G4V8pWNGKAG4oprhXkl/yoBgYbRtrDEXl4Avm8TtVci6H+/I9hRCWE8TnTB6uWD6v5reh/c0kT492DqPawQqpSldVohw==; 24:B+8+FIx+5y7jbKwC7OGNCoCCrRoCWeaWTInf63KjkpcWKfKXHmGj8H3rYNfnqTi0zlTQHVjV29VrQebIACjPLBG1JcpsAIQsQScLllAWdXo=; 7:qIDEl+TLPI+Gkh4lsIZD+Rt9sB0Zv4Q8RsZ07Yp7p4ebxkD/AFX97AdW5Wan2tEhHSIXMTV/mm9k8egO07je5APqTibOE6pIiX1oUoN3m/+xQpuP7ZPDtape/hrWsYa2rT5BlhadssPVdh+/KHg7j4N7iKlpFC9uju1Orf/F75wQIGgR5LCy5QJCrNKCv9+v SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2016 15:35:33.9093 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1725 Subject: Re: [dpdk-dev] [PATCH v5 1/3] mempool: support external handler X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2016 15:35:38 -0000 On Thu, May 19, 2016 at 02:44:59PM +0100, David Hunt wrote: > Until now, the objects stored in mempool mempool were internally stored a > ring. This patch introduce the possibility to register external handlers > replacing the ring. > > The default behavior remains unchanged, but calling the new function > rte_mempool_set_handler() right after rte_mempool_create_empty() allows to > change the handler that will be used when populating the mempool. > > v5 changes: rebasing on top of 35 patch set mempool work. > > Signed-off-by: David Hunt > Signed-off-by: Olivier Matz > --- > app/test/test_mempool_perf.c | 1 - > lib/librte_mempool/Makefile | 2 + > lib/librte_mempool/rte_mempool.c | 73 ++++------ > lib/librte_mempool/rte_mempool.h | 212 +++++++++++++++++++++++++---- > lib/librte_mempool/rte_mempool_default.c | 147 ++++++++++++++++++++ > lib/librte_mempool/rte_mempool_handler.c | 139 +++++++++++++++++++ > lib/librte_mempool/rte_mempool_version.map | 4 + > 7 files changed, 506 insertions(+), 72 deletions(-) > create mode 100644 lib/librte_mempool/rte_mempool_default.c > create mode 100644 lib/librte_mempool/rte_mempool_handler.c > > diff --git a/app/test/test_mempool_perf.c b/app/test/test_mempool_perf.c > index cdc02a0..091c1df 100644 > --- a/app/test/test_mempool_perf.c > +++ b/app/test/test_mempool_perf.c > @@ -161,7 +161,6 @@ per_lcore_mempool_test(__attribute__((unused)) void *arg) > n_get_bulk); > if (unlikely(ret < 0)) { > rte_mempool_dump(stdout, mp); > - rte_ring_dump(stdout, mp->ring); > /* in this case, objects are lost... */ > return -1; > } > diff --git a/lib/librte_mempool/Makefile b/lib/librte_mempool/Makefile > index 43423e0..f19366e 100644 > --- a/lib/librte_mempool/Makefile > +++ b/lib/librte_mempool/Makefile > @@ -42,6 +42,8 @@ LIBABIVER := 2 > > # all source are stored in SRCS-y > SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c > +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_handler.c > +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c > # install includes > SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h > > diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c > index 1ab6701..6ec2b3f 100644 > --- a/lib/librte_mempool/rte_mempool.c > +++ b/lib/librte_mempool/rte_mempool.c > @@ -148,7 +148,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, phys_addr_t physaddr) > #endif > > /* enqueue in ring */ > - rte_ring_sp_enqueue(mp->ring, obj); > + rte_mempool_ext_put_bulk(mp, &obj, 1); > } > > /* call obj_cb() for each mempool element */ > @@ -300,40 +300,6 @@ rte_mempool_xmem_usage(__rte_unused void *vaddr, uint32_t elt_num, > return (size_t)paddr_idx << pg_shift; > } > > -/* create the internal ring */ > -static int > -rte_mempool_ring_create(struct rte_mempool *mp) > -{ > - int rg_flags = 0, ret; > - char rg_name[RTE_RING_NAMESIZE]; > - struct rte_ring *r; > - > - ret = snprintf(rg_name, sizeof(rg_name), > - RTE_MEMPOOL_MZ_FORMAT, mp->name); > - if (ret < 0 || ret >= (int)sizeof(rg_name)) > - return -ENAMETOOLONG; > - > - /* ring flags */ > - if (mp->flags & MEMPOOL_F_SP_PUT) > - rg_flags |= RING_F_SP_ENQ; > - if (mp->flags & MEMPOOL_F_SC_GET) > - rg_flags |= RING_F_SC_DEQ; > - > - /* Allocate the ring that will be used to store objects. > - * Ring functions will return appropriate errors if we are > - * running as a secondary process etc., so no checks made > - * in this function for that condition. > - */ > - r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1), > - mp->socket_id, rg_flags); > - if (r == NULL) > - return -rte_errno; > - > - mp->ring = r; > - mp->flags |= MEMPOOL_F_RING_CREATED; > - return 0; > -} > - > /* free a memchunk allocated with rte_memzone_reserve() */ > static void > rte_mempool_memchunk_mz_free(__rte_unused struct rte_mempool_memhdr *memhdr, > @@ -351,7 +317,7 @@ rte_mempool_free_memchunks(struct rte_mempool *mp) > void *elt; > > while (!STAILQ_EMPTY(&mp->elt_list)) { > - rte_ring_sc_dequeue(mp->ring, &elt); > + rte_mempool_ext_get_bulk(mp, &elt, 1); > (void)elt; > STAILQ_REMOVE_HEAD(&mp->elt_list, next); > mp->populated_size--; > @@ -380,15 +346,18 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, > unsigned i = 0; > size_t off; > struct rte_mempool_memhdr *memhdr; > - int ret; > > /* create the internal ring if not already done */ > if ((mp->flags & MEMPOOL_F_RING_CREATED) == 0) { > - ret = rte_mempool_ring_create(mp); > - if (ret < 0) > - return ret; > + rte_errno = 0; > + mp->pool = rte_mempool_ext_alloc(mp); > + if (mp->pool == NULL) { > + if (rte_errno == 0) > + return -EINVAL; > + else > + return -rte_errno; > + } > } > - > /* mempool is already populated */ > if (mp->populated_size >= mp->size) > return -ENOSPC; > @@ -700,7 +669,7 @@ rte_mempool_free(struct rte_mempool *mp) > rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); > > rte_mempool_free_memchunks(mp); > - rte_ring_free(mp->ring); > + rte_mempool_ext_free(mp); > rte_memzone_free(mp->mz); > } > > @@ -812,6 +781,20 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, > RTE_PTR_ADD(mp, MEMPOOL_HEADER_SIZE(mp, 0)); > > te->data = mp; > + > + /* > + * Since we have 4 combinations of the SP/SC/MP/MC examine the flags to > + * set the correct index into the handler table. > + */ > + if (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET)) > + rte_mempool_set_handler(mp, "ring_sp_sc"); > + else if (flags & MEMPOOL_F_SP_PUT) > + rte_mempool_set_handler(mp, "ring_sp_mc"); > + else if (flags & MEMPOOL_F_SC_GET) > + rte_mempool_set_handler(mp, "ring_mp_sc"); > + else > + rte_mempool_set_handler(mp, "ring_mp_mc"); IMO, We should decouple the implementation specific flags of _a_ external pool manager implementation from the generic rte_mempool_create_empty function as going further when we introduce new flags for custom HW accelerated external pool manager then this common code will be bloated. > + > rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); > TAILQ_INSERT_TAIL(mempool_list, te, next); > rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); > @@ -927,7 +910,7 @@ rte_mempool_count(const struct rte_mempool *mp) > unsigned count; > unsigned lcore_id; > > - count = rte_ring_count(mp->ring); > + count = rte_mempool_ext_get_count(mp); > > if (mp->cache_size == 0) > return count; > @@ -1120,7 +1103,7 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp) > > fprintf(f, "mempool <%s>@%p\n", mp->name, mp); > fprintf(f, " flags=%x\n", mp->flags); > - fprintf(f, " ring=<%s>@%p\n", mp->ring->name, mp->ring); > + fprintf(f, " pool=%p\n", mp->pool); > fprintf(f, " phys_addr=0x%" PRIx64 "\n", mp->mz->phys_addr); > fprintf(f, " nb_mem_chunks=%u\n", mp->nb_mem_chunks); > fprintf(f, " size=%"PRIu32"\n", mp->size); > @@ -1141,7 +1124,7 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp) > } > > cache_count = rte_mempool_dump_cache(f, mp); > - common_count = rte_ring_count(mp->ring); > + common_count = rte_mempool_ext_get_count(mp); > if ((cache_count + common_count) > mp->size) > common_count = mp->size - cache_count; > fprintf(f, " common_pool_count=%u\n", common_count); > diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h > index 60339bd..ed2c110 100644 > --- a/lib/librte_mempool/rte_mempool.h > +++ b/lib/librte_mempool/rte_mempool.h > @@ -67,6 +67,7 @@ > #include > #include > > +#include > #include > #include > #include > @@ -203,7 +204,15 @@ struct rte_mempool_memhdr { > */ > struct rte_mempool { > char name[RTE_MEMPOOL_NAMESIZE]; /**< Name of mempool. */ > - struct rte_ring *ring; /**< Ring to store objects. */ > + void *pool; /**< Ring or ext-pool to store objects. */ > + /** > + * Index into the array of structs containing callback fn pointers. > + * We're using an index here rather than pointers to the callbacks > + * to facilitate any secondary processes that may want to use > + * this mempool. Any function pointers stored in the mempool > + * directly would not be valid for secondary processes. > + */ > + int32_t handler_idx; > const struct rte_memzone *mz; /**< Memzone where pool is allocated */ > int flags; /**< Flags of the mempool. */ > int socket_id; /**< Socket id passed at mempool creation. */ > @@ -325,6 +334,175 @@ void rte_mempool_check_cookies(const struct rte_mempool *mp, > #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0) > #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */ > > +#define RTE_MEMPOOL_HANDLER_NAMESIZE 32 /**< Max length of handler name. */ > + > +/** Allocate the external pool. */ > +typedef void *(*rte_mempool_alloc_t)(struct rte_mempool *mp); > + > +/** Free the external pool. */ > +typedef void (*rte_mempool_free_t)(void *p); > + > +/** Put an object in the external pool. */ > +typedef int (*rte_mempool_put_t)(void *p, void * const *obj_table, unsigned n); > + > +/** Get an object from the external pool. */ > +typedef int (*rte_mempool_get_t)(void *p, void **obj_table, unsigned n); > + > +/** Return the number of available objects in the external pool. */ > +typedef unsigned (*rte_mempool_get_count)(void *p); > + > +/** Structure defining a mempool handler. */ > +struct rte_mempool_handler { > + char name[RTE_MEMPOOL_HANDLER_NAMESIZE]; /**< Name of mempool handler */ > + rte_mempool_alloc_t alloc; /**< Allocate the external pool. */ > + rte_mempool_free_t free; /**< Free the external pool. */ > + rte_mempool_put_t put; /**< Put an object. */ > + rte_mempool_get_t get; /**< Get an object. */ > + rte_mempool_get_count get_count; /**< Get the number of available objs. */ > +} __rte_cache_aligned; > + > +#define RTE_MEMPOOL_MAX_HANDLER_IDX 16 /**< Max number of registered handlers */ > + > +/** Structure storing the table of registered handlers. */ > +struct rte_mempool_handler_table { > + rte_spinlock_t sl; /**< Spinlock for add/delete. */ > + uint32_t num_handlers; /**< Number of handlers in the table. */ > + /** Storage for all possible handlers. */ > + struct rte_mempool_handler handler[RTE_MEMPOOL_MAX_HANDLER_IDX]; > +}; add __rte_cache_aligned to this structure to avoid "handler" memory cacheline being shared with other variables > + > +/** Array of registered handlers */ > +extern struct rte_mempool_handler_table rte_mempool_handler_table; > + > +/** > + * @internal Get the mempool handler from its index. > + * > + * @param handler_idx > + * The index of the handler in the handler table. It must be a valid > + * index: (0 <= idx < num_handlers). > + * @return > + * The pointer to the handler in the table. > + */ > +static struct rte_mempool_handler * inline? > +rte_mempool_handler_get(int handler_idx) > +{ > + return &rte_mempool_handler_table.handler[handler_idx]; > +} > + > +/** > + * @internal wrapper for external mempool manager alloc callback. > + * > + * @param mp > + * Pointer to the memory pool. > + * @return > + * The opaque pointer to the external pool. > + */ > +void * > +rte_mempool_ext_alloc(struct rte_mempool *mp); > + > +/** > + * @internal wrapper for external mempool manager get callback. > + * > + * @param mp > + * Pointer to the memory pool. > + * @param obj_table > + * Pointer to a table of void * pointers (objects). > + * @param n > + * Number of objects to get. > + * @return > + * - 0: Success; got n objects. > + * - <0: Error; code of handler get function. > + */ > +static inline int > +rte_mempool_ext_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n) > +{ > + struct rte_mempool_handler *handler; > + > + handler = rte_mempool_handler_get(mp->handler_idx); > + return handler->get(mp->pool, obj_table, n); > +} > + > +/** > + * @internal wrapper for external mempool manager put callback. > + * > + * @param mp > + * Pointer to the memory pool. > + * @param obj_table > + * Pointer to a table of void * pointers (objects). > + * @param n > + * Number of objects to put. > + * @return > + * - 0: Success; n objects supplied. > + * - <0: Error; code of handler put function. > + */ > +static inline int > +rte_mempool_ext_put_bulk(struct rte_mempool *mp, void * const *obj_table, > + unsigned n) > +{ > + struct rte_mempool_handler *handler; > + > + handler = rte_mempool_handler_get(mp->handler_idx); > + return handler->put(mp->pool, obj_table, n); > +} > + > +/** > + * @internal wrapper for external mempool manager get_count callback. > + * > + * @param mp > + * Pointer to the memory pool. > + * @return > + * The number of available objects in the external pool. > + */ > +unsigned > +rte_mempool_ext_get_count(const struct rte_mempool *mp); > + > +/** > + * @internal wrapper for external mempool manager free callback. > + * > + * @param mp > + * Pointer to the memory pool. > + */ > +void > +rte_mempool_ext_free(struct rte_mempool *mp); > + > +/** > + * Set the handler of a mempool > + * > + * This can only be done on a mempool that is not populated, i.e. just after > + * a call to rte_mempool_create_empty(). > + * > + * @param mp > + * Pointer to the memory pool. > + * @param name > + * Name of the handler. > + * @return > + * - 0: Sucess; the new handler is configured. > + * - <0: Error (errno) > + */ > +int > +rte_mempool_set_handler(struct rte_mempool *mp, const char *name); > + > +/** > + * Register an external pool handler. > + * > + * @param h > + * Pointer to the external pool handler > + * @return > + * - >=0: Sucess; return the index of the handler in the table. > + * - <0: Error (errno) > + */ > +int rte_mempool_handler_register(struct rte_mempool_handler *h); > + > +/** > + * Macro to statically register an external pool handler. > + */ > +#define MEMPOOL_REGISTER_HANDLER(h) \ > + void mp_hdlr_init_##h(void); \ > + void __attribute__((constructor, used)) mp_hdlr_init_##h(void) \ > + { \ > + rte_mempool_handler_register(&h); \ > + } > + > /** > * An object callback function for mempool. > * > @@ -736,7 +914,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp); > */ > static inline void __attribute__((always_inline)) > __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table, > - unsigned n, int is_mp) > + unsigned n, __rte_unused int is_mp) > { > struct rte_mempool_cache *cache; > uint32_t index; > @@ -774,7 +952,7 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table, > cache->len += n; > > if (cache->len >= flushthresh) { > - rte_ring_mp_enqueue_bulk(mp->ring, &cache->objs[cache_size], > + rte_mempool_ext_put_bulk(mp, &cache->objs[cache_size], > cache->len - cache_size); > cache->len = cache_size; > } > @@ -782,26 +960,10 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table, > return; > > ring_enqueue: > - > /* push remaining objects in ring */ > -#ifdef RTE_LIBRTE_MEMPOOL_DEBUG > - if (is_mp) { > - if (rte_ring_mp_enqueue_bulk(mp->ring, obj_table, n) < 0) > - rte_panic("cannot put objects in mempool\n"); > - } > - else { > - if (rte_ring_sp_enqueue_bulk(mp->ring, obj_table, n) < 0) > - rte_panic("cannot put objects in mempool\n"); > - } > -#else > - if (is_mp) > - rte_ring_mp_enqueue_bulk(mp->ring, obj_table, n); > - else > - rte_ring_sp_enqueue_bulk(mp->ring, obj_table, n); > -#endif > + rte_mempool_ext_put_bulk(mp, obj_table, n); > } > > - > /** > * Put several objects back in the mempool (multi-producers safe). > * > @@ -922,7 +1084,7 @@ rte_mempool_put(struct rte_mempool *mp, void *obj) > */ > static inline int __attribute__((always_inline)) > __mempool_get_bulk(struct rte_mempool *mp, void **obj_table, > - unsigned n, int is_mc) > + unsigned n, __rte_unused int is_mc) > { > int ret; > struct rte_mempool_cache *cache; > @@ -945,7 +1107,8 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table, > uint32_t req = n + (cache_size - cache->len); > > /* How many do we require i.e. number to fill the cache + the request */ > - ret = rte_ring_mc_dequeue_bulk(mp->ring, &cache->objs[cache->len], req); > + ret = rte_mempool_ext_get_bulk(mp, This makes inline function to a function pointer. Nothing wrong in that. However, Do you see any performance drop with "local cache" only use case? http://dpdk.org/dev/patchwork/patch/12993/ > + &cache->objs[cache->len], req); > if (unlikely(ret < 0)) { > /* > * In the offchance that we are buffer constrained, > @@ -972,10 +1135,7 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table, > ring_dequeue: > > /* get remaining objects from ring */ > - if (is_mc) > - ret = rte_ring_mc_dequeue_bulk(mp->ring, obj_table, n); > - else > - ret = rte_ring_sc_dequeue_bulk(mp->ring, obj_table, n); > + ret = rte_mempool_ext_get_bulk(mp, obj_table, n); > > if (ret < 0) > __MEMPOOL_STAT_ADD(mp, get_fail, n); > diff --git a/lib/librte_mempool/rte_mempool_default.c b/lib/librte_mempool/rte_mempool_default.c > new file mode 100644 > index 0000000..a6ac65a > --- /dev/null > +++ b/lib/librte_mempool/rte_mempool_default.c > @@ -0,0 +1,147 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Intel Corporation nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +#include > +#include > +#include > + > +static int > +common_ring_mp_put(void *p, void * const *obj_table, unsigned n) > +{ > + return rte_ring_mp_enqueue_bulk((struct rte_ring *)p, obj_table, n); > +} > + > +static int > +common_ring_sp_put(void *p, void * const *obj_table, unsigned n) > +{ > + return rte_ring_sp_enqueue_bulk((struct rte_ring *)p, obj_table, n); > +} > + > +static int > +common_ring_mc_get(void *p, void **obj_table, unsigned n) > +{ > + return rte_ring_mc_dequeue_bulk((struct rte_ring *)p, obj_table, n); > +} > + > +static int > +common_ring_sc_get(void *p, void **obj_table, unsigned n) > +{ > + return rte_ring_sc_dequeue_bulk((struct rte_ring *)p, obj_table, n); > +} > + > +static unsigned > +common_ring_get_count(void *p) > +{ > + return rte_ring_count((struct rte_ring *)p); > +} > + > + > +static void * > +common_ring_alloc(struct rte_mempool *mp) > +{ > + int rg_flags = 0, ret; > + char rg_name[RTE_RING_NAMESIZE]; > + struct rte_ring *r; > + > + ret = snprintf(rg_name, sizeof(rg_name), > + RTE_MEMPOOL_MZ_FORMAT, mp->name); > + if (ret < 0 || ret >= (int)sizeof(rg_name)) { > + rte_errno = ENAMETOOLONG; > + return NULL; > + } > + > + /* ring flags */ > + if (mp->flags & MEMPOOL_F_SP_PUT) > + rg_flags |= RING_F_SP_ENQ; > + if (mp->flags & MEMPOOL_F_SC_GET) > + rg_flags |= RING_F_SC_DEQ; > + > + /* Allocate the ring that will be used to store objects. > + * Ring functions will return appropriate errors if we are > + * running as a secondary process etc., so no checks made > + * in this function for that condition. */ > + r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1), > + mp->socket_id, rg_flags); > + > + return r; > +} > + > +static void > +common_ring_free(void *p) > +{ > + rte_ring_free((struct rte_ring *)p); > +} > + > +static struct rte_mempool_handler handler_mp_mc = { > + .name = "ring_mp_mc", > + .alloc = common_ring_alloc, > + .free = common_ring_free, > + .put = common_ring_mp_put, > + .get = common_ring_mc_get, > + .get_count = common_ring_get_count, > +}; > + > +static struct rte_mempool_handler handler_sp_sc = { > + .name = "ring_sp_sc", > + .alloc = common_ring_alloc, > + .free = common_ring_free, > + .put = common_ring_sp_put, > + .get = common_ring_sc_get, > + .get_count = common_ring_get_count, > +}; > + > +static struct rte_mempool_handler handler_mp_sc = { > + .name = "ring_mp_sc", > + .alloc = common_ring_alloc, > + .free = common_ring_free, > + .put = common_ring_mp_put, > + .get = common_ring_sc_get, > + .get_count = common_ring_get_count, > +}; > + > +static struct rte_mempool_handler handler_sp_mc = { > + .name = "ring_sp_mc", > + .alloc = common_ring_alloc, > + .free = common_ring_free, > + .put = common_ring_sp_put, > + .get = common_ring_mc_get, > + .get_count = common_ring_get_count, > +}; > + > +MEMPOOL_REGISTER_HANDLER(handler_mp_mc); > +MEMPOOL_REGISTER_HANDLER(handler_sp_sc); > +MEMPOOL_REGISTER_HANDLER(handler_mp_sc); > +MEMPOOL_REGISTER_HANDLER(handler_sp_mc); > diff --git a/lib/librte_mempool/rte_mempool_handler.c b/lib/librte_mempool/rte_mempool_handler.c > new file mode 100644 > index 0000000..78611f8 > --- /dev/null > +++ b/lib/librte_mempool/rte_mempool_handler.c > @@ -0,0 +1,139 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2016 Intel Corporation. All rights reserved. > + * Copyright(c) 2016 6WIND S.A. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Intel Corporation nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +#include > + > +/* indirect jump table to support external memory pools */ > +struct rte_mempool_handler_table rte_mempool_handler_table = { > + .sl = RTE_SPINLOCK_INITIALIZER , > + .num_handlers = 0 > +}; > + > +/* add a new handler in rte_mempool_handler_table, return its index */ > +int > +rte_mempool_handler_register(struct rte_mempool_handler *h) > +{ > + struct rte_mempool_handler *handler; > + int16_t handler_idx; > + > + rte_spinlock_lock(&rte_mempool_handler_table.sl); > + > + if (rte_mempool_handler_table.num_handlers >= RTE_MEMPOOL_MAX_HANDLER_IDX) { > + rte_spinlock_unlock(&rte_mempool_handler_table.sl); > + RTE_LOG(ERR, MEMPOOL, > + "Maximum number of mempool handlers exceeded\n"); > + return -ENOSPC; > + } > + > + if (h->put == NULL || h->get == NULL || h->get_count == NULL) { > + rte_spinlock_unlock(&rte_mempool_handler_table.sl); > + RTE_LOG(ERR, MEMPOOL, > + "Missing callback while registering mempool handler\n"); > + return -EINVAL; > + } > + > + handler_idx = rte_mempool_handler_table.num_handlers++; > + handler = &rte_mempool_handler_table.handler[handler_idx]; > + snprintf(handler->name, sizeof(handler->name), "%s", h->name); > + handler->alloc = h->alloc; > + handler->put = h->put; > + handler->get = h->get; > + handler->get_count = h->get_count; > + > + rte_spinlock_unlock(&rte_mempool_handler_table.sl); > + > + return handler_idx; > +} > + > +/* wrapper to allocate an external pool handler */ > +void * > +rte_mempool_ext_alloc(struct rte_mempool *mp) > +{ > + struct rte_mempool_handler *handler; > + > + handler = rte_mempool_handler_get(mp->handler_idx); > + if (handler->alloc == NULL) > + return NULL; > + return handler->alloc(mp); > +} > + > +/* wrapper to free an external pool handler */ > +void > +rte_mempool_ext_free(struct rte_mempool *mp) > +{ > + struct rte_mempool_handler *handler; > + > + handler = rte_mempool_handler_get(mp->handler_idx); > + if (handler->free == NULL) > + return; > + return handler->free(mp); > +} > + > +/* wrapper to get available objects in an external pool handler */ > +unsigned > +rte_mempool_ext_get_count(const struct rte_mempool *mp) > +{ > + struct rte_mempool_handler *handler; > + > + handler = rte_mempool_handler_get(mp->handler_idx); > + return handler->get_count(mp->pool); > +} > + > +/* set the handler of a mempool */ > +int > +rte_mempool_set_handler(struct rte_mempool *mp, const char *name) > +{ > + struct rte_mempool_handler *handler = NULL; > + unsigned i; > + > + /* too late, the mempool is already populated */ > + if (mp->flags & MEMPOOL_F_RING_CREATED) > + return -EEXIST; > + > + for (i = 0; i < rte_mempool_handler_table.num_handlers; i++) { > + if (!strcmp(name, rte_mempool_handler_table.handler[i].name)) { > + handler = &rte_mempool_handler_table.handler[i]; > + break; > + } > + } > + > + if (handler == NULL) > + return -EINVAL; > + > + mp->handler_idx = i; > + return 0; > +} > diff --git a/lib/librte_mempool/rte_mempool_version.map b/lib/librte_mempool/rte_mempool_version.map > index f63461b..a0e9aed 100644 > --- a/lib/librte_mempool/rte_mempool_version.map > +++ b/lib/librte_mempool/rte_mempool_version.map > @@ -19,6 +19,8 @@ DPDK_2.0 { > DPDK_16.7 { > global: > > + rte_mempool_handler_table; > + > rte_mempool_check_cookies; > rte_mempool_obj_iter; > rte_mempool_mem_iter; > @@ -29,6 +31,8 @@ DPDK_16.7 { > rte_mempool_populate_default; > rte_mempool_populate_anon; > rte_mempool_free; > + rte_mempool_set_handler; > + rte_mempool_handler_register; > > local: *; > } DPDK_2.0; > -- > 2.5.5 >