From patchwork Mon Nov 28 14:34:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 84413 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1162164qgi; Mon, 28 Nov 2016 06:34:21 -0800 (PST) X-Received: by 10.233.235.67 with SMTP id b64mr21083806qkg.156.1480343661696; Mon, 28 Nov 2016 06:34:21 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o21si24753480qtf.100.2016.11.28.06.34.21; Mon, 28 Nov 2016 06:34:21 -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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 55DF6607D4; Mon, 28 Nov 2016 14:34:21 +0000 (UTC) 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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 55F3B60643; Mon, 28 Nov 2016 14:34:17 +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 220E460643; Mon, 28 Nov 2016 14:34:15 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id 5560D60AC5 for ; Mon, 28 Nov 2016 14:34:09 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id t196so97856510lff.3 for ; Mon, 28 Nov 2016 06:34:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=bHBIg9iCgWV9wSyOYb6rNaWW0Nt84K27aRNUD3J5rrQ=; b=LjUxweK6OtXGGGqs4ySVzAoD4eznR5S4MHet49zx+Tc4+TNsMWwD8+7iPnoOZI0rop wCBwXFq8+zr5BQxp/I30QJYaRJzppz3Jhp7omak3Mt98w0nWwFs2srxc3A/O7yXod7IF 6EQE3dip8tHEq3T509mAePgWxTTPJCV4vuBrw7XYHv7j32AlTgvj9uhuHpF2IN/HbttG fSG0yCZcHTCHcR8fIeBxlWJSxrME0mzkzRbPB6C2Uelgl+0RF3bkD61/z+EEmZw4rJsy Zxdqjt0zaTN7g5lVrkSnwaaQqRtGECD5wphVkCDCGwo855oJyK9ynYI4xGOXGz1rlRq5 EscA== X-Gm-Message-State: AKaTC01Vy5EwhO13tmmWEvdtww1hRcnA05ps/pxehQ0AKYnmpKrQxUaxSJ255SOBea7dX6f2dO4= X-Received: by 10.25.40.212 with SMTP id o203mr8398446lfo.1.1480343647887; Mon, 28 Nov 2016 06:34:07 -0800 (PST) Received: from elxahtkds32.localdomain (host-95-192-68-15.mobileonline.telia.com. [95.192.68.15]) by smtp.gmail.com with ESMTPSA id l141sm12865828lfl.0.2016.11.28.06.34.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 06:34:07 -0800 (PST) From: Balakrishna Garapati To: lng-odp@lists.linaro.org Date: Mon, 28 Nov 2016 15:34:06 +0100 Message-Id: <1480343646-5423-1-git-send-email-balakrishna.garapati@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCHv3] platform: linux-generic: reading cpu affinity from cpuset 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" With this new proposal cpu affinity is read correctly especially when using cgroups otherwise wrong cpu mask is set. Fixes bug: https://bugs.linaro.org/show_bug.cgi?id=2472 Signed-off-by: Balakrishna Garapati --- v1 to v2: added Description of the issue to the patch commit log. v2 to v3: Resending the patch adding the log change from v1 to v2 platform/linux-generic/odp_cpumask.c | 69 +++++++++--------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) -- 1.9.1 diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index 6bf2632..7b0d80a 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -227,71 +227,34 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu) */ static int get_installed_cpus(void) { - char *numptr; - char *endptr; - long int cpu_idnum; - DIR *d; - struct dirent *dir; + int cpu_idnum; + cpu_set_t cpuset; + int ret; /* Clear the global cpumasks for control and worker CPUs */ odp_cpumask_zero(&odp_global_data.control_cpus); odp_cpumask_zero(&odp_global_data.worker_cpus); - /* - * Scan the /sysfs pseudo-filesystem for CPU info directories. - * There should be one subdirectory for each installed logical CPU - */ - d = opendir("/sys/devices/system/cpu"); - if (d) { - while ((dir = readdir(d)) != NULL) { - cpu_idnum = CPU_SETSIZE; - - /* - * If the current directory entry doesn't represent - * a CPU info subdirectory then skip to the next entry. - */ - if (dir->d_type == DT_DIR) { - if (!strncmp(dir->d_name, "cpu", 3)) { - /* - * Directory name starts with "cpu"... - * Try to extract a CPU ID number - * from the remainder of the dirname. - */ - errno = 0; - numptr = dir->d_name; - numptr += 3; - cpu_idnum = strtol(numptr, &endptr, - 10); - if (errno || (endptr == numptr)) - continue; - } else { - continue; - } - } else { - continue; - } - /* - * If we get here the current directory entry specifies - * a CPU info subdir for the CPU indexed by cpu_idnum. - */ + CPU_ZERO(&cpuset); + ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); - /* Track number of logical CPUs discovered */ - if (odp_global_data.num_cpus_installed < - (int)(cpu_idnum + 1)) - odp_global_data.num_cpus_installed = - (int)(cpu_idnum + 1); + if (ret < 0) { + ODP_ERR("Failed to get cpu affinity"); + return -1; + } + for (cpu_idnum = 0; cpu_idnum < CPU_SETSIZE - 1; cpu_idnum++) { + if (CPU_ISSET(cpu_idnum, &cpuset)) { + odp_global_data.num_cpus_installed++; /* Add the CPU to our default cpumasks */ odp_cpumask_set(&odp_global_data.control_cpus, - (int)cpu_idnum); + (int)cpu_idnum); odp_cpumask_set(&odp_global_data.worker_cpus, - (int)cpu_idnum); + (int)cpu_idnum); } - closedir(d); - return 0; - } else { - return -1; } + + return 0; } /*