All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eal/bsd: query the cpu count only once
@ 2017-03-23 15:09 Bruce Richardson
  2017-03-27 21:51 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Bruce Richardson @ 2017-03-23 15:09 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
index b8bfafde0..bc584dd53 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;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] eal/bsd: query the cpu count only once
  2017-03-23 15:09 [PATCH] eal/bsd: query the cpu count only once Bruce Richardson
@ 2017-03-27 21:51 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2017-03-27 21:51 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

2017-03-23 15:09, Bruce Richardson:
> 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>

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-27 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 15:09 [PATCH] eal/bsd: query the cpu count only once Bruce Richardson
2017-03-27 21:51 ` Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.