From patchwork Thu Jul 9 13:46:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 50963 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8CD1B228E5 for ; Thu, 9 Jul 2015 13:51:06 +0000 (UTC) Received: by lbbpo10 with SMTP id po10sf32651276lbb.1 for ; Thu, 09 Jul 2015 06:51:05 -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=mW3jrNFAXb2yQdv7HjCZOwog/hLyhzsJQeQVGn20W5c=; b=BQEsc1JtCmfFilh59bf9qJeaMtO3DPMktzgT5ZRz+wQmvatoh3m6nAzr0K/BNwTOse kpMJDKNEIiyzfZcU2420oVTwBPiRUQrwtS+Pkc6ETwpH1V0xkz4Iur8NM7sE/20+7rwg FoQX1vyj1e4kvbtvcyHwHomH4l9uPQCYA+9TmwKjBQcsbVM5hGgRHhm3NmHQsWK9CWbA V8eMPFBA5dc3nP/9/YLsl8Ob8nwlKjQ93S4/E91FhPWRCo3ptSWmSi5wTT5B1cvRqORY hAL+nSaZj9LSMk2aGlHhbS1mgAiz90KAH0LQvX3i/4JPGvrhrfXLd4IsmiV4EgAQlrfl 1F8w== X-Gm-Message-State: ALoCoQmNCHbpD7DwzHhUpsy51D3MJhjZKUYFYoZ2Ap6+pQJCRzFQvGQ4j3BeifoSAj/a6KrV4e3f X-Received: by 10.112.98.42 with SMTP id ef10mr173324lbb.18.1436449865575; Thu, 09 Jul 2015 06:51:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.228 with SMTP id h4ls1097286lam.23.gmail; Thu, 09 Jul 2015 06:51:05 -0700 (PDT) X-Received: by 10.152.3.70 with SMTP id a6mr14947646laa.44.1436449865415; Thu, 09 Jul 2015 06:51:05 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id xg7si4875975lbb.48.2015.07.09.06.51.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 06:51:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbzd8 with SMTP id d8so30151804lbz.0 for ; Thu, 09 Jul 2015 06:51:05 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr14936520laj.88.1436449865234; Thu, 09 Jul 2015 06:51:05 -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 hn6csp682592lbb; Thu, 9 Jul 2015 06:51:04 -0700 (PDT) X-Received: by 10.140.238.22 with SMTP id j22mr25698075qhc.98.1436449863936; Thu, 09 Jul 2015 06:51:03 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d34si6833488qgd.127.2015.07.09.06.51.03; Thu, 09 Jul 2015 06:51:03 -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 0C4C761FC9; Thu, 9 Jul 2015 13:51:03 +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 3947061FDE; Thu, 9 Jul 2015 13:47:40 +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 8667F61FE4; Thu, 9 Jul 2015 13:47:35 +0000 (UTC) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by lists.linaro.org (Postfix) with ESMTPS id 697FA61FD0 for ; Thu, 9 Jul 2015 13:46:42 +0000 (UTC) Received: by wiga1 with SMTP id a1so313531817wig.0 for ; Thu, 09 Jul 2015 06:46:41 -0700 (PDT) X-Received: by 10.194.184.140 with SMTP id eu12mr30222264wjc.78.1436449601578; Thu, 09 Jul 2015 06:46:41 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id df1sm8414627wib.12.2015.07.09.06.46.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Jul 2015 06:46:40 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 9 Jul 2015 16:46:19 +0300 Message-Id: <1436449585-23252-6-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 05/11] api: cpumask: added default masks 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.176 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 Added default cpumask functions for worker and control threads. These will replace odph_linux_cpumask_default() helper. CPU masks and IDs are system specific, API is generic. Signed-off-by: Petri Savolainen Reviewed-by: Christophe Milard Signed-off-by: Maxim Uvarov --- include/odp/api/cpumask.h | 24 +++++++++++++++++++++++ platform/linux-generic/odp_cpumask.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/odp/api/cpumask.h b/include/odp/api/cpumask.h index 1fdbfb4..02fd131 100644 --- a/include/odp/api/cpumask.h +++ b/include/odp/api/cpumask.h @@ -194,6 +194,30 @@ int odp_cpumask_last(const odp_cpumask_t *mask); int odp_cpumask_next(const odp_cpumask_t *mask, int cpu); /** + * Default cpumask for worker threads + * + * Initializes cpumask with CPUs available for worker threads. Sets up to 'num' + * CPUs and returns the count actually set. Use zero for all available CPUs. + * + * @param[out] mask CPU mask to initialize + * @param num Number of worker threads, zero for all available CPUs + * @return Actual number of CPUs used to create the mask + */ +int odp_cpumask_def_worker(odp_cpumask_t *mask, int num); + +/** + * Default cpumask for control threads + * + * Initializes cpumask with CPUs available for control threads. Sets up to 'num' + * CPUs and returns the count actually set. Use zero for all available CPUs. + * + * @param[out] mask CPU mask to initialize + * @param num Number of control threads, zero for all available CPUs + * @return Actual number of CPUs used to create the mask + */ +int odp_cpumask_def_control(odp_cpumask_t *mask, int num); + +/** * @} */ diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index a89c3b6..1ea7dcb 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -8,6 +8,7 @@ #define _GNU_SOURCE #endif #include +#include #include #include @@ -204,3 +205,40 @@ 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) +{ + /* By default all control threads on CPU 0 */ + odp_cpumask_set(mask, 0); + return 1; +}