From patchwork Fri Jan 22 22:24:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 60206 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp139064lbb; Fri, 22 Jan 2016 14:27:03 -0800 (PST) X-Received: by 10.107.10.217 with SMTP id 86mr5814593iok.75.1453501623319; Fri, 22 Jan 2016 14:27:03 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x92si14748629ioi.106.2016.01.22.14.27.02; Fri, 22 Jan 2016 14:27:03 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 6CEA961A06; Fri, 22 Jan 2016 22:27:02 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=R23XE7/a; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id C311C619C9; Fri, 22 Jan 2016 22:26:54 +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 83443619CB; Fri, 22 Jan 2016 22:26:24 +0000 (UTC) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com [209.85.217.173]) by lists.linaro.org (Postfix) with ESMTPS id 8F142619E8 for ; Fri, 22 Jan 2016 22:25:04 +0000 (UTC) Received: by mail-lb0-f173.google.com with SMTP id x4so49160742lbm.0 for ; Fri, 22 Jan 2016 14:25:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ys2v4ybMUvwM9K8KBa4Pk2/1Dr+/lp5OLGLsjCWdPik=; b=R23XE7/amUwqCOqlSbWV8qzficVOmx4jyJThuLUcNEbHPky0E9JZ959mSzJFd0Li+N mxvVvVdhyn8pxxaQviu70Pe71Q/b0yHs52fWPt98LOl50rr8SNiro2CIrvd6uOJc+pGb GDxq9WncmykpDHVSGYBcXcJyN9it0khB1AF9U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ys2v4ybMUvwM9K8KBa4Pk2/1Dr+/lp5OLGLsjCWdPik=; b=kkoqwsbe0SYltgERJqqBvar0lBuyMpia/PQ+0rzgbyY3E2/lUBX8On6RcFHTf5/r+i QhcokLvyGkaPFZzVg1hRq/kBjwYlCeiIbZMVhf4CLEO5IaFejaWk5jix6dsAuPFv9v7b 9uQK8kHDiHcGwvNjBVWAoECGs2LyTYh4OsPMFf6t9Fkh5ufMYbI8k4M4eTVdP2Sc6zkD QEYplxXsyWgbCIGmWsUuO5NvX3ew9auFcJC7WXmoIecIrAXKOo+pu6kAuRpQ1ioI3MCK 0yFSP3tnmte8Kf8Mgvns5MzgsVHiE2ngetXZwWJLrFqWzSvAe4FNGp49BYhjt5at/S74 3Fkg== X-Gm-Message-State: AG10YOTr6QSRtJqOLsD3Q6WmFO/chC00e03/DRRk7BpFHch3UMOIb2Hu1hxSDgKgh6jVt8S1zeQ= X-Received: by 10.112.149.230 with SMTP id ud6mr2134787lbb.12.1453501503474; Fri, 22 Jan 2016 14:25:03 -0800 (PST) Received: from khorivan.synapse.com ([212.90.63.58]) by smtp.gmail.com with ESMTPSA id z193sm1138164lfd.0.2016.01.22.14.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jan 2016 14:25:02 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Sat, 23 Jan 2016 00:24:51 +0200 Message-Id: <1453501492-9721-2-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453501492-9721-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1453501492-9721-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 1/2] linux-generic: cpumask_task: use cpumask got at init X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" It's not correct to read affinity each time to get worker cpumask. The affinity for main thread can be changed, but cpunum is still for old cpumask. So, better to remember at init cpumask for available cpus and then use it, thus, if main thread changed it`s affinity, the available CPUs are still the same. Signed-off-by: Ivan Khoronzhuk --- platform/linux-generic/include/odp_internal.h | 3 +++ platform/linux-generic/odp_cpumask_task.c | 9 +++------ platform/linux-generic/odp_system_info.c | 22 ++++++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index b22f956..b795af6 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include extern __thread int __odp_errno; @@ -30,6 +31,7 @@ typedef struct { int cache_line_size; int cpu_count; char model_str[128]; + cpu_set_t cpuset; } odp_system_info_t; struct odp_global_data_s { @@ -61,6 +63,7 @@ int _odp_term_local(enum init_stage stage); int odp_system_info_init(void); int odp_system_info_term(void); +cpu_set_t _odp_cpuset(void); int odp_thread_init_global(void); int odp_thread_init_local(odp_thread_type_t type); diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c index 41f2bc9..43a5281 100644 --- a/platform/linux-generic/odp_cpumask_task.c +++ b/platform/linux-generic/odp_cpumask_task.c @@ -10,19 +10,16 @@ #include #include +#include #include int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) { - int ret, cpu, i; + int cpu, i; cpu_set_t cpuset; - ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpu_set_t), &cpuset); - if (ret != 0) - ODP_ABORT("failed to read CPU affinity value\n"); - odp_cpumask_zero(mask); + cpuset = _odp_cpuset(); /* * If no user supplied number or it's too large, then attempt diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index a948fce..395e6b7 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -24,8 +24,6 @@ #include #include - - typedef struct { const char *cpu_arch_str; int (*cpuinfo_parser)(FILE *file, odp_system_info_t *sysinfo); @@ -41,17 +39,20 @@ typedef struct { /* * Report the number of CPUs in the affinity mask of the main thread */ -static int sysconf_cpu_count(void) +static int sysconf_cpu_count(cpu_set_t *cpuset) { - cpu_set_t cpuset; + cpu_set_t tmp; int ret; + CPU_ZERO(&tmp); ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpuset), &cpuset); + sizeof(cpuset), &tmp); if (ret != 0) return 0; - return CPU_COUNT(&cpuset); + *cpuset = tmp; + + return CPU_COUNT(cpuset); } #if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \ @@ -282,7 +283,7 @@ static int systemcpu(odp_system_info_t *sysinfo) { int ret; - ret = sysconf_cpu_count(); + ret = sysconf_cpu_count(&sysinfo->cpuset); if (ret == 0) { ODP_ERR("sysconf_cpu_count failed.\n"); return -1; @@ -320,7 +321,7 @@ static int systemcpu(odp_system_info_t *sysinfo) { int ret; - ret = sysconf_cpu_count(); + ret = sysconf_cpu_count(&sysinfo->cpuset); if (ret == 0) { ODP_ERR("sysconf_cpu_count failed.\n"); return -1; @@ -370,6 +371,11 @@ int odp_system_info_init(void) return 0; } +cpu_set_t _odp_cpuset(void) +{ + return odp_global_data.system_info.cpuset; +} + /* * System info termination */