From patchwork Tue Aug 11 12:47:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 52312 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 63F8322FEC for ; Tue, 11 Aug 2015 12:48:16 +0000 (UTC) Received: by wicja10 with SMTP id ja10sf24216241wic.2 for ; Tue, 11 Aug 2015 05:48:15 -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: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=9esfKavLTTzfWBq2Gxt8byial7stqLHTYFmyFKnyYSc=; b=Z1mqYX89h8rZmv7xViqfBWxReumDO/I7cfmNvZpRN97DMD3TmHBuU+0k+X0m/91O9D GZzYNVhWAINt85yVMXqEgNpzvP+bmeO1o6FGpK4aDd/n7PqWwbuxIuBIOighzwJjRETa cVvAeGsp6Yk1n6MG3KGvBC6GNRUDW65Hm1/08AGUIvjPJH0u2eTvYVxQuhlT9W2TdOZh VB0LjF3PIgNPkFUF2l2MiPrM381T5p8Q3Wt7OyznntyHMl8Ylo1m39cB1KLkSiJ5KxEA 9jE+f8NANpfX4MaPzpdKu9kVLZHM/NZ4vCVGpPTln/cF71UT22Xmh/+byLHBQzPpSYM0 aIHg== X-Gm-Message-State: ALoCoQm5YCZPy5y40hNX3B2c58EBqx0mHuyMNpoOf1Hat6mNOaWPQ2OL+B10t3HGy0yYn5PfwjTv X-Received: by 10.112.13.200 with SMTP id j8mr8046371lbc.14.1439297295692; Tue, 11 Aug 2015 05:48:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.35 with SMTP id s3ls870076lae.29.gmail; Tue, 11 Aug 2015 05:48:15 -0700 (PDT) X-Received: by 10.112.125.200 with SMTP id ms8mr25867148lbb.60.1439297295414; Tue, 11 Aug 2015 05:48:15 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id yo1si1278109lbb.167.2015.08.11.05.48.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 05:48:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbsx3 with SMTP id sx3so28881968lbb.0 for ; Tue, 11 Aug 2015 05:48:15 -0700 (PDT) X-Received: by 10.152.28.193 with SMTP id d1mr12449446lah.72.1439297295304; Tue, 11 Aug 2015 05:48:15 -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.7.198 with SMTP id l6csp2508149lba; Tue, 11 Aug 2015 05:48:14 -0700 (PDT) X-Received: by 10.140.97.72 with SMTP id l66mr47687874qge.11.1439297292615; Tue, 11 Aug 2015 05:48:12 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o82si3128161qko.76.2015.08.11.05.48.11; Tue, 11 Aug 2015 05:48:12 -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 93EE761D7F; Tue, 11 Aug 2015 12:48:11 +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 41C7761D75; Tue, 11 Aug 2015 12:48:07 +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 3D0A961D76; Tue, 11 Aug 2015 12:48:04 +0000 (UTC) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by lists.linaro.org (Postfix) with ESMTPS id 17A9E61D71 for ; Tue, 11 Aug 2015 12:48:03 +0000 (UTC) Received: by wicne3 with SMTP id ne3so59249727wic.0 for ; Tue, 11 Aug 2015 05:48:02 -0700 (PDT) X-Received: by 10.194.189.145 with SMTP id gi17mr54278486wjc.102.1439297282277; Tue, 11 Aug 2015 05:48:02 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id yz10sm2893772wjc.0.2015.08.11.05.48.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Aug 2015 05:48:01 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 11 Aug 2015 15:47:54 +0300 Message-Id: <1439297274-4110-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv2] linux-generic: move default cpumask functions to separate file 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.217.170 as permitted sender) smtp.mailfrom=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 Keep functions which iterates with bit mask and more likely will not be accelerated by hw in odp_cpumask.c. And put functions for default cpu mask to odp_cpumask_task.c, which is more platform specific. That patch should simplify portability to other platforms when odp_cpumask.c will be inherit from linux generic. Signed-off-by: Maxim Uvarov Reviewed-by: Mike Holmes --- v2: - copyright 2015 - odp_cpumask_def.c -> odp_cpumask_task.c platform/linux-generic/Makefile.am | 1 + platform/linux-generic/odp_cpumask.c | 38 ---------------------- platform/linux-generic/odp_cpumask_task.c | 52 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 platform/linux-generic/odp_cpumask_task.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index ed4add5..fb145e7 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -134,6 +134,7 @@ __LIB__libodp_la_SOURCES = \ odp_buffer.c \ odp_classification.c \ odp_cpumask.c \ + odp_cpumask_task.c \ odp_crypto.c \ odp_errno.c \ odp_event.c \ diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index c28153b..b31e1ca 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -205,41 +205,3 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu) return cpu; return -1; } - -int odp_cpumask_def_worker(odp_cpumask_t *mask, int num) -{ - int ret, 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); - - /* - * If no user supplied number or it's too large, then attempt - * to use all CPUs - */ - if (0 == num || CPU_SETSIZE < num) - num = CPU_COUNT(&cpuset); - - /* build the mask, allocating down from highest numbered CPU */ - for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) { - if (CPU_ISSET(i, &cpuset)) { - odp_cpumask_set(mask, i); - cpu++; - } - } - - return cpu; -} - -int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED) -{ - odp_cpumask_zero(mask); - /* By default all control threads on CPU 0 */ - odp_cpumask_set(mask, 0); - return 1; -} diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c new file mode 100644 index 0000000..665e82a --- /dev/null +++ b/platform/linux-generic/odp_cpumask_task.c @@ -0,0 +1,52 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include + +#include +#include + +int odp_cpumask_def_worker(odp_cpumask_t *mask, int num) +{ + int ret, 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); + + /* + * If no user supplied number or it's too large, then attempt + * to use all CPUs + */ + if (0 == num || CPU_SETSIZE < num) + num = CPU_COUNT(&cpuset); + + /* build the mask, allocating down from highest numbered CPU */ + for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) { + if (CPU_ISSET(i, &cpuset)) { + odp_cpumask_set(mask, i); + cpu++; + } + } + + return cpu; +} + +int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED) +{ + odp_cpumask_zero(mask); + /* By default all control threads on CPU 0 */ + odp_cpumask_set(mask, 0); + return 1; +}