]> git.droids-corp.org - dpdk.git/commitdiff
eal/bsd: query the cpu count only once
authorBruce Richardson <bruce.richardson@intel.com>
Thu, 23 Mar 2017 15:09:58 +0000 (15:09 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 27 Mar 2017 21:56:58 +0000 (23:56 +0200)
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 <bruce.richardson@intel.com>
lib/librte_eal/bsdapp/eal/eal_lcore.c

index b8bfafde06ae48fc1efcdf2879d882e5c874c673..bc584dd53ab9b11a85c0d941c86d905fbba1a6cb 100644 (file)
@@ -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;
 }