From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0076.outbound.protection.outlook.com [157.56.110.76]) by dpdk.org (Postfix) with ESMTP id 09E39C478 for ; Thu, 28 Jan 2016 18:54:34 +0100 (CET) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@caviumnetworks.com; Received: from localhost.localdomain (122.166.129.161) by BN3PR0701MB1720.namprd07.prod.outlook.com (10.163.39.19) with Microsoft SMTP Server (TLS) id 15.1.390.13; Thu, 28 Jan 2016 17:54:30 +0000 Date: Thu, 28 Jan 2016 23:24:07 +0530 From: Jerin Jacob To: David Hunt Message-ID: <20160128175406.GC11992@localhost.localdomain> References: <1453829155-1366-1-git-send-email-david.hunt@intel.com> <1453829155-1366-4-git-send-email-david.hunt@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1453829155-1366-4-git-send-email-david.hunt@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Originating-IP: [122.166.129.161] X-ClientProxiedBy: MAXPR01CA0034.INDPRD01.PROD.OUTLOOK.COM (25.164.147.41) To BN3PR0701MB1720.namprd07.prod.outlook.com (25.163.39.19) X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1720; 2:UHON8S14FtRE0RYP1IV+k+1n7wXgTWa187C8TNOmVa429evHCSs2G3TIcH7pUCjIQNAtMZZzhPr0CMue6TcuYhBObqtK+604fkaov3pywardtt/VR2dfZc5V+o/beBSwNp5YX4B++IPDmIiPSZmNwA==; 3:y8ljDBN4nPcMCSvi4DjXbJ3OAup1L9x5EQMnsRlo7J0oaETjcUhhxQcqcS+teiGrOeG2898Ia1MrOvADqEVeofaviY5Op9FJeQ4nWCbA3zE3MLOjEKjyFXvnUPgGVCrN; 25:3aoQLPPCHr5yJO0E72FqqJvrrD18yMI410aFkAVTTGO3Er66YsLg0q9dPxHLgd9S+ZX2LZfjVC5BluDZSox8yr6p9+X7rSreEzhXQQ5/U5tKLVeyzSZt6GQWwIhOvOVIQwZi6DWAJpQXr88u4ZQx0ChkNgHI9O980Yf7kcYRis9wIjhu6zof0TYfEyiRDIyc9/w9HBiVJNWX3MmVXp8AXtSN0wPuhDmNEsshsqFcyKZYYOWZ6/mZepSHYcapv0tZ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1720; X-MS-Office365-Filtering-Correlation-Id: 096ea1bf-0645-4854-789a-08d3280c135c X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1720; 20:xlI0NIUIgG8/432xNkfQgJ24oCo7l1AWpSaGB2EMCutXlOeimMjEBfxtF9ixGOgTwDtdZlfFIM1JncLDpPNSVKQvmMB9vGAVmWanGhMy+p3C6q3JAAFHoeWqJ3PVmKR2WZ6u14zDHheoKyNVoG/vlUHocO8WovlHi2u3pgVUotFDpSduwpWmY6J87KjjHSaGZeJgnKiyBkLstRUnRYqrCgnjTe5Pvw2pX/4xlqLhSEjUIX4il94ra0pP3lQA3BR2fBkfmdIsK8RMf7XfFTLaeClndxjN9ax4kMAYYG1oMIKY8DJf8uDOA82nfvizMsx9Go98wWqay1NRhDCxadICs5u346y5Bh1xkXG0ZCpb2AYcUvYBRXEcQKdBVkabG+EAAuSDjHLI9mmClGszokPf4FU2mB21xlvHyuVVg1GUv7JDtf7eSXBNPg2XR0sIjedEQiR9RUd2hzOAMpbDeGG0T74y8G0yGvgajDNIre3yQotBLg2mRmjp7tjK0nyCOgqArV+yRIJv5L13fQYYsqSrnCIuF3zpI+wmca8ZeYAuGfx3CluBgn7cxJb72R+jdIvIns7nhYkuC7q46LBrKTiCO4w1asIqnVrC3sdSfj12XRc= 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:BN3PR0701MB1720; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1720; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1720; 4:dqRVdoJ1+YMykc4kMv7fXBoJ2ptO/prHxfJDp29rHyZBN2tLyIsNLTyVzoJrJV1y8c+7Wlo5gKVzhBpOqWSnijlRBxZOBGN8FaENw/yTK8csQqoJOajPY9sQGaem2mmZ7/tXg9QDH/K8ZLr7u0MkTQ8IzkA33f68G5UqDyvB9YiikJtZWam5F6pTLD+mGa0C3sAvR+8CT4Iuv2pCoAITB1T369q+F86m8G6QUncKnI7bbE77XmwWh0N6B7dC2++DXAr8SAdE3VM49ZCfFC+dvly2ZBRl9JHOAYyojEHzfll7d846TPFyefR2RIdBzc8ehcprX2brpatQ/Vd3bMH0iSayAwmGFQOTaSW/8f75ZwtUPfQ37YP7US4AnukHAHNO X-Forefront-PRVS: 083526BF8A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(6009001)(24454002)(199003)(189002)(586003)(86362001)(1096002)(1076002)(110136002)(105586002)(46406003)(6116002)(3846002)(77096005)(23726003)(87976001)(106356001)(92566002)(50466002)(101416001)(5004730100002)(5008740100001)(42186005)(61506002)(122386002)(2950100001)(66066001)(97756001)(2906002)(4326007)(83506001)(54356999)(50986999)(19580395003)(3470700001)(189998001)(40100003)(19580405001)(4001350100001)(97736004)(5001960100002)(81156007)(76176999)(47776003)(33656002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1720; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1720; 23:lonWMJ9JSgFvQL7id/J7ZuWEjiDVA0D2156+1C2?= =?us-ascii?Q?dN9mf7+MW9R0tCZcBjy4uljrm/cVTexPzO+7/oKHDGENILEZoop5z/CQby6H?= =?us-ascii?Q?dEuCdpF0IQa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qRvAv/63xf0y7QDu18vSVxaYrxOT?= =?us-ascii?Q?bgDCc5s5nkZx8eO9uPo3K0Mk5ZsuykDP+UVRvf4c6amA/wVVgRGADJopYwHi?= =?us-ascii?Q?adRGsgHpk6tD/k/4ZeCs7lAKUKAlgXkVeGLCcEhJYv5fLNX79kJ/EWTHIJ/f?= =?us-ascii?Q?6rKENS6L/lCYS8XTwxA7vfVDYJ00Wx4OOUB6q/VtJB+9UrYlieZ9c55np0ZW?= =?us-ascii?Q?WEVQhAzklqOOF40k=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1720; 5:tDYpBQ6fg4vQW21otYjOodYm0rOlUpOS4wOFM6pr78VCztEo0z+TdNODv1I5NwYrwVfiYuPo5JB7NxCLg/R5Y5LaoQVugWKgmu21kJgeQ2P7Qbel/4yGc35FN518BRbsFREuNWtGs1Wvw0vA6MKCmQ==; 24:zD9wzq+6qyHB34TmzfsJJSvpW6GZROg64njODV5+xHAF5H4NzZRalYBXbr9U34C/UsYuNXFFnSRYaMbf/uFFrOU9DQOAK1dvlTUK8Jn+a7Q= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2016 17:54:30.3604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1720 Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH 3/5] mempool: add custom external mempool handler example 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: Thu, 28 Jan 2016 17:54:34 -0000 On Tue, Jan 26, 2016 at 05:25:53PM +0000, David Hunt wrote: > adds a simple ring-based mempool handler using mallocs for each object nit, $ git am /export/dh/3 Applying: mempool: add custom external mempool handler example /export/dpdk-master/.git/rebase-apply/patch:184: new blank line at EOF. + warning: 1 line adds whitespace errors. > > Signed-off-by: David Hunt > --- > lib/librte_mempool/Makefile | 1 + > lib/librte_mempool/custom_mempool.c | 160 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 161 insertions(+) > create mode 100644 lib/librte_mempool/custom_mempool.c > > diff --git a/lib/librte_mempool/Makefile b/lib/librte_mempool/Makefile > index d795b48..4f72546 100644 > --- a/lib/librte_mempool/Makefile > +++ b/lib/librte_mempool/Makefile > @@ -44,6 +44,7 @@ LIBABIVER := 1 > SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c > SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_default.c > SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_stack.c > +SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += custom_mempool.c > ifeq ($(CONFIG_RTE_LIBRTE_XEN_DOM0),y) > SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_dom0_mempool.c > endif > diff --git a/lib/librte_mempool/custom_mempool.c b/lib/librte_mempool/custom_mempool.c > new file mode 100644 > index 0000000..a9da8c5 > --- /dev/null > +++ b/lib/librte_mempool/custom_mempool.c > @@ -0,0 +1,160 @@ > +/*- > + * 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 > +#include > +#include > +#include > + > +#include > + > +#include "rte_mempool_internal.h" > + > +/* > + * Mempool > + * ======= > + * > + * Basic tests: done on one core with and without cache: > + * > + * - Get one object, put one object > + * - Get two objects, put two objects > + * - Get all objects, test that their content is not modified and > + * put them back in the pool. > + */ > + > +#define TIME_S 5 > +#define MEMPOOL_ELT_SIZE 2048 > +#define MAX_KEEP 128 > +#define MEMPOOL_SIZE 8192 > + > +#if 0 > +/* > + * For our example mempool handler, we use the following struct to > + * pass info to our create callback so it can call rte_mempool_create > + */ > +struct custom_mempool_alloc_params { > + char ring_name[RTE_RING_NAMESIZE]; > + unsigned n_elt; > + unsigned elt_size; > +}; > +#endif > + > +/* > + * Simple example of custom mempool structure. Holds pointers to all the > + * elements which are simply malloc'd in this example. > + */ > +struct custom_mempool { > + struct rte_ring *r; /* Ring to manage elements */ > + void *elements[MEMPOOL_SIZE]; /* Element pointers */ > +}; > + > +/* > + * Loop though all the element pointers and allocate a chunk of memory, then > + * insert that memory into the ring. > + */ > +static void * > +custom_mempool_alloc(struct rte_mempool *mp, > + const char *name, unsigned n, > + __attribute__((unused)) int socket_id, > + __attribute__((unused)) unsigned flags) > + > +{ > + static struct custom_mempool *cm; > + uint32_t *objnum; > + unsigned int i; > + > + cm = malloc(sizeof(struct custom_mempool)); > + > + /* Create the ring so we can enqueue/dequeue */ > + cm->r = rte_ring_create(name, > + rte_align32pow2(n+1), 0, 0); > + if (cm->r == NULL) > + return NULL; > + > + /* > + * Loop around the elements an allocate the required memory > + * and place them in the ring. > + * Not worried about alignment or performance for this example. > + * Also, set the first 32-bits to be the element number so we > + * can check later on. > + */ > + for (i = 0; i < n; i++) { > + cm->elements[i] = malloc(mp->elt_size); > + memset(cm->elements[i], 0, mp->elt_size); > + objnum = (uint32_t *)cm->elements[i]; > + *objnum = i; > + rte_ring_sp_enqueue_bulk(cm->r, &(cm->elements[i]), 1); > + } > + > + return cm; > +} > + > +static int > +custom_mempool_put(void *p, void * const *obj_table, unsigned n) > +{ > + struct custom_mempool *cm = (struct custom_mempool *)p; > + > + return rte_ring_mp_enqueue_bulk(cm->r, obj_table, n); > +} > + > + > +static int > +custom_mempool_get(void *p, void **obj_table, unsigned n) > +{ > + struct custom_mempool *cm = (struct custom_mempool *)p; > + > + return rte_ring_mc_dequeue_bulk(cm->r, obj_table, n); > +} > + > +static unsigned > +custom_mempool_get_count(void *p) > +{ > + struct custom_mempool *cm = (struct custom_mempool *)p; > + > + return rte_ring_count(cm->r); > +} > + > +static struct rte_mempool_handler mempool_handler_custom = { > + .name = "custom_handler", > + .alloc = custom_mempool_alloc, > + .put = custom_mempool_put, > + .get = custom_mempool_get, > + .get_count = custom_mempool_get_count, > +}; > + > +REGISTER_MEMPOOL_HANDLER(mempool_handler_custom); > + > -- > 1.9.3 >