[PATCH 2/2] tools/power turbostat: Optimize core count calculation and fix naming inconsistency
From: Zhang Rui
Date: Tue Mar 10 2026 - 02:04:39 EST
The current core counting logic has both naming and efficiency issues.
The variable topo.cores_per_node is misleadingly named since it actually
represents the maximum number of cores per package, not per node. And
the core count calculation is suboptimal and wastes memory.
Rename topo.cores_per_node to topo.cores_per_pkg and improve the system
core count calculation algorithm to avoid memory over-allocation.
Validated on multiple Intel platforms (ICX/SPR/SRF/EMR/GNR/CWF) with
various CPU online/offline configurations and SMT enabled/disabled
scenarios. No functional changes found.
Signed-off-by: Zhang Rui <rui.zhang@xxxxxxxxx>
---
tools/power/x86/turbostat/turbostat.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index ae827485950d..ef3059ba07cd 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2409,7 +2409,7 @@ struct topo_params {
int max_l3_id;
int max_node_num;
int nodes_per_pkg;
- int cores_per_node;
+ int cores_per_pkg;
int threads_per_core;
} topo;
@@ -9634,9 +9634,9 @@ void topology_probe(bool startup)
topo.max_core_id = max_core_id; /* within a package */
topo.max_package_id = max_package_id;
- topo.cores_per_node = max_core_id + 1;
+ topo.cores_per_pkg = max_core_id + 1;
if (debug > 1)
- fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", max_core_id, topo.cores_per_node);
+ fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", max_core_id, topo.cores_per_pkg);
if (!summary_only)
BIC_PRESENT(BIC_Core);
@@ -9701,7 +9701,7 @@ void allocate_counters_1(struct counters *counters)
void allocate_counters(struct counters *counters)
{
int i;
- int num_cores = topo.cores_per_node * topo.nodes_per_pkg * topo.num_packages;
+ int num_cores = topo.cores_per_pkg * topo.num_packages;
counters->threads = calloc(topo.max_cpu_num + 1, sizeof(struct thread_data));
if (counters->threads == NULL)
--
2.43.0