aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/unix
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-04-05 19:18:20 +0200
committerDave Barach <openvpp@barachs.net>2017-04-06 11:31:39 +0000
commit586afd762bfa149f5ca167bd5fd5a0cd59ce94fe (patch)
tree808b57c61e0fe1a181871bb1ad94398c5ba42671 /src/vlib/unix
parentbc799c92d761a2d45105aa6a1685b3663687d2a4 (diff)
Use thread local storage for thread index
This patch deprecates stack-based thread identification, Also removes requirement that thread stacks are adjacent. Finally, possibly annoying for some folks, it renames all occurences of cpu_index and cpu_number with thread index. Using word "cpu" is misleading here as thread can be migrated ti different CPU, and also it is not related to linux cpu index. Change-Id: I68cdaf661e701d2336fc953dcb9978d10a70f7c1 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/unix')
-rw-r--r--src/vlib/unix/cj.c7
-rw-r--r--src/vlib/unix/cj.h2
-rw-r--r--src/vlib/unix/main.c43
3 files changed, 24 insertions, 28 deletions
diff --git a/src/vlib/unix/cj.c b/src/vlib/unix/cj.c
index 33ba163a..7c1e9475 100644
--- a/src/vlib/unix/cj.c
+++ b/src/vlib/unix/cj.c
@@ -48,7 +48,7 @@ cj_log (u32 type, void *data0, void *data1)
r = (cj_record_t *) & (cjm->records[new_tail & (cjm->num_records - 1)]);
r->time = vlib_time_now (cjm->vlib_main);
- r->cpu = os_get_cpu_number ();
+ r->thread_index = vlib_get_thread_index ();
r->type = type;
r->data[0] = pointer_to_uword (data0);
r->data[1] = pointer_to_uword (data1);
@@ -133,7 +133,8 @@ static inline void
cj_dump_one_record (cj_record_t * r)
{
fprintf (stderr, "[%d]: %10.6f T%02d %llx %llx\n",
- r->cpu, r->time, r->type, (long long unsigned int) r->data[0],
+ r->thread_index, r->time, r->type,
+ (long long unsigned int) r->data[0],
(long long unsigned int) r->data[1]);
}
@@ -161,7 +162,7 @@ cj_dump_internal (u8 filter0_enable, u64 filter0,
index = (cjm->tail + 1) & (cjm->num_records - 1);
r = &(cjm->records[index]);
- if (r->cpu != (u32) ~ 0)
+ if (r->thread_index != (u32) ~ 0)
{
/* Yes, dump from tail + 1 to the end */
for (i = index; i < cjm->num_records; i++)
diff --git a/src/vlib/unix/cj.h b/src/vlib/unix/cj.h
index 67626afe..d0a1d46e 100644
--- a/src/vlib/unix/cj.h
+++ b/src/vlib/unix/cj.h
@@ -23,7 +23,7 @@
typedef struct
{
f64 time;
- u32 cpu;
+ u32 thread_index;
u32 type;
u64 data[2];
} cj_record_t;
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index 6b96cc0d..db5ddd64 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -510,13 +510,28 @@ thread0 (uword arg)
return i;
}
+u8 *
+vlib_thread_stack_init (uword thread_index)
+{
+ vec_validate (vlib_thread_stacks, thread_index);
+ vlib_thread_stacks[thread_index] = clib_mem_alloc_aligned
+ (VLIB_THREAD_STACK_SIZE, VLIB_THREAD_STACK_SIZE);
+
+ /*
+ * Disallow writes to the bottom page of the stack, to
+ * catch stack overflows.
+ */
+ if (mprotect (vlib_thread_stacks[thread_index],
+ clib_mem_get_page_size (), PROT_READ) < 0)
+ clib_unix_warning ("thread stack");
+ return vlib_thread_stacks[thread_index];
+}
+
int
vlib_unix_main (int argc, char *argv[])
{
vlib_main_t *vm = &vlib_global_main; /* one and only time for this! */
- vlib_thread_main_t *tm = &vlib_thread_main;
unformat_input_t input;
- u8 *thread_stacks;
clib_error_t *e;
int i;
@@ -548,29 +563,9 @@ vlib_unix_main (int argc, char *argv[])
}
unformat_free (&input);
- /*
- * allocate n x VLIB_THREAD_STACK_SIZE stacks, aligned to a
- * VLIB_THREAD_STACK_SIZE boundary
- * See also: os_get_cpu_number() in vlib/vlib/threads.c
- */
- thread_stacks = clib_mem_alloc_aligned
- ((uword) tm->n_thread_stacks * VLIB_THREAD_STACK_SIZE,
- VLIB_THREAD_STACK_SIZE);
-
- vec_validate (vlib_thread_stacks, tm->n_thread_stacks - 1);
- for (i = 0; i < vec_len (vlib_thread_stacks); i++)
- {
- vlib_thread_stacks[i] = thread_stacks;
-
- /*
- * Disallow writes to the bottom page of the stack, to
- * catch stack overflows.
- */
- if (mprotect (thread_stacks, clib_mem_get_page_size (), PROT_READ) < 0)
- clib_unix_warning ("thread stack");
+ vlib_thread_stack_init (0);
- thread_stacks += VLIB_THREAD_STACK_SIZE;
- }
+ vlib_thread_index = 0;
i = clib_calljmp (thread0, (uword) vm,
(void *) (vlib_thread_stacks[0] +