I've folded in the following incremental which causes us to only do the core calculation once since it looks so expensive. I think this is fine for now, and I intended to merge it, but I think we should revisit the assembler instruction. It's probably cleaner, and would support platforms like Windows and BSD which are becoming more important.
Acked-by: Ethan Jackson <et...@nicira.com> --- lib/ovs-thread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index f800d7d..1a633cf 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -374,11 +374,15 @@ parse_cpuinfo(long int *n_cores) unsigned int count_cpu_cores(void) { - long int n_cores; + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + static long int n_cores; - parse_cpuinfo(&n_cores); - if (!n_cores) { - n_cores = sysconf(_SC_NPROCESSORS_ONLN); + if (ovsthread_once_start(&once)) { + parse_cpuinfo(&n_cores); + if (!n_cores) { + n_cores = sysconf(_SC_NPROCESSORS_ONLN); + } + ovsthread_once_done(&once); } return n_cores > 0 ? n_cores : 0; -- 1.8.1.2 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev