From patchwork Tue Dec 6 14:15:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balakrishna Garapati X-Patchwork-Id: 86845 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp2306436obb; Tue, 6 Dec 2016 06:16:10 -0800 (PST) X-Received: by 10.55.86.70 with SMTP id k67mr61217499qkb.280.1481033770530; Tue, 06 Dec 2016 06:16:10 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d28si11772494qtc.178.2016.12.06.06.16.10; Tue, 06 Dec 2016 06:16:10 -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 1365F60E73; Tue, 6 Dec 2016 14:16:10 +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 64EEC60C89; Tue, 6 Dec 2016 14:16:02 +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 3363760E64; Tue, 6 Dec 2016 14:15:53 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id 0788560C7F for ; Tue, 6 Dec 2016 14:15:52 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id t79so127222111wmt.0 for ; Tue, 06 Dec 2016 06:15:51 -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:cc:subject:date:message-id; bh=LHCp5A0lUHlE8najIn+L8TaXo1uTR8EEap0qGq5AlKs=; b=f/32FZWIzKmfDkS1bBdZlhnughX1L0663YrzKed9q5aLCATkP+i4eGUzXwyXuz9GGR /dYJCwk6gOnQkVv0iVnQIsieJhz02ObpoBZkl1e4MJCk2WBpMAOmtwJOtdd7odXdFD7C t6Z1ugxPzIHAj+zp1cJ2olPquwAPN1nw+Uz0QYCd7jmM83pmw1AEyFyFYhujFURVeb/R J/dEN1VEmOMwwAXrB7ZgSM/+uXyBLDPIqeEyZRw7go3CU6pAvws1yn5B3L8pwtI07BV+ 50ettfuZwqRw60RlZhAxQFpJfYa9dBrMcnJ7tLzHm+DvpmQn7JcEQLZJyrQ96BBA22mu 2akg== X-Gm-Message-State: AKaTC02KrTnYEBRqHBZYKgAezsRlG+KFb8RpUuEuDyOy2aFkNobwZI5tDbTwUQs5SmffGUiPBJA= X-Received: by 10.46.32.77 with SMTP id g74mr19639741ljg.31.1481033750915; Tue, 06 Dec 2016 06:15:50 -0800 (PST) Received: from elxahtkds32.localdomain (host-95-192-172-200.mobileonline.telia.com. [95.192.172.200]) by smtp.gmail.com with ESMTPSA id s7sm3929454lja.14.2016.12.06.06.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 06:15:50 -0800 (PST) From: Balakrishna Garapati To: lng-odp@lists.linaro.org Date: Tue, 6 Dec 2016 15:15:49 +0100 Message-Id: <1481033749-4729-1-git-send-email-balakrishna.garapati@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCHv4] 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 --- since v3: Renaming function call platform/linux-generic/odp_cpumask.c | 73 +++++++++--------------------------- 1 file changed, 18 insertions(+), 55 deletions(-) -- 1.9.1 diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index 6bf2632..64559a6 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -225,73 +225,36 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu) * This function obtains system information specifying which cpus are * available at boot time. */ -static int get_installed_cpus(void) +static int get_available_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; } /* @@ -429,7 +392,7 @@ int odp_cpumask_init_global(const odp_init_t *params) * Initialize the global control and worker cpumasks with lists of * all installed CPUs. Return an error if this procedure fails. */ - if (!get_installed_cpus()) { + if (!get_available_cpus()) { if (params) { if (params->control_cpus) { /*