diff mbox

[4/4] api: thread: Rename thread_id and add thread_count

Message ID 1422617966-27160-4-git-send-email-petri.savolainen@linaro.org
State New
Headers show

Commit Message

Petri Savolainen Jan. 30, 2015, 11:39 a.m. UTC
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(-)
diff mbox

Patch

diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index b7310ae..2309171 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -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);
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index e1960fb..e69fbfd 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -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);
 
diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c
index 83d1bd4..803ecd5 100644
--- a/example/l2fwd/odp_l2fwd.c
+++ b/example/l2fwd/odp_l2fwd.c
@@ -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;
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index c7cb245..daf10c8 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -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);
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 25fca93..b7e8269 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -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());
 
diff --git a/include/odp/api/thread.h b/include/odp/api/thread.h
index 97d5de7..971177b 100644
--- a/include/odp/api/thread.h
+++ b/include/odp/api/thread.h
@@ -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);
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h
index e02e35a..7ed8b3a 100644
--- a/platform/linux-generic/include/odp_buffer_pool_internal.h
+++ b/platform/linux-generic/include/odp_buffer_pool_internal.h
@@ -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;
diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
index 999c800..7174b04 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -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;
diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c
index 9169191..95914c4 100644
--- a/platform/linux-generic/odp_thread.c
+++ b/platform/linux-generic/odp_thread.c
@@ -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;
 }
diff --git a/test/api_test/odp_atomic_test.c b/test/api_test/odp_atomic_test.c
index 6ccdc35..5b0ae9c 100644
--- a/test/api_test/odp_atomic_test.c
+++ b/test/api_test/odp_atomic_test.c
@@ -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);
 
diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
index e8a962a..509a223 100644
--- a/test/api_test/odp_ring_test.c
+++ b/test/api_test/odp_ring_test.c
@@ -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);
 
diff --git a/test/api_test/odp_shm_test.c b/test/api_test/odp_shm_test.c
index 13d037d..530608e 100644
--- a/test/api_test/odp_shm_test.c
+++ b/test/api_test/odp_shm_test.c
@@ -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);
 
diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c
index c8cf6b9..27173e0 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -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());
 
diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c
index 39dd8f0..c9a15ce 100644
--- a/test/validation/odp_shm.c
+++ b/test/validation/odp_shm.c
@@ -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);
diff --git a/test/validation/odp_synchronizers.c b/test/validation/odp_synchronizers.c
index 74ee485..767b4bc 100644
--- a/test/validation/odp_synchronizers.c
+++ b/test/validation/odp_synchronizers.c
@@ -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);
diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c
index 5189301..39eef98 100644
--- a/test/validation/odp_timer.c
+++ b/test/validation/odp_timer.c
@@ -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;