From patchwork Wed Jan 14 22:48:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 43137 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8D6A3240B9 for ; Wed, 14 Jan 2015 22:49:56 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf6261890lbi.0 for ; Wed, 14 Jan 2015 14:49:55 -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=1dKUN0Q3GEyNRMp9ZiqexElQrm99/hXnK5e+cIFI91s=; b=bthlDeNTMTUqH9AS1vIjbwBPAIAfFKX/C2OzIYboEgskWG3zdjPSVYZY5pb+rWB5v7 hfrjYfhCAT9H12LYUcGnnEQbY7qRmpkVaApK3vE5GeVIVUy4Nvdtcc6o5VlJcHSN5U8g tEV2R9KzdBvq5EVJsdar+FtgP3ppxr4TGviNmmARuCUQV53tZRxBfYcjrqfckaAdztkl k+s0yMBO7eBLB7KbX4ZZ6HZqvzDizC3yN+oYcgJvm7nyjE3/KnhRNJjAjOMNBEVydAsO xMKHc29kku7sYyZGVVjCRgVruYS0xuDpUP4uHgVVpR1vnezXHuBjB+DLepLmoS+thVbm O/SA== X-Gm-Message-State: ALoCoQnr7fI/b8rSSkEJmx6SQcru9ah/rTzqpCZS4azTipBmSVTXFIDWYk6qacFpZ1uh9APSIkUs X-Received: by 10.112.89.36 with SMTP id bl4mr820901lbb.1.1421275795539; Wed, 14 Jan 2015 14:49:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.136 with SMTP id kq8ls160488lac.84.gmail; Wed, 14 Jan 2015 14:49:55 -0800 (PST) X-Received: by 10.112.172.167 with SMTP id bd7mr6662238lbc.14.1421275795401; Wed, 14 Jan 2015 14:49:55 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id bn7si28500694lbc.124.2015.01.14.14.49.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 Jan 2015 14:49:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gd6so10814141lab.1 for ; Wed, 14 Jan 2015 14:49:55 -0800 (PST) X-Received: by 10.152.27.8 with SMTP id p8mr6553883lag.69.1421275795318; Wed, 14 Jan 2015 14:49:55 -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.9.200 with SMTP id c8csp1845670lbb; Wed, 14 Jan 2015 14:49:54 -0800 (PST) X-Received: by 10.229.65.133 with SMTP id j5mr11404303qci.27.1421275794076; Wed, 14 Jan 2015 14:49:54 -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 i6si33057160qan.53.2015.01.14.14.49.53 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 14 Jan 2015 14:49:54 -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 1YBWl5-0000KS-1Z; Wed, 14 Jan 2015 22:49:51 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YBWke-0000BV-Lw for lng-odp@lists.linaro.org; Wed, 14 Jan 2015 22:49:24 +0000 Received: by mail-lb0-f179.google.com with SMTP id z11so10481528lbi.10 for ; Wed, 14 Jan 2015 14:49:19 -0800 (PST) X-Received: by 10.112.97.163 with SMTP id eb3mr377044lbb.47.1421275759058; Wed, 14 Jan 2015 14:49:19 -0800 (PST) Received: from localhost (c-853670d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.54.133]) by mx.google.com with ESMTPSA id kt7sm2174340lac.4.2015.01.14.14.49.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jan 2015 14:49:18 -0800 (PST) From: Anders Roxell To: lng-odp@lists.linaro.org Date: Wed, 14 Jan 2015 23:48:25 +0100 Message-Id: <1421275706-11176-9-git-send-email-anders.roxell@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421275706-11176-1-git-send-email-anders.roxell@linaro.org> References: <1421275706-11176-1-git-send-email-anders.roxell@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 8/9] helper: linux: add odph_linux_cpumask_default 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: anders.roxell@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.42 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: Robbie King A default cpumask based on number of requested CPUs and bounded by number of CPUs in the system. Signed-off-by: Robbie King Signed-off-by: Anders Roxell --- helper/include/odph_linux.h | 11 +++++++++++ platform/linux-generic/odp_linux.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/helper/include/odph_linux.h b/helper/include/odph_linux.h index 26ff278..6458fde 100644 --- a/helper/include/odph_linux.h +++ b/helper/include/odph_linux.h @@ -22,6 +22,7 @@ extern "C" { #endif +#include #include #include @@ -50,6 +51,16 @@ typedef struct { int status; /**< Process state change status */ } odph_linux_process_t; +/** + * Creates default pthread/process cpumask + * + * Creates cpumask based on starting count, actual value returned + * + * @param mask CPU mask to initialize + * @param num Number of threads to create, zero for all available + * @return Actual values of CPUs used to create mask + */ +int odph_linux_cpumask_default(odp_cpumask_t *mask, int num); /** * Creates and launches pthreads diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index ba1da1f..a051024 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -25,6 +25,41 @@ #include #include +int odph_linux_cpumask_default(odp_cpumask_t *mask, int num_in) +{ + int i; + int first_cpu = 1; + int num = num_in; + int cpu_count; + + cpu_count = odp_sys_cpu_count(); + + /* + * If no user supplied number or it's too large, then attempt + * to use all CPUs + */ + if (0 == num) + num = cpu_count; + if (cpu_count < num) + num = cpu_count; + + /* + * Always force "first_cpu" to a valid CPU + */ + if (first_cpu >= cpu_count) + first_cpu = cpu_count - 1; + + /* Build the mask */ + odp_cpumask_zero(mask); + for (i = 0; i < num; i++) { + int cpu; + + cpu = (first_cpu + i) % cpu_count; + odp_cpumask_set(mask, cpu); + } + + return num; +} static void *odp_run_start_routine(void *arg) {