|
|
05ad79 |
diff -up util-linux-2.23.2/sys-utils/lscpu.c.kzak util-linux-2.23.2/sys-utils/lscpu.c
|
|
|
05ad79 |
--- util-linux-2.23.2/sys-utils/lscpu.c.kzak 2013-07-30 10:39:26.342739583 +0200
|
|
|
05ad79 |
+++ util-linux-2.23.2/sys-utils/lscpu.c 2014-01-14 11:21:51.837599200 +0100
|
|
|
05ad79 |
@@ -49,6 +49,7 @@
|
|
|
05ad79 |
/* /sys paths */
|
|
|
05ad79 |
#define _PATH_SYS_SYSTEM "/sys/devices/system"
|
|
|
05ad79 |
#define _PATH_SYS_CPU _PATH_SYS_SYSTEM "/cpu"
|
|
|
05ad79 |
+#define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
|
|
|
05ad79 |
#define _PATH_PROC_XEN "/proc/xen"
|
|
|
05ad79 |
#define _PATH_PROC_XENCAP _PATH_PROC_XEN "/capabilities"
|
|
|
05ad79 |
#define _PATH_PROC_CPUINFO "/proc/cpuinfo"
|
|
|
05ad79 |
@@ -157,6 +158,7 @@ struct lscpu_desc {
|
|
|
05ad79 |
cpu_set_t *online; /* mask with online CPUs */
|
|
|
05ad79 |
|
|
|
05ad79 |
int nnodes; /* number of NUMA modes */
|
|
|
05ad79 |
+ int *idx2nodenum; /* Support for discontinuous nodes */
|
|
|
05ad79 |
cpu_set_t **nodemaps; /* array with NUMA nodes */
|
|
|
05ad79 |
|
|
|
05ad79 |
/* books -- based on book_siblings (internal kernel map of cpuX's
|
|
|
05ad79 |
@@ -802,25 +804,59 @@ read_cache(struct lscpu_desc *desc, int
|
|
|
05ad79 |
}
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
+static inline int is_node_dirent(struct dirent *d)
|
|
|
05ad79 |
+{
|
|
|
05ad79 |
+ return
|
|
|
05ad79 |
+ d &&
|
|
|
05ad79 |
+#ifdef _DIRENT_HAVE_D_TYPE
|
|
|
05ad79 |
+ d->d_type == DT_DIR &&
|
|
|
05ad79 |
+#endif
|
|
|
05ad79 |
+ strncmp(d->d_name, "node", 4) == 0 &&
|
|
|
05ad79 |
+ isdigit_string(d->d_name + 4);
|
|
|
05ad79 |
+}
|
|
|
05ad79 |
+
|
|
|
05ad79 |
static void
|
|
|
05ad79 |
read_nodes(struct lscpu_desc *desc)
|
|
|
05ad79 |
{
|
|
|
05ad79 |
- int i;
|
|
|
05ad79 |
+ int i = 0;
|
|
|
05ad79 |
+ DIR *dir;
|
|
|
05ad79 |
+ struct dirent *d;
|
|
|
05ad79 |
+ char *path;
|
|
|
05ad79 |
|
|
|
05ad79 |
/* number of NUMA node */
|
|
|
05ad79 |
- while (path_exist(_PATH_SYS_SYSTEM "/node/node%d", desc->nnodes))
|
|
|
05ad79 |
- desc->nnodes++;
|
|
|
05ad79 |
+ path = path_strdup(_PATH_SYS_NODE);
|
|
|
05ad79 |
+ dir = opendir(path);
|
|
|
05ad79 |
+ free(path);
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ while (dir && (d = readdir(dir))) {
|
|
|
05ad79 |
+ if (is_node_dirent(d))
|
|
|
05ad79 |
+ desc->nnodes++;
|
|
|
05ad79 |
+ }
|
|
|
05ad79 |
|
|
|
05ad79 |
- if (!desc->nnodes)
|
|
|
05ad79 |
+ if (!desc->nnodes) {
|
|
|
05ad79 |
+ if (dir)
|
|
|
05ad79 |
+ closedir(dir);
|
|
|
05ad79 |
return;
|
|
|
05ad79 |
+ }
|
|
|
05ad79 |
|
|
|
05ad79 |
desc->nodemaps = xcalloc(desc->nnodes, sizeof(cpu_set_t *));
|
|
|
05ad79 |
+ desc->idx2nodenum = xmalloc(desc->nnodes * sizeof(int));
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ if (dir) {
|
|
|
05ad79 |
+ rewinddir(dir);
|
|
|
05ad79 |
+ while ((d = readdir(dir)) && i < desc->nnodes) {
|
|
|
05ad79 |
+ if (is_node_dirent(d))
|
|
|
05ad79 |
+ desc->idx2nodenum[i++] = strtol_or_err(((d->d_name) + 4),
|
|
|
05ad79 |
+ _("Failed to extract the node number"));
|
|
|
05ad79 |
+ }
|
|
|
05ad79 |
+ closedir(dir);
|
|
|
05ad79 |
+ }
|
|
|
05ad79 |
|
|
|
05ad79 |
/* information about how nodes share different CPUs */
|
|
|
05ad79 |
for (i = 0; i < desc->nnodes; i++)
|
|
|
05ad79 |
desc->nodemaps[i] = path_read_cpuset(maxcpus,
|
|
|
05ad79 |
_PATH_SYS_SYSTEM "/node/node%d/cpumap",
|
|
|
05ad79 |
- i);
|
|
|
05ad79 |
+ desc->idx2nodenum[i]);
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
static char *
|
|
|
05ad79 |
@@ -850,7 +886,7 @@ get_cell_data(struct lscpu_desc *desc, i
|
|
|
05ad79 |
case COL_NODE:
|
|
|
05ad79 |
if (cpuset_ary_isset(cpu, desc->nodemaps,
|
|
|
05ad79 |
desc->nnodes, setsize, &idx) == 0)
|
|
|
05ad79 |
- snprintf(buf, bufsz, "%zd", idx);
|
|
|
05ad79 |
+ snprintf(buf, bufsz, "%d", desc->idx2nodenum[idx]);
|
|
|
05ad79 |
break;
|
|
|
05ad79 |
case COL_BOOK:
|
|
|
05ad79 |
if (cpuset_ary_isset(cpu, desc->bookmaps,
|
|
|
05ad79 |
@@ -1250,7 +1286,7 @@ print_summary(struct lscpu_desc *desc, s
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
for (i = 0; i < desc->nnodes; i++) {
|
|
|
05ad79 |
- snprintf(buf, sizeof(buf), _("NUMA node%d CPU(s):"), i);
|
|
|
05ad79 |
+ snprintf(buf, sizeof(buf), _("NUMA node%d CPU(s):"), desc->idx2nodenum[i]);
|
|
|
05ad79 |
print_cpuset(buf, desc->nodemaps[i], mod->hex);
|
|
|
05ad79 |
}
|
|
|
05ad79 |
}
|