Skip to content

Commit 0fe3752

Browse files
committed
tools/power/turbostat: Obey allowed CPUs for system summary
System summary should summarize the information for allowed CPUs instead of all the present CPUs. Introduce topology information for allowed CPUs, and use them to get system summary. Signed-off-by: Zhang Rui <[email protected]>
1 parent ccf8a05 commit 0fe3752

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,9 @@ struct topo_params {
11341134
int num_die;
11351135
int num_cpus;
11361136
int num_cores;
1137+
int allowed_packages;
1138+
int allowed_cpus;
1139+
int allowed_cores;
11371140
int max_cpu_num;
11381141
int max_node_num;
11391142
int nodes_per_pkg;
@@ -1179,7 +1182,6 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
11791182
struct thread_data *t;
11801183
struct core_data *c;
11811184
struct pkg_data *p;
1182-
11831185
t = GET_THREAD(thread_base, thread_no, core_no, node_no, pkg_no);
11841186

11851187
if (cpu_is_not_allowed(t->cpu_id))
@@ -2426,40 +2428,40 @@ void compute_average(struct thread_data *t, struct core_data *c, struct pkg_data
24262428
/* Use the global time delta for the average. */
24272429
average.threads.tv_delta = tv_delta;
24282430

2429-
average.threads.tsc /= topo.num_cpus;
2430-
average.threads.aperf /= topo.num_cpus;
2431-
average.threads.mperf /= topo.num_cpus;
2432-
average.threads.instr_count /= topo.num_cpus;
2433-
average.threads.c1 /= topo.num_cpus;
2431+
average.threads.tsc /= topo.allowed_cpus;
2432+
average.threads.aperf /= topo.allowed_cpus;
2433+
average.threads.mperf /= topo.allowed_cpus;
2434+
average.threads.instr_count /= topo.allowed_cpus;
2435+
average.threads.c1 /= topo.allowed_cpus;
24342436

24352437
if (average.threads.irq_count > 9999999)
24362438
sums_need_wide_columns = 1;
24372439

2438-
average.cores.c3 /= topo.num_cores;
2439-
average.cores.c6 /= topo.num_cores;
2440-
average.cores.c7 /= topo.num_cores;
2441-
average.cores.mc6_us /= topo.num_cores;
2440+
average.cores.c3 /= topo.allowed_cores;
2441+
average.cores.c6 /= topo.allowed_cores;
2442+
average.cores.c7 /= topo.allowed_cores;
2443+
average.cores.mc6_us /= topo.allowed_cores;
24422444

24432445
if (DO_BIC(BIC_Totl_c0))
2444-
average.packages.pkg_wtd_core_c0 /= topo.num_packages;
2446+
average.packages.pkg_wtd_core_c0 /= topo.allowed_packages;
24452447
if (DO_BIC(BIC_Any_c0))
2446-
average.packages.pkg_any_core_c0 /= topo.num_packages;
2448+
average.packages.pkg_any_core_c0 /= topo.allowed_packages;
24472449
if (DO_BIC(BIC_GFX_c0))
2448-
average.packages.pkg_any_gfxe_c0 /= topo.num_packages;
2450+
average.packages.pkg_any_gfxe_c0 /= topo.allowed_packages;
24492451
if (DO_BIC(BIC_CPUGFX))
2450-
average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages;
2452+
average.packages.pkg_both_core_gfxe_c0 /= topo.allowed_packages;
24512453

2452-
average.packages.pc2 /= topo.num_packages;
2454+
average.packages.pc2 /= topo.allowed_packages;
24532455
if (DO_BIC(BIC_Pkgpc3))
2454-
average.packages.pc3 /= topo.num_packages;
2456+
average.packages.pc3 /= topo.allowed_packages;
24552457
if (DO_BIC(BIC_Pkgpc6))
2456-
average.packages.pc6 /= topo.num_packages;
2458+
average.packages.pc6 /= topo.allowed_packages;
24572459
if (DO_BIC(BIC_Pkgpc7))
2458-
average.packages.pc7 /= topo.num_packages;
2460+
average.packages.pc7 /= topo.allowed_packages;
24592461

2460-
average.packages.pc8 /= topo.num_packages;
2461-
average.packages.pc9 /= topo.num_packages;
2462-
average.packages.pc10 /= topo.num_packages;
2462+
average.packages.pc8 /= topo.allowed_packages;
2463+
average.packages.pc9 /= topo.allowed_packages;
2464+
average.packages.pc10 /= topo.allowed_packages;
24632465

24642466
for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) {
24652467
if (mp->format == FORMAT_RAW)
@@ -2469,7 +2471,7 @@ void compute_average(struct thread_data *t, struct core_data *c, struct pkg_data
24692471
sums_need_wide_columns = 1;
24702472
continue;
24712473
}
2472-
average.threads.counter[i] /= topo.num_cpus;
2474+
average.threads.counter[i] /= topo.allowed_cpus;
24732475
}
24742476
for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) {
24752477
if (mp->format == FORMAT_RAW)
@@ -2478,7 +2480,7 @@ void compute_average(struct thread_data *t, struct core_data *c, struct pkg_data
24782480
if (average.cores.counter[i] > 9999999)
24792481
sums_need_wide_columns = 1;
24802482
}
2481-
average.cores.counter[i] /= topo.num_cores;
2483+
average.cores.counter[i] /= topo.allowed_cores;
24822484
}
24832485
for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) {
24842486
if (mp->format == FORMAT_RAW)
@@ -2487,7 +2489,7 @@ void compute_average(struct thread_data *t, struct core_data *c, struct pkg_data
24872489
if (average.packages.counter[i] > 9999999)
24882490
sums_need_wide_columns = 1;
24892491
}
2490-
average.packages.counter[i] /= topo.num_packages;
2492+
average.packages.counter[i] /= topo.allowed_packages;
24912493
}
24922494
}
24932495

@@ -3690,7 +3692,7 @@ void re_initialize(void)
36903692
{
36913693
free_all_buffers();
36923694
setup_all_buffers();
3693-
fprintf(outf, "turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
3695+
fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus, topo.allowed_cpus);
36943696
}
36953697

36963698
void set_max_cpu_num(void)
@@ -5953,6 +5955,24 @@ void allocate_irq_buffers(void)
59535955
err(-1, "calloc %d", topo.max_cpu_num + 1);
59545956
}
59555957

5958+
int update_topo(struct thread_data *t, struct core_data *c, struct pkg_data *p)
5959+
{
5960+
topo.allowed_cpus++;
5961+
if ((int)t->cpu_id == c->base_cpu)
5962+
topo.allowed_cores++;
5963+
if ((int)t->cpu_id == p->base_cpu)
5964+
topo.allowed_packages++;
5965+
5966+
return 0;
5967+
}
5968+
5969+
void topology_update(void)
5970+
{
5971+
topo.allowed_cpus = 0;
5972+
topo.allowed_cores = 0;
5973+
topo.allowed_packages = 0;
5974+
for_all_cpus(update_topo, ODD_COUNTERS);
5975+
}
59565976
void setup_all_buffers(void)
59575977
{
59585978
topology_probe();
@@ -5962,6 +5982,7 @@ void setup_all_buffers(void)
59625982
allocate_counters(&thread_odd, &core_odd, &package_odd);
59635983
allocate_output_buffer();
59645984
for_all_proc_cpus(initialize_counters);
5985+
topology_update();
59655986
}
59665987

59675988
void set_base_cpu(void)

0 commit comments

Comments
 (0)