Commit 2ffbb224 authored by Prarit Bhargava's avatar Prarit Bhargava Committed by Len Brown

tools/power turbostat: Fix logical node enumeration to allow for non-sequential physical nodes

turbostat fails on some multi-package topologies because the logical node
enumeration assumes that the nodes are sequentially numbered,
which causes the logical numa nodes to not be enumerated, or enumerated incorrectly.

Use a more robust enumeration algorithm which allows for non-seqential physical nodes.
Signed-off-by: default avatarPrarit Bhargava <prarit@redhat.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent cfce494d
...@@ -2471,55 +2471,43 @@ int get_core_id(int cpu) ...@@ -2471,55 +2471,43 @@ int get_core_id(int cpu)
void set_node_data(void) void set_node_data(void)
{ {
char path[80]; int pkg, node, lnode, cpu, cpux;
FILE *filep; int cpu_count;
int pkg, node, cpu;
/* initialize logical_node_id */
struct pkg_node_info { for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu)
int count; cpus[cpu].logical_node_id = -1;
int min;
} *pni; cpu_count = 0;
for (pkg = 0; pkg < topo.num_packages; pkg++) {
pni = calloc(topo.num_packages, sizeof(struct pkg_node_info)); lnode = 0;
if (!pni) for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu) {
err(1, "calloc pkg_node_count"); if (cpus[cpu].physical_package_id != pkg)
continue;
for (pkg = 0; pkg < topo.num_packages; pkg++) /* find a cpu with an unset logical_node_id */
pni[pkg].min = topo.num_cpus; if (cpus[cpu].logical_node_id != -1)
continue;
for (node = 0; node <= topo.max_node_num; node++) { cpus[cpu].logical_node_id = lnode;
/* find the "first" cpu in the node */ node = cpus[cpu].physical_node_id;
sprintf(path, "/sys/bus/node/devices/node%d/cpulist", node); cpu_count++;
filep = fopen(path, "r"); /*
if (!filep) * find all matching cpus on this pkg and set
continue; * the logical_node_id
fscanf(filep, "%d", &cpu); */
fclose(filep); for (cpux = cpu; cpux <= topo.max_cpu_num; cpux++) {
if ((cpus[cpux].physical_package_id == pkg) &&
pkg = cpus[cpu].physical_package_id; (cpus[cpux].physical_node_id == node)) {
pni[pkg].count++; cpus[cpux].logical_node_id = lnode;
cpu_count++;
if (node < pni[pkg].min) }
pni[pkg].min = node; }
} lnode++;
if (lnode > topo.nodes_per_pkg)
for (pkg = 0; pkg < topo.num_packages; pkg++) topo.nodes_per_pkg = lnode;
if (pni[pkg].count > topo.nodes_per_pkg) }
topo.nodes_per_pkg = pni[0].count; if (cpu_count >= topo.max_cpu_num)
break;
/* Fake 1 node per pkg for machines that don't
* expose nodes and thus avoid -nan results
*/
if (topo.nodes_per_pkg == 0)
topo.nodes_per_pkg = 1;
for (cpu = 0; cpu < topo.num_cpus; cpu++) {
pkg = cpus[cpu].physical_package_id;
node = cpus[cpu].physical_node_id;
cpus[cpu].logical_node_id = node - pni[pkg].min;
} }
free(pni);
} }
int get_physical_node_id(struct cpu_topology *thiscpu) int get_physical_node_id(struct cpu_topology *thiscpu)
...@@ -4840,14 +4828,6 @@ void topology_probe() ...@@ -4840,14 +4828,6 @@ void topology_probe()
max_siblings = siblings; max_siblings = siblings;
if (cpus[i].thread_id == 0) if (cpus[i].thread_id == 0)
topo.num_cores++; topo.num_cores++;
if (debug > 1)
fprintf(outf,
"cpu %d pkg %d node %d core %d thread %d\n",
i, cpus[i].physical_package_id,
cpus[i].physical_node_id,
cpus[i].physical_core_id,
cpus[i].thread_id);
} }
topo.cores_per_node = max_core_id + 1; topo.cores_per_node = max_core_id + 1;
...@@ -4873,6 +4853,20 @@ void topology_probe() ...@@ -4873,6 +4853,20 @@ void topology_probe()
topo.threads_per_core = max_siblings; topo.threads_per_core = max_siblings;
if (debug > 1) if (debug > 1)
fprintf(outf, "max_siblings %d\n", max_siblings); fprintf(outf, "max_siblings %d\n", max_siblings);
if (debug < 1)
return;
for (i = 0; i <= topo.max_cpu_num; ++i) {
fprintf(outf,
"cpu %d pkg %d node %d lnode %d core %d thread %d\n",
i, cpus[i].physical_package_id,
cpus[i].physical_node_id,
cpus[i].logical_node_id,
cpus[i].physical_core_id,
cpus[i].thread_id);
}
} }
void void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment