aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/unix-misc.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2024-02-12 19:44:58 +0000
committerMohammed HAWARI <momohawari@gmail.com>2024-03-18 16:01:35 +0000
commit3eb6cbec50a5cbe4c3465d60ba6aea7bf2845cd1 (patch)
tree0f45044087400911e213048c1967ac96a9f8ea29 /src/vppinfra/unix-misc.c
parent8799bf6ca6b78321049bbc397256dd8b3884d829 (diff)
vppinfra: os agnostic api for getting CPU information
Avoid direct sysfs reads when possible... Type: improvement Change-Id: I2b84cd18f3da47925d068951f24b79b5b6e20bb1 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/unix-misc.c')
-rw-r--r--src/vppinfra/unix-misc.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c
index 623b2e98555..e0591ff4604 100644
--- a/src/vppinfra/unix-misc.c
+++ b/src/vppinfra/unix-misc.c
@@ -268,7 +268,7 @@ __clib_export clib_bitmap_t *
os_get_online_cpu_core_bitmap ()
{
#if __linux__
- return clib_sysfs_list_to_bitmap ("/sys/devices/system/cpu/online");
+ return clib_sysfs_read_bitmap ("/sys/devices/system/cpu/online");
#else
return 0;
#endif
@@ -278,11 +278,54 @@ __clib_export clib_bitmap_t *
os_get_online_cpu_node_bitmap ()
{
#if __linux__
- return clib_sysfs_list_to_bitmap ("/sys/devices/system/node/online");
+ return clib_sysfs_read_bitmap ("/sys/devices/system/node/online");
#else
return 0;
#endif
}
+__clib_export clib_bitmap_t *
+os_get_cpu_on_node_bitmap (int node)
+{
+#if __linux__
+ return clib_sysfs_read_bitmap ("/sys/devices/system/node/node%u/cpulist",
+ node);
+#else
+ return 0;
+#endif
+}
+
+__clib_export clib_bitmap_t *
+os_get_cpu_with_memory_bitmap ()
+{
+#if __linux__
+ return clib_sysfs_read_bitmap ("/sys/devices/system/node/has_memory");
+#else
+ return 0;
+#endif
+}
+
+__clib_export int
+os_get_cpu_phys_core_id (int cpu_id)
+{
+#if __linux
+ int core_id = -1;
+ clib_error_t *err;
+ u8 *p;
+
+ p =
+ format (0, "/sys/devices/system/cpu/cpu%u/topology/core_id%c", cpu_id, 0);
+ err = clib_sysfs_read ((char *) p, "%d", &core_id);
+ vec_free (p);
+ if (err)
+ {
+ clib_error_free (err);
+ return -1;
+ }
+ return core_id;
+#else
+ return -1;
+#endif
+}
/*
* fd.io coding-style-patch-verification: ON