summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux
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/linux
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/linux')
-rw-r--r--src/vppinfra/linux/mem.c1
-rw-r--r--src/vppinfra/linux/sysfs.c14
-rw-r--r--src/vppinfra/linux/sysfs.h3
3 files changed, 13 insertions, 5 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 8f696a1036a..734f5c4788c 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -31,7 +31,6 @@
#include <vppinfra/bitmap.h>
#include <vppinfra/format.h>
#include <vppinfra/clib_error.h>
-#include <vppinfra/linux/sysfs.h>
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
diff --git a/src/vppinfra/linux/sysfs.c b/src/vppinfra/linux/sysfs.c
index 6d9f859640c..61ee6378c8c 100644
--- a/src/vppinfra/linux/sysfs.c
+++ b/src/vppinfra/linux/sysfs.c
@@ -237,13 +237,21 @@ clib_sysfs_prealloc_hugepages (int numa_node, int log2_page_size, int nr)
return clib_sysfs_set_nr_hugepages (numa_node, log2_page_size, n + needed);
}
-__clib_export uword *
-clib_sysfs_list_to_bitmap (char *filename)
+__clib_export clib_bitmap_t *
+clib_sysfs_read_bitmap (char *fmt, ...)
{
FILE *fp;
uword *r = 0;
+ va_list va;
+ u8 *filename;
+
+ va_start (va, fmt);
+ filename = va_format (0, fmt, &va);
+ va_end (va);
+ vec_add1 (filename, 0);
- fp = fopen (filename, "r");
+ fp = fopen ((char *) filename, "r");
+ vec_free (filename);
if (fp != NULL)
{
diff --git a/src/vppinfra/linux/sysfs.h b/src/vppinfra/linux/sysfs.h
index a616fa422a1..f2f822d9741 100644
--- a/src/vppinfra/linux/sysfs.h
+++ b/src/vppinfra/linux/sysfs.h
@@ -17,6 +17,7 @@
#define included_linux_sysfs_h
#include <vppinfra/error.h>
+#include <vppinfra/bitmap.h>
clib_error_t *clib_sysfs_write (char *file_name, char *fmt, ...);
@@ -33,7 +34,7 @@ clib_error_t *clib_sysfs_get_surplus_hugepages (int numa_node,
clib_error_t *clib_sysfs_prealloc_hugepages (int numa_node,
int log2_page_size, int nr);
-uword *clib_sysfs_list_to_bitmap (char *filename);
+uword *clib_sysfs_read_bitmap (char *fmt, ...);
#endif /* included_linux_sysfs_h */