summaryrefslogtreecommitdiffstats
path: root/vlib
diff options
context:
space:
mode:
authorPavel Kotucek <pkotucek@cisco.com>2016-10-07 08:37:28 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2016-10-13 08:13:37 +0000
commit9876520f9ba746ed4d9923f392911c4f1888a105 (patch)
treea6dfa09134fcb79c5ff56cbf04c3425a1f637e97 /vlib
parent1946a12a52deddfb501d2bdf320ff280cb42a076 (diff)
vpp_lite: add cpu pinning support (VPP-467)
Proper cpu pinning in vpp_lite platform, like in normal vpp image. Extended “show threads” command to show propper information. Changed handling of coreID and socketID for threads in "show threads" CLI, pthread_getaffinity is used instead of info stored in DPDK. Change-Id: Ic8299ec5e284472bb10a37a95fadeed57b6edae8 Signed-off-by: Pavel Kotucek <pkotucek@cisco.com>
Diffstat (limited to 'vlib')
-rw-r--r--vlib/vlib/node_cli.c4
-rw-r--r--vlib/vlib/threads.c23
-rw-r--r--vlib/vlib/threads.h3
-rw-r--r--vlib/vlib/threads_cli.c63
4 files changed, 62 insertions, 31 deletions
diff --git a/vlib/vlib/node_cli.c b/vlib/vlib/node_cli.c
index af9b47dd05d..05d0f0b5a95 100644
--- a/vlib/vlib/node_cli.c
+++ b/vlib/vlib/node_cli.c
@@ -337,9 +337,9 @@ show_node_runtime (vlib_main_t * vm,
if (j > 0)
vlib_cli_output (vm, "---------------");
- if (w->dpdk_lcore_id > -1)
+ if (w->lcore_id > -1)
vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
- w->dpdk_lcore_id);
+ w->lcore_id);
else
vlib_cli_output (vm, "Thread %d %s", j, w->name);
}
diff --git a/vlib/vlib/threads.c b/vlib/vlib/threads.c
index e371699f1d4..70505b072ff 100644
--- a/vlib/vlib/threads.c
+++ b/vlib/vlib/threads.c
@@ -211,8 +211,9 @@ 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->dpdk_lcore_id = -1;
+ w->lcore_id = tm->main_lcore;
w->lwp = syscall (SYS_gettid);
+ w->thread_id = pthread_self ();
tm->n_vlib_mains = 1;
if (tm->sched_policy != ~0)
@@ -510,15 +511,7 @@ vlib_worker_thread_bootstrap_fn (void *arg)
vlib_worker_thread_t *w = arg;
w->lwp = syscall (SYS_gettid);
- w->dpdk_lcore_id = -1;
-#if DPDK==1
- if (w->registration && !w->registration->use_pthreads && rte_socket_id) /* do we really have dpdk linked */
- {
- unsigned lcore = rte_lcore_id ();
- lcore = lcore < RTE_MAX_LCORE ? lcore : -1;
- w->dpdk_lcore_id = lcore;
- }
-#endif
+ w->thread_id = pthread_self ();
rv = (void *) clib_calljmp
((uword (*)(uword)) w->thread_function,
@@ -532,6 +525,7 @@ vlib_launch_thread (void *fp, vlib_worker_thread_t * w, unsigned lcore_id)
{
void *(*fp_arg) (void *) = fp;
+ w->lcore_id = lcore_id;
#if DPDK==1
if (!w->registration->use_pthreads)
if (rte_eal_remote_launch) /* do we have dpdk linked */
@@ -584,15 +578,6 @@ start_workers (vlib_main_t * vm)
vlib_set_thread_name ((char *) w->name);
}
-#if DPDK==1
- w->dpdk_lcore_id = -1;
- if (rte_socket_id) /* do we really have dpdk linked */
- {
- unsigned lcore = rte_lcore_id ();
- w->dpdk_lcore_id = lcore < RTE_MAX_LCORE ? lcore : -1;;
- }
-#endif
-
/*
* Truth of the matter: we always use at least two
* threads. So, make the main heap thread-safe
diff --git a/vlib/vlib/threads.h b/vlib/vlib/threads.h
index 589d1f3a1ec..e65794cfb6b 100644
--- a/vlib/vlib/threads.h
+++ b/vlib/vlib/threads.h
@@ -105,7 +105,8 @@ typedef struct
u64 barrier_sync_count;
long lwp;
- int dpdk_lcore_id;
+ int lcore_id;
+ pthread_t thread_id;
} vlib_worker_thread_t;
vlib_worker_thread_t *vlib_worker_threads;
diff --git a/vlib/vlib/threads_cli.c b/vlib/vlib/threads_cli.c
index e788b04b795..631fe0c6244 100644
--- a/vlib/vlib/threads_cli.c
+++ b/vlib/vlib/threads_cli.c
@@ -12,12 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define _GNU_SOURCE
#include <vppinfra/format.h>
#include <vlib/vlib.h>
#include <vlib/threads.h>
-#include <linux/sched.h>
+#include <vlib/unix/unix.h>
static u8 *
format_sched_policy_and_priority (u8 * s, va_list * args)
@@ -62,15 +63,52 @@ show_threads_fn (vlib_main_t * vm,
line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp);
-#if DPDK==1
- int lcore = w->dpdk_lcore_id;
- if (lcore > -1)
+ 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
{
- line = format (line, "%-7u%-7u%-7u",
- lcore,
- lcore_config[lcore].core_id,
- lcore_config[lcore].socket_id);
+ lcore = w->lcore_id;
+ }
+ if (lcore > -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);
+ vlib_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);
+ vlib_sysfs_read ((char *) p, "%d", &socket_id);
+ vec_free (p);
+
+ line = format (line, "%-7u%-7u%-7u%", lcore, core_id, socket_id);
+#if DPDK==1
switch (lcore_config[lcore].state)
{
case WAIT:
@@ -85,8 +123,15 @@ show_threads_fn (vlib_main_t * vm,
default:
line = format (line, "unknown");
}
- }
#endif
+ }
+ else
+ {
+ line =
+ format (line, "%-7s%-7s%-7s%", (lcore == -2) ? "M" : "n/a", "n/a",
+ "n/a");
+ }
+
vlib_cli_output (vm, "%v", line);
vec_free (line);
}