From patchwork Wed Apr 16 00:34:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 1 Return-Path: Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by dpdk.org (Postfix) with ESMTP id 30FEEAFDC for ; Wed, 16 Apr 2014 02:34:46 +0200 (CEST) Received: by mail-pd0-f171.google.com with SMTP id r10so10082642pdi.2 for ; Tue, 15 Apr 2014 17:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=fxrjgGAX4G6Ux0usUzttaUeL3R+FIIW5G4KWxBoF4hA=; b=OUAiDKLi08FdJCKdFiVsBGJ5gYLYtT11xfZGUf4ZlSyWlEEvipGzKZ/tWY683ZfkRQ FhpEtqLaW+32JXrQkp13hdbqNp9K9IKI9lR2ynSIt+F9rIC7duhlJWLBecrp84+sD4Ba MRDFjaf9izifIgnfAFErC5/pCOioVYDH/2ThPV0Og/MJnpEox5jvFEypkuNWK4lhTrFg pDECkwSvlLX8TcFu80vJL6LjVskZVLaINRubKxXhyK6FVKr5q9dLagzkfE3zcVeXzR1K 06zrtvkaq7L2Cq37UJgf/9ArWcZqvTBMzPLRZE0ZIEr2gp4VSkjOwxLkOkkov5fyhHPR 4STA== X-Received: by 10.69.31.42 with SMTP id kj10mr5029616pbd.165.1397608486112; Tue, 15 Apr 2014 17:34:46 -0700 (PDT) Received: from [10.200.0.70] ([124.207.145.166]) by mx.google.com with ESMTPSA id sy1sm102414849pab.30.2014.04.15.17.34.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Apr 2014 17:34:44 -0700 (PDT) Message-ID: <534DD019.108@gmail.com> Date: Wed, 16 Apr 2014 08:34:33 +0800 From: Wang Sheng-Hui User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: dev@dpdk.org Subject: [dpdk-dev] [PATCH] eal_lcore: check /sys/devices/system/node/nodeY/cpuX as a, fallback for socket id detecting X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Apr 2014 00:34:46 -0000 3 ways to get the NUMA info: 1) check the existence of symlink /sys/devices/system/cpu/cpuX/nodeY 2) check the existence of symlink /sys/devices/system/node/nodeY/cpuX 3) get the value from /sys/devices/system/cpu/cpuX/topology/physical_package_id Signed-off-by: Wang Sheng-Hui --- lib/librte_eal/linuxapp/eal/eal_lcore.c | 76 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c index da20fa3..ace5cec 100644 --- a/lib/librte_eal/linuxapp/eal/eal_lcore.c +++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include #include @@ -49,6 +52,7 @@ #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u" #define CORE_ID_FILE "topology/core_id" #define PHYS_PKG_FILE "topology/physical_package_id" +#define SYS_NODE_DIR "/sys/devices/system/node" /* Check if a cpu is present by the presence of the cpu information for it */ static int @@ -66,31 +70,36 @@ cpu_detected(unsigned lcore_id) } /* Get CPU socket id (NUMA node) by reading directory - * /sys/devices/system/cpu/cpuX looking for symlink "nodeY" + * /sys/devices/system/cpu/cpuX looking for symlink "nodeY", + * or /sys/devices/system/node/nodeY for symlink "cpuX", * which gives the NUMA topology information. * Note: physical package id != NUMA node, but we use it as a - * fallback for kernels which don't create a nodeY link + * fallback for kernels which don't create a nodeY or cpuX link. */ static unsigned cpu_socket_id(unsigned lcore_id) { const char node_prefix[] = "node"; + const char cpu_prefix[] = "cpu"; const size_t prefix_len = sizeof(node_prefix) - 1; char path[PATH_MAX]; DIR *d; + DIR *sub_dir = NULL; unsigned long id = 0; struct dirent *e; char *endptr = NULL; + RTE_LOG(DEBUG, EAL, "Read numa node link for lcore %u from" + "/sys/devices/system/cpu/cpu%u/nodeX\n", + lcore_id, lcore_id); + int len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR, lcore_id); if (len <= 0 || (unsigned)len >= sizeof(path)) goto err; - d = opendir(path); if (!d) goto err; - while ((e = readdir(d)) != NULL) { if (strncmp(e->d_name, node_prefix, prefix_len) == 0) { id = strtoul(e->d_name+prefix_len, &endptr, 0); @@ -98,23 +107,56 @@ cpu_socket_id(unsigned lcore_id) } } closedir(d); - if (endptr == NULL || *endptr!='\0' || endptr == e->d_name+prefix_len) { - RTE_LOG(WARNING, EAL, "Cannot read numa node link " - "for lcore %u - using physical package id instead\n", - lcore_id); - - len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", - lcore_id, PHYS_PKG_FILE); - if (len <= 0 || (unsigned)len >= sizeof(path)) - goto err; - if (eal_parse_sysfs_value(path, &id) != 0) - goto err; + if (! (endptr == NULL || *endptr!='\0' || + endptr == e->d_name+prefix_len)) + goto out; + + RTE_LOG(DEBUG, EAL, "Read numa node topo for lcore %u from " + "/sys/devices/system/node/nodeX/cpu%u\n", + lcore_id, lcore_id); + + len = rte_snprintf(path, sizeof(path), SYS_NODE_DIR); + if (len <= 0 || (unsigned)len >= sizeof(path)) + goto err; + d = opendir(path); + if (!d) + goto err; + while ((e = readdir(d)) != NULL) { + if (strncmp(e->d_name, node_prefix, prefix_len) == 0) { + len = rte_snprintf(path, sizeof(path), SYS_NODE_DIR "/%s/%s%d", + e->d_name, cpu_prefix, lcore_id); + if (len <= 0 || (unsigned)len >= sizeof(path)) + goto err; + sub_dir = opendir(path); + closedir(sub_dir); + if (!sub_dir) + continue; + id = strtoul(e->d_name+prefix_len, &endptr, 0); + break; + } } + closedir(d); + if (! (endptr == NULL || *endptr!='\0' || + endptr == e->d_name+prefix_len)) + goto out; + + RTE_LOG(WARNING, EAL, "Cannot read numa node link " + "for lcore %u - using physical package id instead\n", + lcore_id); + len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", + lcore_id, PHYS_PKG_FILE); + if (len <= 0 || (unsigned)len >= sizeof(path)) + goto err; + if (eal_parse_sysfs_value(path, &id) != 0) + goto err; + +out: return (unsigned)id; err: - RTE_LOG(ERR, EAL, "Error getting NUMA socket information from %s " - "for lcore %u - assuming NUMA socket 0\n", SYS_CPU_DIR, lcore_id); + RTE_LOG(ERR, EAL, "Error getting NUMA socket information from %s or %s" + "for lcore %u - assuming NUMA socket 0\n", SYS_CPU_DIR, + SYS_NODE_DIR, lcore_id); return 0; }