From patchwork Wed May 27 08:40:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ananyev, Konstantin" X-Patchwork-Id: 4914 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 E57675A40; Wed, 27 May 2015 10:40:23 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 201AFE72 for ; Wed, 27 May 2015 10:40:21 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 27 May 2015 01:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,503,1427785200"; d="scan'208";a="498794096" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by FMSMGA003.fm.intel.com with ESMTP; 27 May 2015 01:40:20 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t4R8eIIP004883; Wed, 27 May 2015 09:40:19 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t4R8eIIg021464; Wed, 27 May 2015 09:40:18 +0100 Received: (from kananye1@localhost) by sivswdev02.ir.intel.com with id t4R8eIB8021460; Wed, 27 May 2015 09:40:18 +0100 From: Konstantin Ananyev To: dev@dpdk.org Date: Wed, 27 May 2015 09:40:05 +0100 Message-Id: <1432716005-21290-1-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1432571266-25840-2-git-send-email-adrien.mazarguil@6wind.com> References: <1432571266-25840-2-git-send-email-adrien.mazarguil@6wind.com> Subject: [dpdk-dev] [PATCHv3] mempool: fix pages computation to determine number of objects 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" v3: - Fixed typo in the commit message. v2: - As suggested in comments use slightly different approach for the fix. In rte_mempool_obj_iter(), when element boundary coincides with page boundary, even if a single page is required per object, a loop checks that the next page is contiguous and drops the first one otherwise. This commit checks subsequent pages only when several are required per object. Signed-off-by: Konstantin Ananyev --- lib/librte_mempool/rte_mempool.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 01972ba..ecb03b3 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -156,7 +156,7 @@ rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align, rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg) { uint32_t i, j, k; - uint32_t pgn; + uint32_t pgn, pgf; uintptr_t end, start, va; uintptr_t pg_sz; @@ -171,10 +171,14 @@ rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align, start = RTE_ALIGN_CEIL(va, align); end = start + elt_sz; - pgn = (end >> pg_shift) - (start >> pg_shift); + /* index of the first page for the next element. */ + pgf = (end >> pg_shift) - (start >> pg_shift); + + /* index of the last page for the current element. */ + pgn = ((end - 1) >> pg_shift) - (start >> pg_shift); pgn += j; - /* do we have enough space left for the next element. */ + /* do we have enough space left for the element. */ if (pgn >= pg_num) break; @@ -194,7 +198,7 @@ rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align, obj_iter(obj_iter_arg, (void *)start, (void *)end, i); va = end; - j = pgn; + j += pgf; i++; } else { va = RTE_ALIGN_CEIL((va + 1), pg_sz);