From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1on0056.outbound.protection.outlook.com [157.56.112.56]) by dpdk.org (Postfix) with ESMTP id DC71F2C72 for ; Mon, 6 Jul 2015 10:53:06 +0200 (CEST) Received: from HE1PR02MB0810.eurprd02.prod.outlook.com (10.161.118.15) by HE1PR02MB0635.eurprd02.prod.outlook.com (10.161.114.141) with Microsoft SMTP Server (TLS) id 15.1.207.19; Mon, 6 Jul 2015 08:53:06 +0000 Received: from AM3PR02CA0020.eurprd02.prod.outlook.com (10.242.240.20) by HE1PR02MB0810.eurprd02.prod.outlook.com (10.161.118.15) with Microsoft SMTP Server (TLS) id 15.1.201.16; Mon, 6 Jul 2015 08:53:04 +0000 Received: from AM1FFO11FD040.protection.gbl (2a01:111:f400:7e00::145) by AM3PR02CA0020.outlook.office365.com (2a01:111:e400:8800::20) with Microsoft SMTP Server (TLS) id 15.1.207.19 via Frontend Transport; Mon, 6 Jul 2015 08:53:03 +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 AM1FFO11FD040.mail.protection.outlook.com (10.174.64.229) with Microsoft SMTP Server (TLS) id 15.1.201.10 via Frontend Transport; Mon, 6 Jul 2015 08:53:02 +0000 Received: (from zlu@localhost) by bjgfarm-1.internal.tilera.com (8.14.4/8.14.4/Submit) id t668quTE024535; Mon, 6 Jul 2015 16:52:56 +0800 From: Zhigang Lu To: Date: Mon, 6 Jul 2015 16:51:31 +0800 Message-ID: <1436172698-21749-7-git-send-email-zlu@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1436172698-21749-1-git-send-email-zlu@ezchip.com> References: <1436172698-21749-1-git-send-email-zlu@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD040; 1:nI9X0RAZAMVj7zHE3C2phXdb9mEbEVNXs7eh4KhgBfqCisCBOEDNtTza2+5uJrnIq/2ncwDsoNZiiBWd3axdtTQ6+sPwPcfvJpIkKwh+yzmkE7osnCugEsCw8nTvcdR6RxyYu/fyb0q4CgSg/3j7+cwNj8h1EaXERjkYdgrbbO+uy7txk+2dPkZIx1UABBNL1X2vEV/EOh+5ix8Xpl3l11iLaOyamzB+HIxdg8mMD88hmeyUKuBRKbbXKTv4e9OqGVmLFp8ExesCt60cFezBUmNVkA15HzSiMrcHBE7q6SFCgQz4yEyCWgXFZhI2uzKxUqlHxoC0hKSFlaY2y9W1fA== X-Forefront-Antispam-Report: CIP:124.207.145.166; CTRY:CN; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(979002)(6009001)(2980300002)(339900001)(199003)(189002)(46102003)(19580395003)(6806004)(19580405001)(106466001)(87936001)(86362001)(2351001)(42186005)(50986999)(33646002)(104016003)(229853001)(85426001)(76176999)(50466002)(77156002)(62966003)(48376002)(450100001)(2950100001)(107886002)(5001960100002)(189998001)(110136002)(47776003)(36756003)(105606002)(50226001)(92566002)(9376004)(4001430100001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR02MB0810; H:bjgfarm-1.internal.tilera.com; FPR:; SPF:Fail; MLV:ovrnspm; A:1; MX:1; PTR:InfoDomainNonexistent; LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0810; 2:PScweO3dZG2RnyGRJx1E0EU7Ogo/LhFT1kmtwiYABAjqiPFY2LBGAsyYprymsg/H; 3:CIqm8pE8Fa1SCXBP5kfded0CaQLNtBDjf3xYeBm/r5tIrwJ+FaD5ZZ+9wU/oLqKIvuh3HOh8oX9dkpJdruENx+uXT6K4Tu74xThXcEXVEH87dAaBwM7YQJBNfhW3gMQ8Ggi6eOJ+N1Xe8nigQOypzVHSXyvEUQja/4Mi6R0UTb8Gl9trt9VxvcFnJVQBefgPrlR1Wv5N9VmF/n3RCv2P5NuOmPhmB6JRoZqyTd/gORz5iytyCuKFz+9xb4/VrPUe; 25:ihHATBEUfp3i8Ad5JjW5KUIZypuUn/uxm0wGPIP51VFfuFi08nBvgXP2OeaqQsLZyJCVS3MIYcm6Utkhz0Zfr0N2DPfpaocZqN3vtHHAy+BKA1k7s7k6ljWrr7lKf501wxaqc1lhWCDABchM7GGHuKZONNQadUUQA9M5Dv93GKKIIh009whpJKyTDdWtsaNfq3cHOPy41qEiWr5i1CCto6VGkbJj28aP4Tu8laPKvUXC24d1CJtmKweO262vGP2j; 20:PjPFCdVaismNcjmNTuQX1n/LZUv0/1rmwySF+wZqGA1buqo/mN9RTPhj96mN68aBDIXiLmONU1UVfmrzIlygBSKF2STgOPoCIkPCDCrdFRKv3yDKaggh4KW9wyvYhhMx5+aajrw0tYmZPHMSuuEqFtq5e+aJgLC5SP7ekhpU2mA= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:HE1PR02MB0810; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:HE1PR02MB0635; 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:HE1PR02MB0810; BCL:0; PCL:0; RULEID:; SRVR:HE1PR02MB0810; X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0810; 4:tI88iNrL+gqX2849NcsHSrmMtUqIib8/wKP18IVIA8135OADzJ2jUw0j0q34e65QyhtEgp8PVB0xbnxuPijfzCxgLe7RfPPXxb1utWmKKPUkHHL2EcQXbphasS6nXvSTrfp9k00uFokW4aVquw/CzXm3t2NfwlkFX6mbapfkFOR8b5ZJ2rhNTeXLmTkPokAz/vfWe0lKYYDXu87l3Q3KLeBb5BDOwtuZNGBW9HVGRdDWuOmA4+jU07SOQi9WdT1SuHnE1zEQXYnBSi4ID9mAkPKkuevhY2k+uR8iYqC7gmI= X-Forefront-PRVS: 06290ECA9D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR02MB0810; 23:oexiDAyCnNUuCioS5fBhvjG+HK7IvloeJHUOfzUzF?= =?us-ascii?Q?0pEYCuiq6w/yEinh9qIhjtZb2QTpITFhPjU2WI30lMGD5qNNEajKC3oZJxmq?= =?us-ascii?Q?D+6lYbqNA0VeBi8UIZQ42cwvvGFIAkkNDnl8LRarNcG+dP5R58kJRSMTCOk7?= =?us-ascii?Q?aPsjkGaVRCixyD/8AFaCnxBrJxMddcYTYelv3HgrWHogbCaU2PLSL2GY45tN?= =?us-ascii?Q?ePwBouaFx8AsiOXOx+rMuUdDkChS3WbzodingMK1ANVQPxXbsRF3PF4FfIwS?= =?us-ascii?Q?soJCj1+o6B10kw5g/3Tblo1TJ5NqDoLohEzja5HNYP2w3XmYlG4gkJx8+MVn?= =?us-ascii?Q?sQHgXisYjkpaj46Uw22UFn6oRcLpjplfieZrQmxOA5VshXJDTHMmbjiX1HxI?= =?us-ascii?Q?ZykZKDIQvV/qLyCUrWmvU+S2UVaH/rziO5VqbwK5YvpaE/Rf2py27Ms1JF7s?= =?us-ascii?Q?bAR7V4B5laQ7w4BoGo0Xf16VzctCKea67Wtctp18VVNUKjB8v2IUxD+Bw2Ox?= =?us-ascii?Q?XmUVv6pRCJu7Ii3u5jDjS9If9ndddktfpM9qQ9hwJnuvi9VcT9Td8arpijMC?= =?us-ascii?Q?Iv7T83dukcw4vYFBbvgJmiBAbk08VXkjaYiVPOHwAEcX773nHzeQJ/ZryjPU?= =?us-ascii?Q?y/7aLfXDre0EnUls186GSd5X64wyYfFbVtPSUj8gzSJDv8k0xVURNLWNCvSe?= =?us-ascii?Q?cxJRyYuPK78nBOotR/kR1wQeRoSB9Xiz5qEM778paz1puTuK/T+fkzRn+Xrc?= =?us-ascii?Q?JR4KA7QU2VTMvtyyinX2Ye+2sz+qMuJtyHNoDi1B5rk74w7oLOkZnIpvGU55?= =?us-ascii?Q?ok3oXLgidP1jM518HdEhBCcY3klAh8+7QL2zXlgaUoFQnECNVJ7VutbbugaB?= =?us-ascii?Q?IWzzZVEgC11Vd7nxujVfDbtGQsvfshWxjsESMuq3Pj+MP7xXZk4Gre2slGdi?= =?us-ascii?Q?FUpsNR1RWmKGIXKVB18NctS9ZMF62ty/OhY532Jec8YwWnfdbfi4rS1qH4U8?= =?us-ascii?Q?g2dbiALEXI2rL01quAGxsKtaCks1zEN6p4ntgiyy4oH7vgCWfZmcaSvRcUvN?= =?us-ascii?Q?U5MuENiuw60XTifYd16ygfLIN58?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0810; 5:auGBImlF7uhGoBeydNjgSwOyizw3wJmrc0+BGgCPIaGgkiRj2mJrahjJKDQT6CCZ3Wa75PQK4TNA+JVvdfNIlbxc2thxONIQr5/cCb+49mhOEA1ClMippH0vXZANjEZS9fGiK7JiPtfMuiV7b98tHg==; 24:kwqRWy0HXagkfyY8KzxdF98yBsH+n5LKuqXJ1YeWQdwSf/BFzWUYVp4yBfCm6kX8SiUnGAiGU7CykuhJTbAYeK9p4JhZHrAxwmPDSgWRJw4=; 20:6D6TZGOH99aC2Temd/rSWPuPV4Q73vmCV8+hOFEgxfANnvUtYbVluffFnrfgHfeuT1BAAU7pjfSu7HeWVxIvCA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2015 08:53:02.5178 (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: HE1PR02MB0810 X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0635; 2:YLGrsPZinwRKbJK3pGrdOarSpk5v27cKe5FK9OcOX2nf0TpwxPEvdIC+6uBuohMa; 3:VrFXdpifUTygooWT3XbEJ6LGVUl1uGdUc+a3uQEljCD6qSSCbIM1kVQ7gEY7dYPa3rZpj42HZ4bj3Z/0COzz697rb2ZZyBb5edBBxYWOLqIBh2gv8VKnDND7h4xjVPjxum91+gzsYdgFQ9gH9UmakkwI7g+J1idieUrwlRrtNb2ooXVribtBrwXEP8Gr6/2JNYp/uVdYnimVarNbtRkamsv56P75jkKz30J4aFjiiXMk8H46Zs/CqzZmCE1QQFN7; 25:J1XGkH2Xb197zxf+LHyAoSvMQ65IurlvbofmMuYpFtzIM8QlfVuq/FBdwVV51abRRmID+JF8DMnuNtOGU0G/h7+XTUqtiHCM8cdXqIQ/RCWkcIJ8CGARhl6rHleCjyKVUiBPlem7PgaxbDwGcwQoERaFD4xZqxWGpMHDypAoDVHtl5Smg6fu45vMhVcEjvnP1eG6nlIABCWdhImPmiiB5kDFq+YirxmvLP8mwKz5a1u7xZBjpQ72f19WG0oS8ACK; 23:2RfkrYzN61A3f9TAJaEDTcCqktC55P+4LmoacRnpUemlBFzzky8lPlYzM9D7PgGslqWyMw35RNaWKTthv33j6oHkExtTMkKb7yl/ARdtQGIK4MYqYEPv5yVIh0IsWXZRapTNFTEkOuZpWVHjO50G5S/0HeVkr11iueytGEKYw0PeFPuOpXpNITpdA6dwtLGROAt235YUJQHngFwKCJn1INd2zLVDSXXWwTZtXHtuXzttJqKDMY3Z4hPl3x5w94TI X-OriginatorOrg: ezchip.com Subject: [dpdk-dev] [PATCH v3 06/12] 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: Mon, 06 Jul 2015 08:53:07 -0000 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(). Change-Id: Id26c25b4dd3d07861eaf35e72aaa2de555916fa3 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