From patchwork Thu Dec 18 11:19:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42420 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5FBB726C6B for ; Thu, 18 Dec 2014 11:20:07 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf552133wiw.4 for ; Thu, 18 Dec 2014 03:20:06 -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=nC4hWj5mO6nrxyW3rQOBiB+IzwAtRrR7l65PGgCmmio=; b=HxQ0I/knCdFOQnmUTVRZ3Xy5lkob8U+j6WQJ0m8764xR91ZTbYOfL4Btg2hTHylQau MUo1GXfba4BIS5eadMwTUozsyppJLYTyAEphd4FoEsZddb57J/b6a/iMzxLcrqO3R+c4 urlCYcBLNBHs71th9DstfOl9ZmRbFGvBCtN7etFU1MlyCevTKDWPokNwRCFvmOqwtkcd VQ/nlMY9CuW/GyRnvECeMNw7uPjQxZrJG8igb6EErMo0G4t2nVLLsba7m0SBVNOXxNNi oh0GTPAf58ynawYC06mSQV7zFxYkycE4XxP8J5oqq2MCU6L7si9BoJjl6OuORwtYjTGw klYQ== X-Gm-Message-State: ALoCoQnFtIIqOc3D4tYwc/iytY6sJ+yXiG9BukuVSFcg74PDPVxgceJyHAXn2nCKCCfYjbV6xIn0 X-Received: by 10.180.24.35 with SMTP id r3mr329491wif.0.1418901606654; Thu, 18 Dec 2014 03:20:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.99 with SMTP id s3ls890923lag.79.gmail; Thu, 18 Dec 2014 03:20:06 -0800 (PST) X-Received: by 10.152.29.129 with SMTP id k1mr1749899lah.10.1418901606332; Thu, 18 Dec 2014 03:20:06 -0800 (PST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id k1si6521728lah.94.2014.12.18.03.20.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Dec 2014 03:20:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id b6so763903lbj.36 for ; Thu, 18 Dec 2014 03:20:06 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr1692889laa.80.1418901606237; Thu, 18 Dec 2014 03:20:06 -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 ru5csp1670262lbb; Thu, 18 Dec 2014 03:20:05 -0800 (PST) X-Received: by 10.224.129.132 with SMTP id o4mr2422212qas.66.1418901604832; Thu, 18 Dec 2014 03:20:04 -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 r2si7854408qcq.9.2014.12.18.03.20.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Dec 2014 03:20:04 -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 1Y1Z7i-0005jm-Qy; Thu, 18 Dec 2014 11:20:02 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y1Z7X-0005gh-GA for lng-odp@lists.linaro.org; Thu, 18 Dec 2014 11:19:51 +0000 Received: by mail-la0-f48.google.com with SMTP id gf13so785169lab.21 for ; Thu, 18 Dec 2014 03:19:45 -0800 (PST) X-Received: by 10.112.169.34 with SMTP id ab2mr1610993lbc.77.1418901585735; Thu, 18 Dec 2014 03:19:45 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id ki4sm1692440lac.1.2014.12.18.03.19.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Dec 2014 03:19:45 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org, petri.savolainen@nsn.com Date: Thu, 18 Dec 2014 13:19:39 +0200 Message-Id: <1418901579-29209-2-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418901579-29209-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418901579-29209-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/2] linux-generic: init: implement basic odp_term_local() 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.177 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/odp_internal.h | 1 + platform/linux-generic/odp_init.c | 3 +-- platform/linux-generic/odp_linux.c | 10 ++++++++-- platform/linux-generic/odp_thread.c | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) 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..7210430 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -90,6 +90,5 @@ int odp_init_local(void) int odp_term_local(void) { - ODP_UNIMPLEMENTED(); - return 0; + return (odp_thread_term_local() > 0) ? 1 : 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) {