From patchwork Wed Dec 17 14:49:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42381 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BEF8D26C8B for ; Wed, 17 Dec 2014 14:49:46 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id y19sf10100906wgg.11 for ; Wed, 17 Dec 2014 06:49:46 -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: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=QU0BgHZYx+4VKQgk7AQqxVxUscPMLOWfd5TM5uzul7k=; b=FHDlIiyce6BZ0rNoN0TTcacXmROV4NFzHMNUccghyihn+QVJI0qlRb4pLC0FQcgD2Y q4J4SCEoKJ6n++8vDOGPWSxCA0DVyfRYIAjLpE2xGlszaEBaTZ6XjtDbzyBPpWXz8Hg9 eobnf0C6GJwDS3CtDORH4SBkbDZmgtIsnfzBAZnYGQRFXNy1onQ6YPC1k5tUvtBMGQp+ wx1m23WrVL/TKS8vRHkQsHJC1b4VcyNGEECS3NJua4x0F7Uvtn6pfHn2d757ZFmhyJWz NnI4K0xFbysiEn+KiFYWEfw3VRqLWygA6SfF1EuGAWo9lVqMgajyzU4MYXiXxNkvttBl ntyw== X-Gm-Message-State: ALoCoQnkfoiDJxoUrPc0XeWqkOIZOKKN78UVFI9fKcrH2poa2zKVXn8DBiyrKPyBSjvbjAIXtLV1 X-Received: by 10.152.42.196 with SMTP id q4mr392315lal.6.1418827785898; Wed, 17 Dec 2014 06:49:45 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.135 with SMTP id s7ls1113648las.33.gmail; Wed, 17 Dec 2014 06:49:45 -0800 (PST) X-Received: by 10.152.25.194 with SMTP id e2mr2859430lag.22.1418827785642; Wed, 17 Dec 2014 06:49:45 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id v2si4014744laj.133.2014.12.17.06.49.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Dec 2014 06:49:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so13709439lbj.41 for ; Wed, 17 Dec 2014 06:49:45 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr41933446lac.70.1418827785537; Wed, 17 Dec 2014 06:49:45 -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.142.69 with SMTP id ru5csp1387038lbb; Wed, 17 Dec 2014 06:49:44 -0800 (PST) X-Received: by 10.224.46.134 with SMTP id j6mr53853295qaf.74.1418827784113; Wed, 17 Dec 2014 06:49:44 -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 l6si4809452qao.37.2014.12.17.06.49.42 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 17 Dec 2014 06:49:44 -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 1Y1Fv1-0006oL-VT; Wed, 17 Dec 2014 14:49:39 +0000 Received: from mail-lb0-f169.google.com ([209.85.217.169]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y1Fuu-0006mw-Lc for lng-odp@lists.linaro.org; Wed, 17 Dec 2014 14:49:32 +0000 Received: by mail-lb0-f169.google.com with SMTP id p9so12916678lbv.0 for ; Wed, 17 Dec 2014 06:49:27 -0800 (PST) X-Received: by 10.112.199.138 with SMTP id jk10mr41380395lbc.86.1418827766968; Wed, 17 Dec 2014 06:49:26 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id wv5sm997822lbb.20.2014.12.17.06.49.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Dec 2014 06:49:24 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org, petri.savolainen@nsn.com Date: Wed, 17 Dec 2014 16:49:19 +0200 Message-Id: <1418827759-1179-1-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [RFC PATCH] api: init: add a way to determine a last ODP thread termination 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: taras.kondratiuk@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.182 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 Signed-off-by: Taras Kondratiuk --- platform/linux-generic/include/api/odp_init.h | 5 ++--- platform/linux-generic/include/odp_internal.h | 1 + platform/linux-generic/odp_init.c | 4 +++- platform/linux-generic/odp_linux.c | 10 ++++++++-- platform/linux-generic/odp_thread.c | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/platform/linux-generic/include/api/odp_init.h b/platform/linux-generic/include/api/odp_init.h index 49f5e41..8ded080 100644 --- a/platform/linux-generic/include/api/odp_init.h +++ b/platform/linux-generic/include/api/odp_init.h @@ -124,10 +124,9 @@ int odp_init_local(void); * * @warning The unwinding of HW resources to allow them to be re used without reseting * the device is a complex task that the application is expected to coordinate. - * All threads must call this function before calling - * any other ODP API functions. * - * @retval 0 if successful + * @retval 1 if successful and more ODP thread exists + * @retval 0 if successful and it was the last ODP thread * @retval -1 on failure */ int odp_term_local(void); diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index ee2ab1a..549d406 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -23,6 +23,7 @@ int odp_system_info_init(void); int odp_thread_init_global(void); int odp_thread_init_local(void); +int odp_thread_term_local(void); int odp_shm_init_global(void); int odp_shm_init_local(void); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index c661231..6c2fc8c 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -90,6 +90,8 @@ int odp_init_local(void) int odp_term_local(void) { - ODP_UNIMPLEMENTED(); + if (odp_thread_term_local() == 0) + return 1; + return 0; } diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index 95761a9..229d24e 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -43,9 +43,15 @@ static void *odp_run_start_routine(void *arg) return NULL; } - void *ret = start_args->start_routine(start_args->arg); + void *ret_ptr = start_args->start_routine(start_args->arg); _odp_flush_caches(); - return ret; + int ret = odp_term_local(); + if (ret < 0) + ODP_ERR("Local term failed\n"); + else if (ret == 0 && odp_term_global()) + ODP_ERR("Global term failed\n"); + + return ret_ptr; } diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c index faa12a2..01c8147 100644 --- a/platform/linux-generic/odp_thread.c +++ b/platform/linux-generic/odp_thread.c @@ -32,6 +32,7 @@ typedef struct { typedef struct { thread_state_t thr[ODP_CONFIG_MAX_THREADS]; odp_atomic_u32_t num; + odp_atomic_u32_t next_id; } thread_globals_t; @@ -58,6 +59,8 @@ int odp_thread_init_global(void) return -1; memset(thread_globals, 0, sizeof(thread_globals_t)); + odp_atomic_init_u32(&thread_globals->next_id, 0); + odp_atomic_init_u32(&thread_globals->num, 0); return 0; } @@ -67,12 +70,13 @@ static int thread_id(void) uint32_t id; int cpu; - id = odp_atomic_fetch_inc_u32(&thread_globals->num); + id = odp_atomic_fetch_inc_u32(&thread_globals->next_id); if (id >= ODP_CONFIG_MAX_THREADS) { ODP_ERR("Too many threads\n"); return -1; } + odp_atomic_inc_u32(&thread_globals->num); cpu = sched_getcpu(); @@ -87,7 +91,6 @@ static int thread_id(void) return id; } - int odp_thread_init_local(void) { int id; @@ -101,6 +104,13 @@ int odp_thread_init_local(void) return 0; } +int odp_thread_term_local(void) +{ + uint32_t num; + num = odp_atomic_fetch_dec_u32(&thread_globals->num); + ODP_ASSERT(num > 0, "Number of threads should be > 0"); + return num - 1; /* return a number of threads left */ +} int odp_thread_id(void) {