diff mbox series

[ovs-dev,2/2] ovs-thread: Clean duplicated count_total_cores

Message ID 20220826132754.360124-3-amorenoz@redhat.com
State Superseded
Headers show
Series Detect changes in cpu affinity | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Adrian Moreno Aug. 26, 2022, 1:27 p.m. UTC
Total cpu count is already being calculated as part of count_cpu_cores.
Consolidate both functions to avoid code duplication.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 lib/ovs-thread.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 0e52a0da7..910d13e9c 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -632,22 +632,7 @@  ovs_thread_stats_next_bucket(const struct ovsthread_stats *stats, size_t i)
 int
 count_cpu_cores(void)
 {
-    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
-    static long int n_total_cores;
-    long int n_cores;
-
-    if (ovsthread_once_start(&once)) {
-#ifndef _WIN32
-        n_total_cores = sysconf(_SC_NPROCESSORS_ONLN);
-#else
-        SYSTEM_INFO sysinfo;
-        GetSystemInfo(&sysinfo);
-        n_total_cores = sysinfo.dwNumberOfProcessors;
-#endif
-        ovsthread_once_done(&once);
-    }
-
-    n_cores = n_total_cores;
+    long int n_cores = count_total_cores();
 #ifdef __linux__
     if (n_cores > 0) {
         cpu_set_t *set = CPU_ALLOC(n_cores);
@@ -670,14 +655,19 @@  count_cpu_cores(void)
 int
 count_total_cores(void)
 {
-    long int n_cores;
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+    static long int n_cores;
 
+    if (ovsthread_once_start(&once)) {
 #ifndef _WIN32
-    n_cores = sysconf(_SC_NPROCESSORS_CONF);
+        n_cores = sysconf(_SC_NPROCESSORS_ONLN);
 #else
-    n_cores = 0;
-    errno = ENOTSUP;
+        SYSTEM_INFO sysinfo;
+        GetSystemInfo(&sysinfo);
+        n_cores = sysinfo.dwNumberOfProcessors;
 #endif
+        ovsthread_once_done(&once);
+    }
 
     return n_cores > 0 ? n_cores : 0;
 }