From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0073.outbound.protection.outlook.com [157.55.234.73]) by dpdk.org (Postfix) with ESMTP id 48A3B5A68 for ; Thu, 9 Jul 2015 07:00:35 +0200 (CEST) Received: from HE1PR02CA0032.eurprd02.prod.outlook.com (10.162.33.42) by HE1PR02MB0795.eurprd02.prod.outlook.com (10.161.118.147) with Microsoft SMTP Server (TLS) id 15.1.207.19; Thu, 9 Jul 2015 05:00:33 +0000 Received: from AM1FFO11FD054.protection.gbl (2a01:111:f400:7e00::182) by HE1PR02CA0032.outlook.office365.com (2a01:111:e400:5149::42) with Microsoft SMTP Server (TLS) id 15.1.213.14 via Frontend Transport; Thu, 9 Jul 2015 05:00:32 +0000 Authentication-Results: spf=fail (sender IP is 124.207.145.166) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of ezchip.com does not designate 124.207.145.166 as permitted sender) receiver=protection.outlook.com; client-ip=124.207.145.166; helo=bjgfarm-1.internal.tilera.com; Received: from bjgfarm-1.internal.tilera.com (124.207.145.166) by AM1FFO11FD054.mail.protection.outlook.com (10.174.65.73) with Microsoft SMTP Server (TLS) id 15.1.213.8 via Frontend Transport; Thu, 9 Jul 2015 05:00:29 +0000 Received: (from zlu@localhost) by bjgfarm-1.internal.tilera.com (8.14.4/8.14.4/Submit) id t6950O8N018571; Thu, 9 Jul 2015 13:00:24 +0800 From: Zhigang Lu To: Date: Thu, 9 Jul 2015 12:58:51 +0800 Message-ID: <1436417938-18496-6-git-send-email-zlu@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1436417938-18496-1-git-send-email-zlu@ezchip.com> References: <1436417938-18496-1-git-send-email-zlu@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD054; 1:aO0iWcc5YAmXGXbE6C3Pnhc9ruZ2DGTe1+XqJFgwJwZzhLhsQVGW1P87EzKzXP9LJceSZHvFQXhDtI96EM6WeaqD+Vuo0K9mZcD18T4nDuculvbAUVU6HZ58WiNec/GSAv6wfUpG2o4R5odO3Em/V8Nayzch8LUMhSdJrQYoeQRJO3bmbug3UrcSSAZzuxajTTiE7J3Di8tTSQERvtIf4fJ27pN2AKtg9oNgyjyea49YnRMrKFbLIctnJ7OKrioFZM/YsNviCl6vGMV5roigU7aIO1tc8E/XbRdBFtOqb33nxmaUV/QkgmB4H2AdqhQ7ySBu9at/31WY5KRBo/n/LA2CQwqlz4aNZnPoUT+XAPNF1N3OTy3NSszu7vdr6F4VoUipVLCB9gUAAdQpPfXCgI8XM5X9wlZpprz6Bh+eYm70ALXZjz6sESnxOAhrS5nY X-Forefront-Antispam-Report: CIP:124.207.145.166; CTRY:CN; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(339900001)(189002)(199003)(105606002)(19580395003)(2351001)(47776003)(189998001)(50986999)(19580405001)(2950100001)(229853001)(46102003)(92566002)(6806004)(42186005)(106466001)(76176999)(5003940100001)(33646002)(450100001)(77156002)(50466002)(48376002)(110136002)(62966003)(5001960100002)(86362001)(85426001)(87936001)(36756003)(50226001)(107886002)(104016003)(4001430100001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR02MB0795; H:bjgfarm-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; MX:1; A:3; LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0795; 2:d2rX3qXl9tNjPo2CzLy/CZ4FqJqVqEIaTMlv5Br/5nVRkLhKyVjtD615IFCOUkcm; 3:bEs6DsTts2U9DaLLgfj7NZcy3MCH5x0jnklol2np4y87nuHp/utI5KdhBvGigfEOwVY7hZZHZZWuZxji3toOUkoyHd3UnWQUqB1CLOIa1nY7Iybc5lyJxfGVIH4m4ur2uhwwyctUTqmr4ZIs3p3ElpsxAHGhMzNUW45g8BZcgF/NAYkWlwWr0cfFuO6bSaHXSqA4PmSL2FITJgJDIotAPw1m6/JDxDyFdZDROUTDnWW4DTGHv0jypgcrsUe1iLkI; 25:hkW6sKQYYDCOHKlLvqMnJWYhT2ViFN2cxHdu07Y3gHQ+4ESURqED/UqZUyWHDIqo9TJQ0PdUSRhJruuPV0ETNw5ffJLaskJwBd67Jgd1Yv1VzqDo0YQfqVgHkW2ML8ssplzEAO9frZ6zrdwWbFg1szNAsVMauNDeQIzv7qZ9Y3QJ4vPIB9XhTsn9hRp5qB4SKmQCBf8JpI7HeiDPZDBsFO99HNjArRI35+UAppKRdJFosHpCyHT6s5AI6H0UGwrr; 20:OSyEQB65ddqUPou8Q23I8We4nYc5fcsw2a1dakUN+yU8eP3IG/eVgcJewYDcqeT92opxKZ3GTLH6OjqqIHcVYAi7GaP1l6TrHCgHcZ7bX2ytLBDlDvGUVV0bH4wVaZmRyzWBWvYxWYg1RYyn3z965pMmhaYJwPgEFIqv/DECsPk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0795; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:HE1PR02MB0795; BCL:0; PCL:0; RULEID:; SRVR:HE1PR02MB0795; X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0795; 4:qDdL8UQmowWD+ZVT0ocZXWbGYoFb+HulapH2VUsAg9Nv95lpLuDpIntnolXsqzxUGqttDBdNEoRQiMUoVXZBf+m7+uDvGcH4NCgcIreAB9LZKfVwtt8LxkDjYK/H7Hzbw/6NNIJHNAD7nSVWB19D2pCrIOrPZAaRATekDHUHCLrjNv3GmArPUX62/yTxN7Gcj3HrrqXZGW48H3XY9iuUKG1IXdFL1M8iNxN21jauNHHRb6HWW5pgks9B6n62PKGvw8czJpZ97csg0Ka5lbmrNy657o9778j32WIRBSJyEaU= X-Forefront-PRVS: 0632519F33 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR02MB0795; 23:nPE2JAxrVDDIyMgnEHNdZup6SV9CCRLAdlOcv/bt7?= =?us-ascii?Q?l6OMUXCOX0DjHGOpNXUfd3WJQVnP0f4IgtfW/gngHj2OgSZ/77e5xFUrMY/1?= =?us-ascii?Q?ZYaFM2zMJDNd2IvHPCyTBWS/hOyA5+9HH78IMpYa2rLsqE6hM7Mj6in78xXD?= =?us-ascii?Q?j+OZDCovc3NSgA+3U2SwQMLzoybHmagndvzAPzHtYBvi1VpOkKhKajrX46o3?= =?us-ascii?Q?uVylaTuLdXhTjAuN0wNx8QUOWVGjeukKvPnL4VsGFMPQPz4TTQg5PhHduIke?= =?us-ascii?Q?xrGWbfTkItjD30Pr8BYzSJ1WDjc5Y/O3sprvPMwS9or/8/cBbnHMGu5I/x/E?= =?us-ascii?Q?zLPz75rKIe0SimL4GAOhn/OkttP7f+yLsG5j+TnmIhIW93Xo6cR7KYdpqVCZ?= =?us-ascii?Q?wRYK0TrIXzH5VIZjXGUS+QCX1sVEjxt9rGSCFPzHcFn8xWx4Q+DmYObM/Xxc?= =?us-ascii?Q?+f/Fkanq2c7SbaCii32SBvhRbbmbD45yIrAbtGjpA+UQzCYFgS0fAZBvu3AA?= =?us-ascii?Q?9zzAsI5ffHoFNtxGVpuR3KtDY95veSbPNDhulLxVEVzA1QKvs7dTXk3g9dbe?= =?us-ascii?Q?RA1/Zbi+V4JQCGUBu+uW9PwSzyQCqxD9yi9CHrrppU6vtbrnvMLACNmXapc0?= =?us-ascii?Q?Tfl3E/SmPl4UkuBjHlXTp1pgPzFZzbDgrUPg2A52PUv+4gC6XTuEs4ojItmz?= =?us-ascii?Q?ub4ndjGa7+YNzGjryQgVwWcc6vgu1p45BUPOxNsDBegJZQLVZPMbG/el2p/2?= =?us-ascii?Q?dWDBWVI32l902iKlXLut2uGj/Z0FNC5djVIFfYXMwZL2c3iMA7aM3rW/dsRw?= =?us-ascii?Q?hC1GcfRTL+MfapqRI+ntr2+GVf8Bp/5nPU0zrkqBGSBAWgwo4jryloXrEmVV?= =?us-ascii?Q?diLza/ggID7zc/QjB9TdDt3WG3Pt1sdCtRzQs1NOzONIoP3bcE4QRlV4/gzO?= =?us-ascii?Q?Ql1Lo11DIfMXXwCIPcWIAuitkpFo5nGnbz8cb6s2f1GTNFAsc++rtTyQNGps?= =?us-ascii?Q?Hc=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0795; 5:ZveMBtgv6rfrT3tEUjnNjxYLqnxhBHgJDuFd20OYVm+uUf2hFIdK9FuOcigfqXZKBppHeeICVUfg4HhLt7YBd+SgfAykSekaZ1jjfDJBi5yMVSBdJ/9SLhegpU+1+N/9Y4+Hnf7VsysGKuf4DaEmgQ==; 24:1tTKhGMVxipvORz5sNgZZLVevjlB/YLQC+H8ZR8Q31AqeCHtvo3Rx7O4+ryn5N6dGdMsMjBHaWiV8nW7nh7HSl5Kmd0AYwlz/CzWr7GZdPM=; 20:qoKZZMboQZ2hwcEYJT+ILa6ThZPMGXZkpUFa0sAaU1zruZNQQoxKpfmvSb8RhjlQa8QqDqJaOIJd192DTuRk+Q== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2015 05:00:29.9978 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3; Ip=[124.207.145.166]; Helo=[bjgfarm-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR02MB0795 Cc: Cyril Chemparathy Subject: [dpdk-dev] [PATCH v4 05/11] memzone: refactor rte_memzone_reserve() variants 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, 09 Jul 2015 05:00:35 -0000 From: Cyril Chemparathy The definitions of rte_memzone_reserve_aligned() and rte_memzone_reserve_bounded() were identical with the exception of the bound argument passed into rte_memzone_reserve_thread_safe(). This patch removes this replication of code by unifying it into rte_memzone_reserve_thread_safe(), which is then called by all three variants of rte_memzone_reserve(). Signed-off-by: Zhigang Lu --- lib/librte_eal/common/eal_common_memzone.c | 77 +++++++++++++----------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index aee184a..1ea502b 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -77,18 +77,6 @@ memzone_lookup_thread_unsafe(const char *name) } /* - * Return a pointer to a correctly filled memzone descriptor. If the - * allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve(const char *name, size_t len, int socket_id, - unsigned flags) -{ - return rte_memzone_reserve_aligned(name, - len, socket_id, flags, RTE_CACHE_LINE_SIZE); -} - -/* * Helper function for memzone_reserve_aligned_thread_unsafe(). * Calculate address offset from the start of the segment. * Align offset in that way that it satisfy istart alignmnet and @@ -307,13 +295,10 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, return mz; } -/* - * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment). If the allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve_aligned(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align) +static const struct rte_memzone * +rte_memzone_reserve_thread_safe(const char *name, size_t len, + int socket_id, unsigned flags, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; @@ -331,7 +316,7 @@ rte_memzone_reserve_aligned(const char *name, size_t len, rte_rwlock_write_lock(&mcfg->mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, 0); + name, len, socket_id, flags, align, bound); rte_rwlock_write_unlock(&mcfg->mlock); @@ -340,36 +325,40 @@ rte_memzone_reserve_aligned(const char *name, size_t len, /* * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment and boundary). - * If the allocation cannot be done, return NULL. + * specified alignment and boundary). If the allocation cannot be done, + * return NULL. */ const struct rte_memzone * -rte_memzone_reserve_bounded(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) +rte_memzone_reserve_bounded(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align, unsigned bound) { - struct rte_mem_config *mcfg; - const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } - - /* get pointer to global configuration */ - mcfg = rte_eal_get_configuration()->mem_config; - - rte_rwlock_write_lock(&mcfg->mlock); - - mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); - - rte_rwlock_write_unlock(&mcfg->mlock); + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, bound); +} - return mz; +/* + * Return a pointer to a correctly filled memzone descriptor (with a + * specified alignment). If the allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve_aligned(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, 0); } +/* + * Return a pointer to a correctly filled memzone descriptor. If the + * allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve(const char *name, size_t len, int socket_id, + unsigned flags) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, + flags, RTE_CACHE_LINE_SIZE, 0); +} /* * Lookup for the memzone identified by the given name -- 2.1.2