From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id B8F921BB7D for ; Wed, 11 Apr 2018 14:30:56 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2018 05:30:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,436,1517904000"; d="scan'208";a="219558519" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga005.fm.intel.com with ESMTP; 11 Apr 2018 05:30:51 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w3BCUpUI012376; Wed, 11 Apr 2018 13:30:51 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w3BCUpfn013746; Wed, 11 Apr 2018 13:30:51 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w3BCUptA013742; Wed, 11 Apr 2018 13:30:51 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: keith.wiles@intel.com, jianfeng.tan@intel.com, andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com, benjamin.walker@intel.com, bruce.richardson@intel.com, thomas@monjalon.net, konstantin.ananyev@intel.com, kuralamudhan.ramakrishnan@intel.com, louise.m.daly@intel.com, nelio.laranjeiro@6wind.com, yskoh@mellanox.com, pepperjo@japf.ch, jerin.jacob@caviumnetworks.com, hemant.agrawal@nxp.com, olivier.matz@6wind.com, shreyansh.jain@nxp.com, gowrishankar.m@linux.vnet.ibm.com Date: Wed, 11 Apr 2018 13:30:06 +0100 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 31/70] test: use memseg walk instead of iteration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Apr 2018 12:30:57 -0000 Reduce dependency on internal details of EAL memory subsystem, and simplify code. Signed-off-by: Anatoly Burakov Tested-by: Santosh Shukla Tested-by: Hemant Agrawal Tested-by: Gowrishankar Muthukrishnan --- test/test/test_malloc.c | 40 +++++++++++++++++++++++------------- test/test/test_memory.c | 23 +++++++++++---------- test/test/test_memzone.c | 53 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 74 insertions(+), 42 deletions(-) diff --git a/test/test/test_malloc.c b/test/test/test_malloc.c index ccc5fea..28c241f 100644 --- a/test/test/test_malloc.c +++ b/test/test/test_malloc.c @@ -705,16 +705,34 @@ test_malloc_bad_params(void) return -1; } +static int +check_socket_mem(const struct rte_memseg *ms, void *arg) +{ + int32_t *socket = arg; + + return *socket == ms->socket_id; +} + /* Check if memory is available on a specific socket */ static int is_mem_on_socket(int32_t socket) { - const struct rte_memseg *ms = rte_eal_get_physmem_layout(); - unsigned i; + return rte_memseg_walk(check_socket_mem, &socket); +} - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if (socket == ms[i].socket_id) - return 1; +struct walk_param { + void *addr; + int32_t socket; +}; +static int +find_socket(const struct rte_memseg *ms, void *arg) +{ + struct walk_param *param = arg; + + if (param->addr >= ms->addr && + param->addr < RTE_PTR_ADD(ms->addr, ms->len)) { + param->socket = ms->socket_id; + return 1; } return 0; } @@ -726,15 +744,9 @@ is_mem_on_socket(int32_t socket) static int32_t addr_to_socket(void * addr) { - const struct rte_memseg *ms = rte_eal_get_physmem_layout(); - unsigned i; - - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if ((ms[i].addr <= addr) && - ((uintptr_t)addr < - ((uintptr_t)ms[i].addr + (uintptr_t)ms[i].len))) - return ms[i].socket_id; - } + struct walk_param param = {.addr = addr, .socket = 0}; + if (rte_memseg_walk(find_socket, ¶m) > 0) + return param.socket; return -1; } diff --git a/test/test/test_memory.c b/test/test/test_memory.c index 972321f..c9b287c 100644 --- a/test/test/test_memory.c +++ b/test/test/test_memory.c @@ -23,12 +23,20 @@ */ static int +check_mem(const struct rte_memseg *ms, void *arg __rte_unused) +{ + volatile uint8_t *mem = (volatile uint8_t *) ms->addr; + size_t i; + + for (i = 0; i < ms->len; i++, mem++) + *mem; + return 0; +} + +static int test_memory(void) { uint64_t s; - unsigned i; - size_t j; - const struct rte_memseg *mem; /* * dump the mapped memory: the python-expect script checks @@ -45,14 +53,7 @@ test_memory(void) } /* try to read memory (should not segfault) */ - mem = rte_eal_get_physmem_layout(); - for (i = 0; i < RTE_MAX_MEMSEG && mem[i].addr != NULL ; i++) { - - /* check memory */ - for (j = 0; jhugepage_sz == RTE_PGSIZE_2M) + wa->hugepage_2MB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_1G) + wa->hugepage_1GB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_16M) + wa->hugepage_16MB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_16G) + wa->hugepage_16GB_avail = 1; + + return 0; +} + static int test_memzone_reserve_flags(void) { const struct rte_memzone *mz; - const struct rte_memseg *ms; - int hugepage_2MB_avail = 0; - int hugepage_1GB_avail = 0; - int hugepage_16MB_avail = 0; - int hugepage_16GB_avail = 0; + struct walk_arg wa; + int hugepage_2MB_avail, hugepage_1GB_avail; + int hugepage_16MB_avail, hugepage_16GB_avail; const size_t size = 100; - int i = 0; - ms = rte_eal_get_physmem_layout(); - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if (ms[i].hugepage_sz == RTE_PGSIZE_2M) - hugepage_2MB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_1G) - hugepage_1GB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_16M) - hugepage_16MB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_16G) - hugepage_16GB_avail = 1; - } + + memset(&wa, 0, sizeof(wa)); + + rte_memseg_walk(find_available_pagesz, &wa); + + hugepage_2MB_avail = wa.hugepage_2MB_avail; + hugepage_1GB_avail = wa.hugepage_1GB_avail; + hugepage_16MB_avail = wa.hugepage_16MB_avail; + hugepage_16GB_avail = wa.hugepage_16GB_avail; + /* Display the availability of 2MB ,1GB, 16MB, 16GB pages */ if (hugepage_2MB_avail) printf("2MB Huge pages available\n"); -- 2.7.4