From patchwork Thu Jul 9 08:25:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhigang Lu X-Patchwork-Id: 6225 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id B26EF5A8C; Thu, 9 Jul 2015 10:26:26 +0200 (CEST) Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1on0053.outbound.protection.outlook.com [157.56.112.53]) by dpdk.org (Postfix) with ESMTP id 842335A7A for ; Thu, 9 Jul 2015 10:26:24 +0200 (CEST) Received: from HE1PR02CA0021.eurprd02.prod.outlook.com (10.162.33.31) by HE1PR02MB0811.eurprd02.prod.outlook.com (10.161.118.150) with Microsoft SMTP Server (TLS) id 15.1.213.14; Thu, 9 Jul 2015 08:26:23 +0000 Received: from AM1FFO11FD024.protection.gbl (2a01:111:f400:7e00::121) by HE1PR02CA0021.outlook.office365.com (2a01:111:e400:5149::31) with Microsoft SMTP Server (TLS) id 15.1.213.14 via Frontend Transport; Thu, 9 Jul 2015 08:26:23 +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 AM1FFO11FD024.mail.protection.outlook.com (10.174.64.213) with Microsoft SMTP Server (TLS) id 15.1.213.8 via Frontend Transport; Thu, 9 Jul 2015 08:26:20 +0000 Received: (from zlu@localhost) by bjgfarm-1.internal.tilera.com (8.14.4/8.14.4/Submit) id t698QFUm003928; Thu, 9 Jul 2015 16:26:15 +0800 From: Zhigang Lu To: Date: Thu, 9 Jul 2015 16:25:14 +0800 Message-ID: <1436430321-3864-6-git-send-email-zlu@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1436430321-3864-1-git-send-email-zlu@ezchip.com> References: <1436430321-3864-1-git-send-email-zlu@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD024; 1:GEmfCtaZmWsTRhh0MzzPvwveml/1FyHwg7Kt4DW3fZ+xfN4dwyodGRHRIJuHuoQqAiNAKGgH7lMz1Pxtb7ReSK93lTkcuE74eOtqFSYRISMIcLfE+JY4THrpIeAdllSEfkbmJf9xO5RTwc3lkZAydxzP/QrShMunjWXFVUxKoTN1MBGc4jJ/mQuR5BaE/Ta4jUfUHe89z776ciPKM31dqeF8nawccA8LKb+rI0OuYJcfSKPgSmZbGdZg+LVDBXRMHXiawI+Ji1fSPG4TkyPEsqsrZGDsrm6ELUBFHL59VkwgGp+OxFmtsKUtpv4wQ0XX9iqjRbRmf1WEUx6MudTDCxAbX+eA/Z3S5uKXNgLfR5C9rnoKhqII9KCnlr0IV7vdiDazgIDUgNrdGp3oHM1emrPyj0/W6zlXJSdooyhcaOz2ePI0ZSytGtdKbvk4CyUj X-Forefront-Antispam-Report: CIP:124.207.145.166; CTRY:CN; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(339900001)(189002)(199003)(2950100001)(189998001)(36756003)(50226001)(46102003)(47776003)(42186005)(104016003)(85426001)(92566002)(77156002)(62966003)(5001960100002)(48376002)(6806004)(107886002)(110136002)(106466001)(19580395003)(2351001)(19580405001)(450100001)(229853001)(105606002)(50986999)(86362001)(33646002)(50466002)(5003940100001)(76176999)(87936001)(4001430100001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR02MB0811; H:bjgfarm-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0811; 2:cX+exv2kpJBMQxaM3ba1tlejZbfTOeu9sLBu/9y8E5utl+EnbLOo5dcgOfkoWE2j; 3:99GiJa83vnDFyfbBp9XSPBXwuCoHg0ouLa6TXDhTta1qfBsTBqbI33iwMiKwyQSQfezVOSe/Q16zV5mRbPFGZSxYfa2scy8bkVfrdn6BfEEeGSMhR7kTGe7S9Z8epOLUnQPoceA8B4c/uw4rCpiXWIAk7e7dfIMQQpTgmpysRmYHz33VawsGqkVvAA6OGBV4snN+x/dwaAfz/xiMIVb7/GlD7kuBybfrPDFWkgRFF/I90ieQuS7N+SejDHESR2it; 25:rl4hLcKgrCEmbanVScdgpIAOQkdOz71Q95Y9OiAFlkT7mkZn+59YJHmcr8IKvAzNtrSOJi0wcZqn48CYLWOrfLHXOXGspWsT/fabHFin+3exOCvcvk7TMpHocGFFnudxNGK914YcWUydx36aopMMnAzwxzNk/gUw/NNO0J87iiKDrEne1LYJ+HM+wSnAXFlTTbbsmdJqASUkh3k/x6oryt8syfvTkh2DESejv2cZaD0lEgnHO9J3h6CB5ZY/t13/; 20:awJD3OSrRScwkFg8qyCnQjLF3BuIxcsvctEuOnhrF8aajdHGgzxqzx+NEgx3eHTmHHsKXjkjENzqJLQb4AExngKaBSB8L7OhNktV7D0ogD+0lIXi0lTXdyZcus677IZ1v1ioULnqgdIqzMVt3AnPrFpsc5gQoEWy9S2SfV9beV8= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0811; HE1PR02MB0811: X-MS-Exchange-Organization-RulesExecuted 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:HE1PR02MB0811; BCL:0; PCL:0; RULEID:; SRVR:HE1PR02MB0811; X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0811; 4:yZIVNmPVME00zTmG1RialLAJQRe0xbx/diibc/je/ip8mo1Ft1h7NcHe9CFprnbBEBRo1eF2LMHMgO3xLE9JcLwCRQ9zvknXGhF1GXiMZbYsJwLCnynkimIHCv1liuyTB/laMbv03wa4PUW+QM9iQ6h53zJg1MZchE7fph1/T9rDxZyljKkxSWwnlHkXICu8tfFegEs+gQ2Kd8cM1G78FyrRrbmfZJv42mYwWgpo983V9MpeQsF6GoQa0AhCeHuTvPpGZcWYgZ4AtErYYJnQCJC05bbpQLSABZ/Z17urmFo= X-Forefront-PRVS: 0632519F33 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR02MB0811; 23:5KGAzl7SOJhM8Ain1/8SIpcz/kHox71Vm84+aEl6s?= =?us-ascii?Q?CcVFQjlhjtI//bXvFGkXidd1pkhnYhQFw5lnktflzx9FBraWwAEDpXgM3JRK?= =?us-ascii?Q?DhGVUGIVhAihoccqLHrHjIWrOn7O9n5BfD4K4cBkTh9UJcmungvFANJtcYxs?= =?us-ascii?Q?uKSqgbgpV9v9xJ6goqkhIKWQuqafyBNoZQt955I3bjN40BrO5BAeOjtqi8DY?= =?us-ascii?Q?Q4hcfk0sAi0WZEnn8b3ud23qppsY0k76nWBXTmE7aONXKgBLAl+eFOG3K/0p?= =?us-ascii?Q?R4u4syBTf45vTdZBjQerPvb4O872yxRF4U6R6RvKmIszLHjGK02//vKRpkQV?= =?us-ascii?Q?0atRiGqMG1UHGy2I7T9gp+XiKimFXYpk5vwKdFHDYSG/RZrtCfOlhHp5AGuC?= =?us-ascii?Q?d0YDxA3uKaIJOt4CrSE6WxlY3/TtaSNMf+PFvTeAD+XVpQWkYtjfn5ytPHU/?= =?us-ascii?Q?Q3y72SCYFA1M6UxWGf+ffou6zjJ3ugIeQX0srKNqZbWuARMVCTjoiaw85bru?= =?us-ascii?Q?nZNMR2LGDy6m9gAZkh8Yi1fzhCE3iov0EloebUp9DZpf3DK28EFkHEDAQPKn?= =?us-ascii?Q?Ws23g94fRBstDiuwKqzxg47Ix/n5u5VX/rV4ndUenyMmDZg/DDvn6PVHF2gG?= =?us-ascii?Q?xDlzL55QmRW5j7mVuegi9yvIzZxk0q2+pX2uL4s+u7xeUPHnK20c0eKmhuNQ?= =?us-ascii?Q?deXizvZ8yAiOZ5cDSqO0liklDhdDUMegDlrnQWYI+4vGBDQLtwNVWIIr1Wpn?= =?us-ascii?Q?f6aUyi/tWj+k98rJVXl2HdFGNqdIYRj9kkHy39bkjcFjfMpnBegbYxHl9T5G?= =?us-ascii?Q?M1Z1nBdnUWHIoXrSgRhEI2YNJvsjT+402FFpINzEtEDz9mWdSMTrnq9blCH/?= =?us-ascii?Q?Ov3oiADrR1nt3kyTC0PKpO+LqniZVH13pKg7xJFpDxyS51uLiLw6FqqfSfdp?= =?us-ascii?Q?dEsjDtHkDkUBCWG9g+s5xqfioAjloI4uyC0yB4Eh92wKMrWRlG3xc5b/OpnH?= =?us-ascii?Q?dg=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR02MB0811; 5:wuGCFws7PCsKGp9ds8mptlTPn7tXbXjYKyJsgviwOPn6WVsfFlobhxn7uKFfjvG/CzVJeUTIX4KWQD8+GPoO9zEae16YiErNKNk+L0AT15Q8G5tamPWOsdz+ey5sUeJxpzMBX4fSyexg3crulGPjVQ==; 24:4aKkTYaXEeCHz6B2zbDOs0ZCFsvvMBgDLNDPhdRUk4/Wng1IQb2UVwE5Q87+7M9dSWDZkxbSdTRuAaxYduNlGt4lOvIWX2du4YJe/VMcOwY=; 20:FtoKuM8U3q09rogWmosUw8FpEqUEJleIIftNPH4/M2KbJyQWRRkKhg9wxN36nBYVqLppIRlW4qVkRdV5g0yC5g== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2015 08:26:20.7145 (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: HE1PR02MB0811 Cc: Cyril Chemparathy Subject: [dpdk-dev] [PATCH v5 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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: Cyril Chemparathy 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