aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2018-09-11 20:27:09 +0200
committerDamjan Marion <dmarion@me.com>2018-10-01 09:44:58 +0000
commit5d64c7868f67749a6c99eb4ee5998b518ab6c71c (patch)
tree57ce487477ddb12dddeb21340ad875328f2ea5a0 /src/vlib
parent28c142e3dedc0b136003f33f67243bf3c1873b71 (diff)
thread: Add show threads api
Change-Id: I3124238ab4d43bcef5590bad33a4ff0b5d8b7d15 Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/node_cli.c4
-rw-r--r--src/vlib/threads.c32
-rw-r--r--src/vlib/threads.h8
-rw-r--r--src/vlib/threads_cli.c54
4 files changed, 40 insertions, 58 deletions
diff --git a/src/vlib/node_cli.c b/src/vlib/node_cli.c
index 3dbf672d441..00199d999d1 100644
--- a/src/vlib/node_cli.c
+++ b/src/vlib/node_cli.c
@@ -345,9 +345,9 @@ show_node_runtime (vlib_main_t * vm,
if (j > 0)
vlib_cli_output (vm, "---------------");
- if (w->lcore_id > -1)
+ if (w->cpu_id > -1)
vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
- w->lcore_id);
+ w->cpu_id);
else
vlib_cli_output (vm, "Thread %d %s", j, w->name);
}
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index def8927e29f..055998adac8 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -17,6 +17,7 @@
#include <signal.h>
#include <math.h>
#include <vppinfra/format.h>
+#include <vppinfra/linux/sysfs.h>
#include <vlib/vlib.h>
#include <vlib/threads.h>
@@ -305,7 +306,7 @@ vlib_thread_init (vlib_main_t * vm)
w = vlib_worker_threads;
w->thread_mheap = clib_mem_get_heap ();
w->thread_stack = vlib_thread_stacks[0];
- w->lcore_id = tm->main_lcore;
+ w->cpu_id = tm->main_lcore;
w->lwp = syscall (SYS_gettid);
w->thread_id = pthread_self ();
tm->n_vlib_mains = 1;
@@ -600,21 +601,42 @@ vlib_worker_thread_bootstrap_fn (void *arg)
return rv;
}
+static void
+vlib_get_thread_core_socket (vlib_worker_thread_t * w, unsigned cpu_id)
+{
+ const char *sys_cpu_path = "/sys/devices/system/cpu/cpu";
+ u8 *p = 0;
+ int core_id = -1, socket_id = -1;
+
+ p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, cpu_id, 0);
+ clib_sysfs_read ((char *) p, "%d", &core_id);
+ vec_reset_length (p);
+ p =
+ format (p, "%s%u/topology/physical_package_id%c", sys_cpu_path, cpu_id,
+ 0);
+ clib_sysfs_read ((char *) p, "%d", &socket_id);
+ vec_free (p);
+
+ w->core_id = core_id;
+ w->socket_id = socket_id;
+}
+
static clib_error_t *
-vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned lcore_id)
+vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
{
vlib_thread_main_t *tm = &vlib_thread_main;
void *(*fp_arg) (void *) = fp;
- w->lcore_id = lcore_id;
+ w->cpu_id = cpu_id;
+ vlib_get_thread_core_socket (w, cpu_id);
if (tm->cb.vlib_launch_thread_cb && !w->registration->use_pthreads)
- return tm->cb.vlib_launch_thread_cb (fp, (void *) w, lcore_id);
+ return tm->cb.vlib_launch_thread_cb (fp, (void *) w, cpu_id);
else
{
pthread_t worker;
cpu_set_t cpuset;
CPU_ZERO (&cpuset);
- CPU_SET (lcore_id, &cpuset);
+ CPU_SET (cpu_id, &cpuset);
if (pthread_create (&worker, NULL /* attr */ , fp_arg, (void *) w))
return clib_error_return_unix (0, "pthread_create");
diff --git a/src/vlib/threads.h b/src/vlib/threads.h
index 7de0412362e..71b5d0c8261 100644
--- a/src/vlib/threads.h
+++ b/src/vlib/threads.h
@@ -108,7 +108,9 @@ typedef struct
volatile u32 *node_reforks_required;
long lwp;
- int lcore_id;
+ int cpu_id;
+ int core_id;
+ int socket_id;
pthread_t thread_id;
} vlib_worker_thread_t;
@@ -270,8 +272,8 @@ typedef enum
typedef struct
{
clib_error_t *(*vlib_launch_thread_cb) (void *fp, vlib_worker_thread_t * w,
- unsigned lcore_id);
- clib_error_t *(*vlib_thread_set_lcore_cb) (u32 thread, u16 lcore);
+ unsigned cpu_id);
+ clib_error_t *(*vlib_thread_set_lcore_cb) (u32 thread, u16 cpu);
} vlib_thread_callbacks_t;
typedef struct
diff --git a/src/vlib/threads_cli.c b/src/vlib/threads_cli.c
index bb9ddbc6e3c..a47d86401bc 100644
--- a/src/vlib/threads_cli.c
+++ b/src/vlib/threads_cli.c
@@ -15,7 +15,6 @@
#define _GNU_SOURCE
#include <vppinfra/format.h>
-#include <vppinfra/linux/sysfs.h>
#include <vlib/vlib.h>
#include <vlib/threads.h>
@@ -64,57 +63,16 @@ show_threads_fn (vlib_main_t * vm,
line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
- int lcore = -1;
- cpu_set_t cpuset;
- CPU_ZERO (&cpuset);
- int ret = -1;
-
- ret =
- pthread_getaffinity_np (w->thread_id, sizeof (cpu_set_t), &cpuset);
- if (!ret)
- {
- int c;
- for (c = 0; c < CPU_SETSIZE; c++)
- if (CPU_ISSET (c, &cpuset))
- {
- if (lcore > -1)
- {
- lcore = -2;
- break;
- }
- lcore = c;
- }
- }
- else
- {
- lcore = w->lcore_id;
- }
-
- if (lcore > -1)
+ int cpu_id = w->cpu_id;
+ if (cpu_id > -1)
{
- const char *sys_cpu_path = "/sys/devices/system/cpu/cpu";
- int socket_id = -1;
- int core_id = -1;
- u8 *p = 0;
-
- p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, lcore, 0);
- clib_sysfs_read ((char *) p, "%d", &core_id);
-
- vec_reset_length (p);
- p =
- format (p,
- "%s%u/topology/physical_package_id%c",
- sys_cpu_path, lcore, 0);
- clib_sysfs_read ((char *) p, "%d", &socket_id);
- vec_free (p);
-
- line = format (line, "%-7u%-7u%-7u%", lcore, core_id, socket_id);
+ int core_id = w->core_id;
+ int socket_id = w->socket_id;
+ line = format (line, "%-7u%-7u%-7u%", cpu_id, core_id, socket_id);
}
else
{
- line =
- format (line, "%-7s%-7s%-7s%", (lcore == -2) ? "M" : "n/a", "n/a",
- "n/a");
+ line = format (line, "%-7s%-7s%-7s%", "n/a", "n/a", "n/a");
}
vlib_cli_output (vm, "%v", line);