@@ -340,7 +340,7 @@ static void *gen_send_thread(void *arg)
odp_queue_t outq_def;
odp_packet_t pkt;
- thr = odp_thread_id();
+ thr = odp_thread();
thr_args = arg;
pktio = odp_pktio_lookup(thr_args->pktio_dev);
@@ -504,7 +504,7 @@ static void *gen_recv_thread(void *arg)
odp_packet_t pkt;
odp_event_t ev;
- thr = odp_thread_id();
+ thr = odp_thread();
thr_args = arg;
pktio = odp_pktio_lookup(thr_args->pktio_dev);
@@ -1040,7 +1040,7 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED)
odp_event_t ev;
unsigned long pkt_cnt = 0;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Pktio thread [%02i] starts\n", thr);
@@ -117,7 +117,7 @@ static void *pktio_queue_thread(void *arg)
(void)arg;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("[%02i] QUEUE mode\n", thr);
@@ -188,7 +188,7 @@ static void *pktio_ifburst_thread(void *arg)
int src_idx, dst_idx;
odp_pktio_t pktio_src, pktio_dst;
- thr = odp_thread_id();
+ thr = odp_thread();
thr_args = arg;
src_idx = thr_args->src_idx;
@@ -154,7 +154,7 @@ static void *pktio_queue_thread(void *arg)
unsigned long pkt_cnt = 0;
unsigned long err_cnt = 0;
- thr = odp_thread_id();
+ thr = odp_thread();
thr_args = arg;
pktio = odp_pktio_lookup(thr_args->pktio_dev);
@@ -231,7 +231,7 @@ static void *pktio_ifburst_thread(void *arg)
unsigned long err_cnt = 0;
unsigned long tmp = 0;
- thr = odp_thread_id();
+ thr = odp_thread();
thr_args = arg;
pktio = odp_pktio_lookup(thr_args->pktio_dev);
@@ -190,7 +190,7 @@ static void *run_thread(void *ptr)
test_args_t *args;
args = ptr;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Thread %i starts on cpu %i\n", thr, odp_cpu());
@@ -23,11 +23,27 @@ extern "C" {
*/
/**
- * Get thread id
+ * Thread id
*
- * @return Thread id of the current thread
+ * Returns the thread id of the current thread. Thread ids range from 0 to
+ * ODP_CONFIG_MAX_THREADS-1. The ODP thread id is assinged by odp_init_local()
+ * and freed by odp_term_local(). Thread id is unique within the ODP instance.
+ *
+ * @return Thread id
+ */
+int odp_thread(void);
+
+/**
+ * Thread count
+ *
+ * Returns the current ODP thread count. This is the number of active threads
+ * running the ODP instance. Each odp_init_local() call increments and each
+ * odp_term_local() call decrements the count. The count is always between 1 and
+ * ODP_CONFIG_MAX_THREADS.
+ *
+ * @return Current thread count
*/
-int odp_thread_id(void);
+int odp_thread_count(void);
/**
* @}
@@ -227,7 +227,7 @@ static inline odp_buffer_hdr_t *get_buf(struct pool_entry_s *pool)
odp_atomic_inc_u64(&pool->bufallocs);
myhead->next = myhead; /* Mark buffer allocated */
- myhead->allocator = odp_thread_id();
+ myhead->allocator = odp_thread();
}
return (void *)myhead;
@@ -296,7 +296,7 @@ static inline void *get_local_buf(local_cache_t *buf_cache,
}
buf_cache->bufallocs++;
- buf->allocator = odp_thread_id(); /* Mark buffer allocated */
+ buf->allocator = odp_thread(); /* Mark buffer allocated */
}
return buf;
@@ -255,7 +255,7 @@ static int schedule(odp_queue_t *out_queue, odp_event_t out_ev[],
if (odp_unlikely(sched_local.pause))
return 0;
- thr = odp_thread_id();
+ thr = odp_thread();
for (i = 0; i < ODP_CONFIG_SCHED_PRIOS; i++) {
int id;
@@ -113,7 +113,7 @@ int odp_thread_term_local(void)
return num - 1; /* return a number of threads left */
}
-int odp_thread_id(void)
+int odp_thread(void)
{
return this_thread->thr_id;
}
@@ -182,7 +182,7 @@ static void *run_thread(void *arg)
pthrd_arg *parg = (pthrd_arg *)arg;
int thr;
- thr = odp_thread_id();
+ thr = odp_thread();
LOG_DBG("Thread %i starts\n", thr);
@@ -319,7 +319,7 @@ typedef enum {
static void test_ring_stress(stress_type_t type)
{
int thr;
- thr = odp_thread_id();
+ thr = odp_thread();
switch (type) {
case one_enq_one_deq:
@@ -359,7 +359,7 @@ static void *test_ring(void *arg)
odph_ring_t *r;
int result = 0;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Thread %i starts\n", thr);
@@ -22,7 +22,7 @@ static void *run_thread(void *arg)
int thr;
odp_shm_t shm;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Thread %i starts\n", thr);
@@ -604,7 +604,7 @@ static void *run_thread(void *arg)
test_globals_t *globals;
odp_barrier_t *barrier;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Thread %i starts on CPU %i\n", thr, odp_cpu());
@@ -19,7 +19,7 @@ static void *run_shm_thread(void *arg)
test_shared_data_t *test_shared_data;
int thr;
- thr = odp_thread_id();
+ thr = odp_thread();
printf("Thread %i starts\n", thr);
shm = odp_shm_lookup(TESTNAME);
@@ -118,7 +118,7 @@ static per_thread_mem_t *thread_init(void)
per_thread_mem->delay_counter = 1;
- per_thread_mem->thread_id = odp_thread_id();
+ per_thread_mem->thread_id = odp_thread();
per_thread_mem->thread_core = odp_cpu();
global_shm = odp_shm_lookup(GLOBAL_SHM_NAME);
@@ -103,7 +103,7 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
* tests */
static void *worker_entrypoint(void *arg)
{
- int thr = odp_thread_id();
+ int thr = odp_thread();
uint32_t i;
unsigned seed = thr;
(void)arg;
Renamed odp_thread_id() to odp_thread(). It can have shorter name as odp_thread_cpu() was renamed and moved out. Added documentation on thread id. Added odp_thread_count(), which returns number of active threads. Didn't add implementation yet. Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> --- example/generator/odp_generator.c | 4 ++-- example/ipsec/odp_ipsec.c | 2 +- example/l2fwd/odp_l2fwd.c | 4 ++-- example/packet/odp_pktio.c | 4 ++-- example/timer/odp_timer_test.c | 2 +- include/odp/api/thread.h | 22 +++++++++++++++++++--- .../include/odp_buffer_pool_internal.h | 4 ++-- platform/linux-generic/odp_schedule.c | 2 +- platform/linux-generic/odp_thread.c | 2 +- test/api_test/odp_atomic_test.c | 2 +- test/api_test/odp_ring_test.c | 4 ++-- test/api_test/odp_shm_test.c | 2 +- test/performance/odp_scheduling.c | 2 +- test/validation/odp_shm.c | 2 +- test/validation/odp_synchronizers.c | 2 +- test/validation/odp_timer.c | 2 +- 16 files changed, 39 insertions(+), 23 deletions(-)