From patchwork Thu Jul 9 13:46:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 50966 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB3F7228E5 for ; Thu, 9 Jul 2015 13:53:10 +0000 (UTC) Received: by wgbbj7 with SMTP id bj7sf79644521wgb.2 for ; Thu, 09 Jul 2015 06:53:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:cc: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=SRfnkVy1MQIdDkB4IHp5iCclnRNB7TKCqSblzmhftUc=; b=O5u2h7PBy+5icEDHq7lecELD5En2uPZysqCjUx4UHFVJPnI5SfLjiq1I3M05KtTKMB jyyKrvX4DWq0LUC1GYsy588wT0G4f+DrirI8bGULU5aYH9QT5pOMlT14n2qJTmcqgWtn dYt7LGDxbc07WbnSgwYlAa/xPCVZE0r/hvx+BF8X46q6SWMhTc8NrxZg/mvrzC0OgK6d CC2S0v8QW32I55GACAHBDQV0t5bUDFYutPJHoDORJGqKp/5iQGf34eHx0+bWFv5CahWs qqXI08nxoIOOiQ26lwbKgQgM4qEzQAXeUuGd+oLGB6AyBNY2tknH3b66EWoB37RPjrEg G4fQ== X-Gm-Message-State: ALoCoQnLo4ytNIZg4Ow8KYN3d/++xoatfFko+3byO2SqfK1pnJA3YZp/rzN7KdKleEl3Hw8vNUfP X-Received: by 10.152.27.130 with SMTP id t2mr8019637lag.2.1436449990108; Thu, 09 Jul 2015 06:53:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.225.129 with SMTP id rk1ls1108230lac.71.gmail; Thu, 09 Jul 2015 06:53:09 -0700 (PDT) X-Received: by 10.152.36.226 with SMTP id t2mr14977650laj.6.1436449989824; Thu, 09 Jul 2015 06:53:09 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id 4si4534979lar.151.2015.07.09.06.53.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 06:53:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lagx9 with SMTP id x9so246674006lag.1 for ; Thu, 09 Jul 2015 06:53:09 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr14984682lbc.86.1436449989696; Thu, 09 Jul 2015 06:53:09 -0700 (PDT) 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.108.230 with SMTP id hn6csp683680lbb; Thu, 9 Jul 2015 06:53:08 -0700 (PDT) X-Received: by 10.55.18.31 with SMTP id c31mr24178381qkh.15.1436449988507; Thu, 09 Jul 2015 06:53:08 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 10si6889418qgd.58.2015.07.09.06.53.07; Thu, 09 Jul 2015 06:53:08 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id 21C1E61FBF; Thu, 9 Jul 2015 13:53:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 362ED61FDD; Thu, 9 Jul 2015 13:48:04 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0ABD161FE0; Thu, 9 Jul 2015 13:47:46 +0000 (UTC) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by lists.linaro.org (Postfix) with ESMTPS id 8591861E19 for ; Thu, 9 Jul 2015 13:46:45 +0000 (UTC) Received: by wifm2 with SMTP id m2so19278822wif.1 for ; Thu, 09 Jul 2015 06:46:44 -0700 (PDT) X-Received: by 10.194.97.196 with SMTP id ec4mr31125711wjb.3.1436449604825; Thu, 09 Jul 2015 06:46:44 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id df1sm8414627wib.12.2015.07.09.06.46.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jul 2015 06:46:44 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 9 Jul 2015 16:46:21 +0300 Message-Id: <1436449585-23252-8-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436449585-23252-1-git-send-email-maxim.uvarov@linaro.org> References: <1436449585-23252-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Cc: Petri Savolainen Subject: [lng-odp] [PATCH 07/11] linux-generic: thread: updated thread mask handling X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@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.215.49 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 From: Petri Savolainen Linux generic thread mask handling uses thrmask API. Added worker and control masks for easy implementation of functions returning those masks. Signed-off-by: Petri Savolainen Reviewed-and-tested-by: Bill Fischofer Signed-off-by: Maxim Uvarov --- platform/linux-generic/include/odp_internal.h | 3 +- platform/linux-generic/odp_init.c | 4 +- platform/linux-generic/odp_thread.c | 71 +++++++++++++++------------ 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 8c5d339..6f0050f 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -19,6 +19,7 @@ extern "C" { #endif #include +#include extern __thread int __odp_errno; @@ -42,7 +43,7 @@ extern struct odp_global_data_s odp_global_data; int odp_system_info_init(void); int odp_thread_init_global(void); -int odp_thread_init_local(void); +int odp_thread_init_local(odp_thread_type_t type); int odp_thread_term_local(void); int odp_thread_term_global(void); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 0b13a6d..9138d37 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -121,14 +121,14 @@ int odp_term_global(void) return rc; } -int odp_init_local(odp_thread_type_t thr_type ODP_UNUSED) +int odp_init_local(odp_thread_type_t thr_type) { if (odp_shm_init_local()) { ODP_ERR("ODP shm local init failed.\n"); return -1; } - if (odp_thread_init_local()) { + if (odp_thread_init_local(thr_type)) { ODP_ERR("ODP thread local init failed.\n"); return -1; } diff --git a/platform/linux-generic/odp_thread.c b/platform/linux-generic/odp_thread.c index e815009..85ca047 100644 --- a/platform/linux-generic/odp_thread.c +++ b/platform/linux-generic/odp_thread.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -22,17 +23,18 @@ #include #include -#define MASK_SIZE_16 ((ODP_CONFIG_MAX_THREADS+15)/16) - typedef struct { int thr; int cpu; + odp_thread_type_t type; } thread_state_t; typedef struct { thread_state_t thr[ODP_CONFIG_MAX_THREADS]; - uint16_t mask[MASK_SIZE_16]; + odp_thrmask_t all; + odp_thrmask_t worker; + odp_thrmask_t control; uint32_t num; odp_spinlock_t lock; } thread_globals_t; @@ -61,6 +63,10 @@ int odp_thread_init_global(void) memset(thread_globals, 0, sizeof(thread_globals_t)); odp_spinlock_init(&thread_globals->lock); + odp_thrmask_zero(&thread_globals->all); + odp_thrmask_zero(&thread_globals->worker); + odp_thrmask_zero(&thread_globals->control); + return 0; } @@ -75,59 +81,59 @@ int odp_thread_term_global(void) return ret; } -static int alloc_id(void) +static int alloc_id(odp_thread_type_t type) { - int i, j; - uint16_t *mask = thread_globals->mask; + int thr; + odp_thrmask_t *all = &thread_globals->all; if (thread_globals->num >= ODP_CONFIG_MAX_THREADS) return -1; - for (i = 0; i < MASK_SIZE_16; i++) { - if (mask[i] != 0xffff) { - for (j = 0; j < 16; j++) { - uint16_t bit = 0x1 << j; - if ((bit & mask[i]) == 0) { - mask[i] |= bit; - thread_globals->num++; - return i*16 + j; - } - } - return -2; + for (thr = 0; thr < ODP_CONFIG_MAX_THREADS; thr++) { + if (odp_thrmask_isset(all, thr) == 0) { + odp_thrmask_set(all, thr); + + if (type == ODP_THREAD_WORKER) + odp_thrmask_set(&thread_globals->worker, thr); + else + odp_thrmask_set(&thread_globals->control, thr); + + thread_globals->num++; + return thr; } } return -2; } -static int free_id(int id) +static int free_id(int thr) { - int i, j; - uint16_t *mask = thread_globals->mask; - uint16_t bit; + odp_thrmask_t *all = &thread_globals->all; - if (id < 0 || id >= ODP_CONFIG_MAX_THREADS) + if (thr < 0 || thr >= ODP_CONFIG_MAX_THREADS) return -1; - i = id / 16; - j = id - (i * 16); - bit = 0x1 << j; - - if ((bit & mask[i]) == 0) + if (odp_thrmask_isset(all, thr) == 0) return -1; - mask[i] &= ~bit; + odp_thrmask_clr(all, thr); + + if (thread_globals->thr[thr].type == ODP_THREAD_WORKER) + odp_thrmask_clr(&thread_globals->worker, thr); + else + odp_thrmask_clr(&thread_globals->control, thr); + thread_globals->num--; return thread_globals->num; } -int odp_thread_init_local(void) +int odp_thread_init_local(odp_thread_type_t type) { int id; int cpu; odp_spinlock_lock(&thread_globals->lock); - id = alloc_id(); + id = alloc_id(type); odp_spinlock_unlock(&thread_globals->lock); if (id < 0) { @@ -142,8 +148,9 @@ int odp_thread_init_local(void) return -1; } - thread_globals->thr[id].thr = id; - thread_globals->thr[id].cpu = cpu; + thread_globals->thr[id].thr = id; + thread_globals->thr[id].cpu = cpu; + thread_globals->thr[id].type = type; this_thread = &thread_globals->thr[id]; return 0;