aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2024-02-29 16:14:27 +0100
committerBeno�t Ganne <bganne@cisco.com>2024-03-04 08:53:08 +0000
commit4b6614030f384f7c8d847360cacf5c7f7560c6be (patch)
treeb560c46a2cda2bf6b16e147a52a70ed83c3ce1ce
parent2921e0234185f615d7530343b340573e2cb5caec (diff)
vppinfra: add os_get_online_cpu_core() and os_get_online_cpu_node()
Type: improvement Change-Id: I6f99f09c7724ce656a4f41a1d5f9c88d74c00faf Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/plugins/perfmon/intel/uncore.c11
-rw-r--r--src/vlib/buffer.c6
-rw-r--r--src/vlib/linux/pci.c8
-rw-r--r--src/vlib/threads.c14
-rw-r--r--src/vppinfra/unix-misc.c24
-rw-r--r--src/vppinfra/unix.h6
6 files changed, 47 insertions, 22 deletions
diff --git a/src/plugins/perfmon/intel/uncore.c b/src/plugins/perfmon/intel/uncore.c
index a709a8d40be..316ebb13571 100644
--- a/src/plugins/perfmon/intel/uncore.c
+++ b/src/plugins/perfmon/intel/uncore.c
@@ -15,6 +15,8 @@
#include <vnet/vnet.h>
#include <vppinfra/linux/sysfs.h>
+#include <vppinfra/bitmap.h>
+#include <vppinfra/unix.h>
#include <perfmon/perfmon.h>
#include <perfmon/intel/core.h>
#include <perfmon/intel/uncore.h>
@@ -148,12 +150,9 @@ intel_uncore_init (vlib_main_t *vm, perfmon_source_t *src)
u32 i, j;
u8 *s = 0;
- if ((err = clib_sysfs_read ("/sys/devices/system/node/online", "%U",
- unformat_bitmap_list, &node_bitmap)))
- {
- clib_error_free (err);
- return clib_error_return (0, "failed to discover numa topology");
- }
+ node_bitmap = os_get_online_cpu_node_bitmap ();
+ if (!node_bitmap)
+ return clib_error_return (0, "failed to discover numa topology");
clib_bitmap_foreach (i, node_bitmap)
{
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index b5200ba5029..e1dcf7ed827 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -44,6 +44,8 @@
*/
#include <vppinfra/linux/sysfs.h>
+#include <vppinfra/bitmap.h>
+#include <vppinfra/unix.h>
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vlib/stats/stats.h>
@@ -840,9 +842,7 @@ vlib_buffer_main_init (struct vlib_main_t * vm)
clib_spinlock_init (&bm->buffer_known_hash_lockp);
- if ((err = clib_sysfs_read ("/sys/devices/system/node/online", "%U",
- unformat_bitmap_list, &bmp)))
- clib_error_free (err);
+ bmp = os_get_online_cpu_node_bitmap ();
if ((err = clib_sysfs_read ("/sys/devices/system/node/has_memory", "%U",
unformat_bitmap_list, &bmp_has_memory)))
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index 0435d569bec..3af97414ed8 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -38,6 +38,8 @@
*/
#include <vppinfra/linux/sysfs.h>
+#include <vppinfra/bitmap.h>
+#include <vppinfra/unix.h>
#include <vlib/vlib.h>
#include <vlib/pci/pci.h>
@@ -257,11 +259,7 @@ vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
}
if (di->numa_node == -1)
{
- /* if '/sys/bus/pci/devices/<device id>/numa_node' returns -1 and
- it is a SMP system, set numa_node to 0. */
- if ((err = clib_sysfs_read ("/sys/devices/system/node/online", "%U",
- unformat_bitmap_list, &bmp)))
- clib_error_free (err);
+ bmp = os_get_online_cpu_node_bitmap ();
if (clib_bitmap_count_set_bits (bmp) == 1)
di->numa_node = 0;
}
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 03fda388edf..b96cbf9470c 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -20,6 +20,8 @@
#include <vppinfra/time_range.h>
#include <vppinfra/interrupt.h>
#include <vppinfra/linux/sysfs.h>
+#include <vppinfra/bitmap.h>
+#include <vppinfra/unix.h>
#include <vlib/vlib.h>
#include <vlib/threads.h>
@@ -186,10 +188,8 @@ vlib_thread_init (vlib_main_t * vm)
ASSERT (stats_num_worker_threads_dir_index != ~0);
/* get bitmaps of active cpu cores and sockets */
- tm->cpu_core_bitmap =
- clib_sysfs_list_to_bitmap ("/sys/devices/system/cpu/online");
- tm->cpu_socket_bitmap =
- clib_sysfs_list_to_bitmap ("/sys/devices/system/node/online");
+ tm->cpu_core_bitmap = os_get_online_cpu_core_bitmap ();
+ tm->cpu_socket_bitmap = os_get_online_cpu_node_bitmap ();
avail_cpu = clib_bitmap_dup (tm->cpu_core_bitmap);
@@ -440,9 +440,7 @@ vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id)
clib_sysfs_read ((char *) p, "%d", &core_id);
vec_reset_length (p);
- /* *INDENT-OFF* */
- clib_sysfs_read ("/sys/devices/system/node/online", "%U",
- unformat_bitmap_list, &nbmp);
+ nbmp = os_get_online_cpu_node_bitmap ();
clib_bitmap_foreach (node, nbmp) {
p = format (p, "%s%u/cpulist%c", sys_node_path, node, 0);
clib_sysfs_read ((char *) p, "%U", unformat_bitmap_list, &cbmp);
@@ -451,7 +449,7 @@ vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id)
vec_reset_length (cbmp);
vec_reset_length (p);
}
- /* *INDENT-ON* */
+
vec_free (nbmp);
vec_free (cbmp);
vec_free (p);
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c
index 6a7328bd873..623b2e98555 100644
--- a/src/vppinfra/unix-misc.c
+++ b/src/vppinfra/unix-misc.c
@@ -37,8 +37,12 @@
#include <vppinfra/error.h>
#include <vppinfra/os.h>
+#include <vppinfra/bitmap.h>
#include <vppinfra/unix.h>
#include <vppinfra/format.h>
+#ifdef __linux__
+#include <vppinfra/linux/sysfs.h>
+#endif
#include <sys/stat.h>
#include <sys/types.h>
@@ -260,6 +264,26 @@ os_get_nthreads (void)
return 1;
}
+__clib_export clib_bitmap_t *
+os_get_online_cpu_core_bitmap ()
+{
+#if __linux__
+ return clib_sysfs_list_to_bitmap ("/sys/devices/system/cpu/online");
+#else
+ return 0;
+#endif
+}
+
+__clib_export clib_bitmap_t *
+os_get_online_cpu_node_bitmap ()
+{
+#if __linux__
+ return clib_sysfs_list_to_bitmap ("/sys/devices/system/node/online");
+#else
+ return 0;
+#endif
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vppinfra/unix.h b/src/vppinfra/unix.h
index 5b82c23a3c0..b43043a567b 100644
--- a/src/vppinfra/unix.h
+++ b/src/vppinfra/unix.h
@@ -53,6 +53,12 @@ clib_error_t *clib_file_contents (char *file, u8 ** result);
/* As above but for /proc file system on Linux. */
clib_error_t *unix_proc_file_contents (char *file, u8 ** result);
+/* Retrieve bitmap of online cpu cures */
+clib_bitmap_t *os_get_online_cpu_core_bitmap ();
+
+/* Retrieve bitmap of online cpu nodes (sockets) */
+clib_bitmap_t *os_get_online_cpu_node_bitmap ();
+
#endif /* included_clib_unix_h */
/*