Skip to contentSkip to conversation

eal/bsd: query the cpu count only once

PATCH Applied Bruce Richardson 2 participants 2 messages Mar 23, 2017 – Mar 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 lib/librte_eal/bsdapp/eal/eal_lcore.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_lcore.c +5 -3
index b8bfafde0..bc584dd53 100644
@@ -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;
 }
 
Signature · 1 line
2.11.0
#1 lore raw

2017-03-23 15:09, Bruce Richardson:

Quoted 5 lines

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.

Applied, thanks