vcl: add api to retrieve num bytes for tx
[vpp.git] / src / vppinfra / unix-misc.c
index 0c5d96c..e0591ff 100644 (file)
 
 #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>
@@ -152,6 +156,7 @@ clib_file_get_resolved_basename (char *fmt, ...)
   if (r < 1)
     return 0;
 
+  buffer[r] = 0;
   p = buffer + r - 1;
   while (p > buffer && p[-1] != '/')
     p--;
@@ -159,6 +164,7 @@ clib_file_get_resolved_basename (char *fmt, ...)
   while (p[0])
     vec_add1 (s, p++[0]);
 
+  vec_add1 (s, 0);
   return s;
 }
 
@@ -258,6 +264,69 @@ os_get_nthreads (void)
   return 1;
 }
 
+__clib_export clib_bitmap_t *
+os_get_online_cpu_core_bitmap ()
+{
+#if __linux__
+  return clib_sysfs_read_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_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
  *