aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/power/x86/turbostat/turbostat.c65
1 files changed, 61 insertions, 4 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 6bf426813797..96390f7e4898 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -260,7 +260,8 @@ struct system_summary {
260struct cpu_topology { 260struct cpu_topology {
261 int physical_package_id; 261 int physical_package_id;
262 int logical_cpu_id; 262 int logical_cpu_id;
263 int node_id; 263 int physical_node_id;
264 int logical_node_id; /* 0-based count within the package */
264 int physical_core_id; 265 int physical_core_id;
265 cpu_set_t *put_ids; /* Processing Unit/Thread IDs */ 266 cpu_set_t *put_ids; /* Processing Unit/Thread IDs */
266} *cpus; 267} *cpus;
@@ -270,6 +271,8 @@ struct topo_params {
270 int num_cpus; 271 int num_cpus;
271 int num_cores; 272 int num_cores;
272 int max_cpu_num; 273 int max_cpu_num;
274 int max_node_num;
275 int num_nodes_per_pkg;
273 int num_cores_per_pkg; 276 int num_cores_per_pkg;
274 int num_threads_per_core; 277 int num_threads_per_core;
275} topo; 278} topo;
@@ -2399,7 +2402,54 @@ int get_core_id(int cpu)
2399 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); 2402 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
2400} 2403}
2401 2404
2402int get_node_id(struct cpu_topology *thiscpu) 2405void set_node_data(void)
2406{
2407 char path[80];
2408 FILE *filep;
2409 int pkg, node, cpu;
2410
2411 struct pkg_node_info {
2412 int count;
2413 int min;
2414 } *pni;
2415
2416 pni = calloc(topo.num_packages, sizeof(struct pkg_node_info));
2417 if (!pni)
2418 err(1, "calloc pkg_node_count");
2419
2420 for (pkg = 0; pkg < topo.num_packages; pkg++)
2421 pni[pkg].min = topo.num_cpus;
2422
2423 for (node = 0; node <= topo.max_node_num; node++) {
2424 /* find the "first" cpu in the node */
2425 sprintf(path, "/sys/bus/node/devices/node%d/cpulist", node);
2426 filep = fopen(path, "r");
2427 if (!filep)
2428 continue;
2429 fscanf(filep, "%d", &cpu);
2430 fclose(filep);
2431
2432 pkg = cpus[cpu].physical_package_id;
2433 pni[pkg].count++;
2434
2435 if (node < pni[pkg].min)
2436 pni[pkg].min = node;
2437 }
2438
2439 for (pkg = 0; pkg < topo.num_packages; pkg++)
2440 if (pni[pkg].count > topo.num_nodes_per_pkg)
2441 topo.num_nodes_per_pkg = pni[0].count;
2442
2443 for (cpu = 0; cpu < topo.num_cpus; cpu++) {
2444 pkg = cpus[cpu].physical_package_id;
2445 node = cpus[cpu].physical_node_id;
2446 cpus[cpu].logical_node_id = node - pni[pkg].min;
2447 }
2448 free(pni);
2449
2450}
2451
2452int get_physical_node_id(struct cpu_topology *thiscpu)
2403{ 2453{
2404 char path[80]; 2454 char path[80];
2405 FILE *filep; 2455 FILE *filep;
@@ -4675,7 +4725,9 @@ void topology_probe()
4675 max_package_id = cpus[i].physical_package_id; 4725 max_package_id = cpus[i].physical_package_id;
4676 4726
4677 /* get numa node information */ 4727 /* get numa node information */
4678 cpus[i].node_id = get_node_id(&cpus[i]); 4728 cpus[i].physical_node_id = get_physical_node_id(&cpus[i]);
4729 if (cpus[i].physical_node_id > topo.max_node_num)
4730 topo.max_node_num = cpus[i].physical_node_id;
4679 4731
4680 /* get core information */ 4732 /* get core information */
4681 cpus[i].physical_core_id = get_core_id(i); 4733 cpus[i].physical_core_id = get_core_id(i);
@@ -4690,9 +4742,10 @@ void topology_probe()
4690 if (debug > 1) 4742 if (debug > 1)
4691 fprintf(outf, "cpu %d pkg %d node %d core %d\n", 4743 fprintf(outf, "cpu %d pkg %d node %d core %d\n",
4692 i, cpus[i].physical_package_id, 4744 i, cpus[i].physical_package_id,
4693 cpus[i].node_id, 4745 cpus[i].physical_node_id,
4694 cpus[i].physical_core_id); 4746 cpus[i].physical_core_id);
4695 } 4747 }
4748
4696 topo.num_cores_per_pkg = max_core_id + 1; 4749 topo.num_cores_per_pkg = max_core_id + 1;
4697 if (debug > 1) 4750 if (debug > 1)
4698 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", 4751 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n",
@@ -4707,6 +4760,10 @@ void topology_probe()
4707 if (!summary_only && topo.num_packages > 1) 4760 if (!summary_only && topo.num_packages > 1)
4708 BIC_PRESENT(BIC_Package); 4761 BIC_PRESENT(BIC_Package);
4709 4762
4763 set_node_data();
4764 if (debug > 1)
4765 fprintf(outf, "num_nodes_per_pkg %d\n", topo.num_nodes_per_pkg);
4766
4710 topo.num_threads_per_core = max_siblings; 4767 topo.num_threads_per_core = max_siblings;
4711 if (debug > 1) 4768 if (debug > 1)
4712 fprintf(outf, "max_siblings %d\n", max_siblings); 4769 fprintf(outf, "max_siblings %d\n", max_siblings);