From patchwork Fri Jan 30 11:39:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 44039 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C0CC52410D for ; Fri, 30 Jan 2015 11:40:17 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id f15sf387023lbj.2 for ; Fri, 30 Jan 2015 03:40:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=4bdL+NmSC3RxSPMG02raNaZIqq6dgMucN0pbomwX86c=; b=mTAvrykxTTgA6I9WbdY7+bcm2PnyN6KaWDDSczgNp8XbJL92q0ha+tGTn6wrprj1HU ZdHGgk3AmLtUK1RA+iuStKw32o3MRZEXNF5yqI33rEYlcJInr+a0QkSVGq+dh0b7kwAg PpAlNfjTmOq93pvRsR0OWuKH1/R8dyMd2bBrMS1TvVjjzz5hJxGgk9pN/PhQOB99c9Jq /MFxxk0nzuxHR0we8DqRR1SPm2DQA9z1g+nTJiVlsHFy0qjiF5kF+u8vMPcISb5/urC4 PLyk122UWvBeci9byjnCLrUNf5Qb2l7qsZn+/Aph+8WzMRfCaLtJY0J1QA2dmvpr15+S 7mdA== X-Gm-Message-State: ALoCoQmLTAw5cRXHn3wLolWfq6aP8NwShdCo4+GiMp9lbH4qFifcATaw05/t+1Bk+XA0Xhqv120Y X-Received: by 10.112.51.100 with SMTP id j4mr751342lbo.24.1422618013226; Fri, 30 Jan 2015 03:40:13 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.135 with SMTP id s7ls426234las.39.gmail; Fri, 30 Jan 2015 03:40:13 -0800 (PST) X-Received: by 10.112.126.98 with SMTP id mx2mr6021357lbb.84.1422618013081; Fri, 30 Jan 2015 03:40:13 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id a8si9915997laf.73.2015.01.30.03.40.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 03:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z12so35826416lbi.7 for ; Fri, 30 Jan 2015 03:40:13 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr6027717laa.80.1422618012945; Fri, 30 Jan 2015 03:40:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp253375lbj; Fri, 30 Jan 2015 03:40:12 -0800 (PST) X-Received: by 10.224.120.130 with SMTP id d2mr11267765qar.81.1422618010722; Fri, 30 Jan 2015 03:40:10 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id g3si13440889qas.62.2015.01.30.03.40.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 03:40:10 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YH9vj-0002Rq-Uq; Fri, 30 Jan 2015 11:40:07 +0000 Received: from mail-qc0-f174.google.com ([209.85.216.174]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YH9vZ-0002Q8-64 for lng-odp@lists.linaro.org; Fri, 30 Jan 2015 11:39:57 +0000 Received: by mail-qc0-f174.google.com with SMTP id s11so19995742qcv.5 for ; Fri, 30 Jan 2015 03:39:52 -0800 (PST) X-Received: by 10.140.92.33 with SMTP id a30mr10806585qge.30.1422617992029; Fri, 30 Jan 2015 03:39:52 -0800 (PST) Received: from mcpro03.emea.nsn-net.net (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id y17sm9778758qaq.14.2015.01.30.03.39.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 03:39:51 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Fri, 30 Jan 2015 13:39:26 +0200 Message-Id: <1422617966-27160-4-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422617966-27160-1-git-send-email-petri.savolainen@linaro.org> References: <1422617966-27160-1-git-send-email-petri.savolainen@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 4/4] api: thread: Rename thread_id and add thread_count X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 --- 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 --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;