summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/bihash_template.c16
-rw-r--r--src/vppinfra/lock.h6
-rw-r--r--src/vppinfra/mem.h6
-rw-r--r--src/vppinfra/mhash.c2
-rw-r--r--src/vppinfra/mhash.h2
-rw-r--r--src/vppinfra/mheap.c4
-rw-r--r--src/vppinfra/os.h20
-rw-r--r--src/vppinfra/smp.c2
-rw-r--r--src/vppinfra/unix-misc.c19
9 files changed, 44 insertions, 33 deletions
diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c
index d8b97b5f3d0..51fadeb8adf 100644
--- a/src/vppinfra/bihash_template.c
+++ b/src/vppinfra/bihash_template.c
@@ -96,12 +96,12 @@ BV (make_working_copy) (BVT (clib_bihash) * h, clib_bihash_bucket_t * b)
clib_bihash_bucket_t working_bucket __attribute__ ((aligned (8)));
void *oldheap;
BVT (clib_bihash_value) * working_copy;
- u32 cpu_number = os_get_cpu_number ();
+ u32 thread_index = os_get_thread_index ();
- if (cpu_number >= vec_len (h->working_copies))
+ if (thread_index >= vec_len (h->working_copies))
{
oldheap = clib_mem_set_heap (h->mheap);
- vec_validate (h->working_copies, cpu_number);
+ vec_validate (h->working_copies, thread_index);
clib_mem_set_heap (oldheap);
}
@@ -110,7 +110,7 @@ BV (make_working_copy) (BVT (clib_bihash) * h, clib_bihash_bucket_t * b)
* updates from multiple threads will not result in sporadic, spurious
* lookup failures.
*/
- working_copy = h->working_copies[cpu_number];
+ working_copy = h->working_copies[thread_index];
h->saved_bucket.as_u64 = b->as_u64;
oldheap = clib_mem_set_heap (h->mheap);
@@ -119,7 +119,7 @@ BV (make_working_copy) (BVT (clib_bihash) * h, clib_bihash_bucket_t * b)
{
vec_validate_aligned (working_copy, (1 << b->log2_pages) - 1,
sizeof (u64));
- h->working_copies[cpu_number] = working_copy;
+ h->working_copies[thread_index] = working_copy;
}
_vec_len (working_copy) = 1 << b->log2_pages;
@@ -132,7 +132,7 @@ BV (make_working_copy) (BVT (clib_bihash) * h, clib_bihash_bucket_t * b)
working_bucket.offset = BV (clib_bihash_get_offset) (h, working_copy);
CLIB_MEMORY_BARRIER ();
b->as_u64 = working_bucket.as_u64;
- h->working_copies[cpu_number] = working_copy;
+ h->working_copies[thread_index] = working_copy;
}
static
@@ -233,7 +233,7 @@ int BV (clib_bihash_add_del)
int i, limit;
u64 hash, new_hash;
u32 new_log2_pages;
- u32 cpu_number = os_get_cpu_number ();
+ u32 thread_index = os_get_thread_index ();
int mark_bucket_linear;
int resplit_once;
@@ -323,7 +323,7 @@ int BV (clib_bihash_add_del)
new_log2_pages = h->saved_bucket.log2_pages + 1;
mark_bucket_linear = 0;
- working_copy = h->working_copies[cpu_number];
+ working_copy = h->working_copies[thread_index];
resplit_once = 0;
new_v = BV (split_and_rehash) (h, working_copy, new_log2_pages);
diff --git a/src/vppinfra/lock.h b/src/vppinfra/lock.h
index c60ff414612..0cd2b4fea53 100644
--- a/src/vppinfra/lock.h
+++ b/src/vppinfra/lock.h
@@ -24,7 +24,7 @@ typedef struct
u32 lock;
#if CLIB_DEBUG > 0
pid_t pid;
- uword cpu_index;
+ uword thread_index;
void *frame_address;
#endif
} *clib_spinlock_t;
@@ -57,7 +57,7 @@ clib_spinlock_lock (clib_spinlock_t * p)
#if CLIB_DEBUG > 0
(*p)->frame_address = __builtin_frame_address (0);
(*p)->pid = getpid ();
- (*p)->cpu_index = os_get_cpu_number ();
+ (*p)->thread_index = os_get_thread_index ();
#endif
}
@@ -75,7 +75,7 @@ clib_spinlock_unlock (clib_spinlock_t * p)
#if CLIB_DEBUG > 0
(*p)->frame_address = 0;
(*p)->pid = 0;
- (*p)->cpu_index = 0;
+ (*p)->thread_index = 0;
#endif
}
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index 1260eab28c0..63c5ac16a02 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -54,14 +54,14 @@ extern void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS];
always_inline void *
clib_mem_get_per_cpu_heap (void)
{
- int cpu = os_get_cpu_number ();
+ int cpu = os_get_thread_index ();
return clib_per_cpu_mheaps[cpu];
}
always_inline void *
clib_mem_set_per_cpu_heap (u8 * new_heap)
{
- int cpu = os_get_cpu_number ();
+ int cpu = os_get_thread_index ();
void *old = clib_per_cpu_mheaps[cpu];
clib_per_cpu_mheaps[cpu] = new_heap;
return old;
@@ -83,7 +83,7 @@ clib_mem_alloc_aligned_at_offset (uword size, uword align, uword align_offset,
align_offset = align;
}
- cpu = os_get_cpu_number ();
+ cpu = os_get_thread_index ();
heap = clib_per_cpu_mheaps[cpu];
heap = mheap_get_aligned (heap, size, align, align_offset, &offset);
clib_per_cpu_mheaps[cpu] = heap;
diff --git a/src/vppinfra/mhash.c b/src/vppinfra/mhash.c
index c917e164cd9..00b67c4959f 100644
--- a/src/vppinfra/mhash.c
+++ b/src/vppinfra/mhash.c
@@ -226,7 +226,7 @@ static uword
mhash_set_tmp_key (mhash_t * h, const void *key)
{
u8 *key_tmp;
- int my_cpu = os_get_cpu_number ();
+ int my_cpu = os_get_thread_index ();
vec_validate (h->key_tmps, my_cpu);
key_tmp = h->key_tmps[my_cpu];
diff --git a/src/vppinfra/mhash.h b/src/vppinfra/mhash.h
index 102adf4eb83..7eb1918384e 100644
--- a/src/vppinfra/mhash.h
+++ b/src/vppinfra/mhash.h
@@ -93,7 +93,7 @@ mhash_key_to_mem (mhash_t * h, uword key)
{
u8 *key_tmp;
- int my_cpu = os_get_cpu_number ();
+ int my_cpu = os_get_thread_index ();
vec_validate (h->key_tmps, my_cpu);
key_tmp = h->key_tmps[my_cpu];
return key_tmp;
diff --git a/src/vppinfra/mheap.c b/src/vppinfra/mheap.c
index 192732db5f9..d4010ceb297 100644
--- a/src/vppinfra/mheap.c
+++ b/src/vppinfra/mheap.c
@@ -56,7 +56,7 @@ mheap_maybe_lock (void *v)
mheap_t *h = mheap_header (v);
if (v && (h->flags & MHEAP_FLAG_THREAD_SAFE))
{
- u32 my_cpu = os_get_cpu_number ();
+ u32 my_cpu = os_get_thread_index ();
if (h->owner_cpu == my_cpu)
{
h->recursion_count++;
@@ -77,7 +77,7 @@ mheap_maybe_unlock (void *v)
mheap_t *h = mheap_header (v);
if (v && h->flags & MHEAP_FLAG_THREAD_SAFE)
{
- ASSERT (os_get_cpu_number () == h->owner_cpu);
+ ASSERT (os_get_thread_index () == h->owner_cpu);
if (--h->recursion_count == 0)
{
h->owner_cpu = ~0;
diff --git a/src/vppinfra/os.h b/src/vppinfra/os.h
index a5c74f8ce72..33300716103 100644
--- a/src/vppinfra/os.h
+++ b/src/vppinfra/os.h
@@ -56,8 +56,24 @@ void os_out_of_memory (void);
/* Estimate, measure or divine CPU timestamp clock frequency. */
f64 os_cpu_clock_frequency (void);
-uword os_get_cpu_number (void);
-uword os_get_ncpus (void);
+extern __thread uword __os_thread_index;
+
+static_always_inline uword
+os_get_thread_index (void)
+{
+ return __os_thread_index;
+}
+
+static_always_inline uword
+os_get_cpu_number (void) __attribute__ ((deprecated));
+
+static_always_inline uword
+os_get_cpu_number (void)
+{
+ return __os_thread_index;
+}
+
+uword os_get_nthreads (void);
#include <vppinfra/smp.h>
diff --git a/src/vppinfra/smp.c b/src/vppinfra/smp.c
index 8ac19960982..f603283ef61 100644
--- a/src/vppinfra/smp.c
+++ b/src/vppinfra/smp.c
@@ -53,7 +53,7 @@ allocate_per_cpu_mheap (uword cpu)
void *heap;
uword vm_size, stack_size, mheap_flags;
- ASSERT (os_get_cpu_number () == cpu);
+ ASSERT (os_get_thread_index () == cpu);
vm_size = (uword) 1 << m->log2_n_per_cpu_vm_bytes;
stack_size = (uword) 1 << m->log2_n_per_cpu_stack_bytes;
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c
index 2928369d52e..361015b4f67 100644
--- a/src/vppinfra/unix-misc.c
+++ b/src/vppinfra/unix-misc.c
@@ -45,6 +45,8 @@
#include <fcntl.h>
#include <stdio.h> /* for sprintf */
+__thread uword __os_thread_index = 0;
+
clib_error_t *
unix_file_n_bytes (char *file, uword * result)
{
@@ -188,14 +190,14 @@ void os_puts (u8 * string, uword string_length, uword is_error)
void
os_puts (u8 * string, uword string_length, uword is_error)
{
- int cpu = os_get_cpu_number ();
- int ncpus = os_get_ncpus ();
+ int cpu = os_get_thread_index ();
+ int nthreads = os_get_nthreads ();
char buf[64];
int fd = is_error ? 2 : 1;
struct iovec iovs[2];
int n_iovs = 0;
- if (ncpus > 1)
+ if (nthreads > 1)
{
snprintf (buf, sizeof (buf), "%d: ", cpu);
@@ -219,16 +221,9 @@ os_out_of_memory (void)
os_panic ();
}
-uword os_get_cpu_number (void) __attribute__ ((weak));
-uword
-os_get_cpu_number (void)
-{
- return 0;
-}
-
-uword os_get_ncpus (void) __attribute__ ((weak));
+uword os_get_nthreads (void) __attribute__ ((weak));
uword
-os_get_ncpus (void)
+os_get_nthreads (void)
{
return 1;
}