From: Bruce Richardson Date: Thu, 23 Mar 2017 15:09:58 +0000 (+0000) Subject: eal/bsd: query the cpu count only once X-Git-Tag: spdx-start~4395 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6f6d2a66f8d370c07efe85b08ca93ec3728a2d01;p=dpdk.git eal/bsd: query the cpu count only once Rather than querying the number of CPUs on the system multiple times, and printing out the number each time, just query the value from sysctl once and store it for future reuse. Signed-off-by: Bruce Richardson --- diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c index b8bfafde06..bc584dd53a 100644 --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c +++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c @@ -53,12 +53,14 @@ eal_cpu_core_id(__rte_unused unsigned lcore_id) static int eal_get_ncpus(void) { + static int ncpu = -1; int mib[2] = {CTL_HW, HW_NCPU}; - int ncpu; size_t len = sizeof(ncpu); - sysctl(mib, 2, &ncpu, &len, NULL, 0); - RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu); + if (ncpu < 0) { + sysctl(mib, 2, &ncpu, &len, NULL, 0); + RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu); + } return ncpu; }