From patchwork Mon Nov 28 13:35:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 84405 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1136919qgi; Mon, 28 Nov 2016 05:36:17 -0800 (PST) X-Received: by 10.233.232.133 with SMTP id a127mr20162266qkg.235.1480340177773; Mon, 28 Nov 2016 05:36:17 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d36si24627102qte.109.2016.11.28.05.36.17; Mon, 28 Nov 2016 05:36:17 -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 1C3FB61065; Mon, 28 Nov 2016 13:36:17 +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 CDDF8609B5; Mon, 28 Nov 2016 13:36:12 +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 398CF60D8C; Mon, 28 Nov 2016 13:36:01 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id 435AF609B5 for ; Mon, 28 Nov 2016 13:35:58 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id o141so96337130lff.1 for ; Mon, 28 Nov 2016 05:35:58 -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=ZsqutzYqXdsrJxNpxR67tUIf4AFw22j7EJPyUsMVkp8=; b=hr16aC7wo0w7RTE/niRl1u6GptdIlZR1DWD/Ep/EmQ4d6xZkRpnKhqah1daHrPVuZo vVVxp6B+9ooVkowkMIO7KXXg7RnNCLJonyWCuDMv5a7cEvZO1D1mrfcJeqUIW8JiAh1S riIXvSDof41vfjot/dr3nIZgNulnB9IZh6+KmnKl2YRpnZnQEG6qbck4LAK1LeTjlPQg 5Gb1c2s30Ktt8coo0Vc3NrdbABxXe9fDQC8/FQh4hRKwuP36/8YoTSCzwzf76SlQp/8K eQokAOcyOf7Ar8cAjaIzLIpNiOVoHgF9IfW6Wep3pWV0wA6ZWHzjCfxzXjzAWSP+Cieq 5QEQ== X-Gm-Message-State: AKaTC00/KFaURR+L2d0G98tMu+PTTVtZky34n73Lma9+fCAkRS7Cpbr0eBwDuTsNCh7zp87trJY= X-Received: by 10.25.212.77 with SMTP id l74mr8034886lfg.103.1480340156852; Mon, 28 Nov 2016 05:35:56 -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 u74sm12941665lfi.9.2016.11.28.05.35.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 05:35:56 -0800 (PST) From: Balakrishna Garapati To: lng-odp@lists.linaro.org Date: Mon, 28 Nov 2016 14:35:55 +0100 Message-Id: <1480340155-19372-1-git-send-email-balakrishna.garapati@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCH] 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" Fixes bug: https://bugs.linaro.org/show_bug.cgi?id=2472 Signed-off-by: Balakrishna Garapati --- With this new proposal cpu affinity is read correctly especialy when using cgroups otherwise wrong cpu mask is set. 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; } /*