From patchwork Mon Nov 28 14:25:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 84411 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1158344qgi; Mon, 28 Nov 2016 06:25:36 -0800 (PST) X-Received: by 10.55.17.68 with SMTP id b65mr18563985qkh.60.1480343135368; Mon, 28 Nov 2016 06:25:35 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j26si24772715qta.114.2016.11.28.06.25.33; Mon, 28 Nov 2016 06:25:35 -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 3671B610F6; Mon, 28 Nov 2016 14:25:33 +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 28EDD60B14; Mon, 28 Nov 2016 14:25:29 +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 432DE60B3F; Mon, 28 Nov 2016 14:25:27 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 1AE8A60AC5 for ; Mon, 28 Nov 2016 14:25:26 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id c13so97384332lfg.0 for ; Mon, 28 Nov 2016 06:25:26 -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=J4VrlkXtZQrBD6bGZ8ZwKiDZOFUozA3LMlXnGjtXeOg=; b=H4nA7+oXrPlR4YjnkV5SOA36QV9WG7PLsLYA6yE+PVb7+G7al2ZsRi7AMKDXCM1+gb UU1S1+lRQb12vjrGbbqy2YBy7DIv4iQSMRqfYD68rJdomdfxKAMEw2zfGNRLd+FbYdOm nMpZOrc/hyrHwY5stb6Mtt0+cTTooIW6OgPJfJL45OArSTvmf8GVlHIIQOAnSAuplQrM SVCWwx+DTblwXY9jcJcJ3lBDKtPXC8hmW0QTfTOxV2I+KtbMHpkXoFUpMXo5Ckx0MIvG VmzwmbntA7FKFI3ksBGvXDpxmMFg0VdOnbg/qKCXk+y37bwk6oeEpKRZPdnmNXLOkVGi YQ5Q== X-Gm-Message-State: AKaTC02TZ8BKKbnls64Hq2cozlxmBU/g+V+iawt9A6H6tu52sbObOeEO3FNXBfMcmy40EEbA27E= X-Received: by 10.25.17.207 with SMTP id 76mr7987219lfr.93.1480343124596; Mon, 28 Nov 2016 06:25:24 -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 d16sm13040461lfj.14.2016.11.28.06.25.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 06:25:24 -0800 (PST) From: Balakrishna Garapati To: lng-odp@lists.linaro.org Date: Mon, 28 Nov 2016 15:25:22 +0100 Message-Id: <1480343122-30521-1-git-send-email-balakrishna.garapati@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCHv2] 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 --- 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; } /*