Store numa-noda and cpu-index in vlib_main_t 02/16902/3
authorDamjan Marion <damarion@cisco.com>
Sat, 19 Jan 2019 22:45:36 +0000 (23:45 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Sun, 20 Jan 2019 19:23:42 +0000 (19:23 +0000)
Change-Id: If88ccd965122b9318a39a8d71b53334cd1fd81e4
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vlib/main.h
src/vlib/threads.c
src/vlib/unix/main.c
src/vppinfra/cpu.h

index 474756b..8a25ce8 100644 (file)
@@ -172,8 +172,10 @@ typedef struct vlib_main_t
   /* Hash table to record which init functions have been called. */
   uword *init_functions_called;
 
-  /* to compare with node runtime */
+  /* thread, cpu and numa_node indices */
   u32 thread_index;
+  u32 cpu_index;
+  u32 numa_node;
 
   /* List of init functions to call, setup by constructors */
   _vlib_init_function_list_elt_t *init_function_registrations;
index 3e184e3..45e4d89 100644 (file)
@@ -1681,6 +1681,9 @@ vlib_worker_thread_fn (void *arg)
 
   ASSERT (vm->thread_index == vlib_get_thread_index ());
 
+  vm->cpu_index = clib_get_current_cpu_index ();
+  vm->numa_node = clib_get_current_numa_node ();
+
   vlib_worker_thread_init (w);
   clib_time_init (&vm->clib_time);
   clib_mem_set_heap (w->thread_mheap);
index 08f0506..4d6519e 100755 (executable)
@@ -671,6 +671,8 @@ vlib_unix_main (int argc, char *argv[])
 
   __os_thread_index = 0;
   vm->thread_index = 0;
+  vm->cpu_index = clib_get_current_cpu_index ();
+  vm->numa_node = clib_get_current_numa_node ();
 
   i = clib_calljmp (thread0, (uword) vm,
                    (void *) (vlib_thread_stacks[0] +
index 6dc0a23..8341eaf 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef included_clib_cpu_h
 #define included_clib_cpu_h
 
+#include <sys/syscall.h>
 #include <vppinfra/format.h>
 
 /*
@@ -99,6 +100,22 @@ _ (asimddp,    20) \
 _ (sha512,     21) \
 _ (sve,        22)
 
+static inline u32
+clib_get_current_cpu_index ()
+{
+  unsigned cpu, node;
+  syscall (__NR_getcpu, &cpu, &node, 0);
+  return cpu;
+}
+
+static inline u32
+clib_get_current_numa_node ()
+{
+  unsigned cpu, node;
+  syscall (__NR_getcpu, &cpu, &node, 0);
+  return node;
+}
+
 #if defined(__x86_64__)
 #include "cpuid.h"