Skip to content

Commit 5499b5a

Browse files
committed
tools/power turbostat: Harden one-shot mode against cpu offline
when turbostat interval mode can't migrate to a CPU, it complains, prints no data, re-initializes with the new CPU configuration and starts a new interval. But this strategy in the face of a CPU hotplug offline during an interval doesn't help in one-shot mode. When the missing CPU is discovered at the end of the interval, the forked program has already returned and there is nothing left for a new interval to measure. So instead of aborting get_coutners() and delta_cpu() if a missing CPU is detected, complain, but carry on and output what statistics are actually present. Use the same strategy for delta_cpu when aperf:mperf are observed to have been reset -- complain, but carry on and print data for the CPUs that are still present. Interval mode error handling is unchanged. One-shot mode can now do this: $ sudo chcpu -e 1 ; sudo ./turbostat --quiet --show PkgWatt,Busy%,CPU chcpu -d 1 CPU 1 enabled CPU 1 disabled get_counters: Could not migrate to CPU 1 ./turbostat: Counter reset detected 0.036920 sec CPU Busy% PkgWatt - 0.00 10.00 0 99.73 10.00 1 0.00 2 91.53 3 16.83 Suggested-by: Zhang Rui <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent b32c369 commit 5499b5a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,8 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
20632063
{
20642064
int retval, pkg_no, core_no, thread_no, node_no;
20652065

2066+
retval = 0;
2067+
20662068
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
20672069
for (node_no = 0; node_no < topo.nodes_per_pkg; node_no++) {
20682070
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
@@ -2078,14 +2080,12 @@ int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pk
20782080
c = GET_CORE(core_base, core_no, node_no, pkg_no);
20792081
p = GET_PKG(pkg_base, pkg_no);
20802082

2081-
retval = func(t, c, p);
2082-
if (retval)
2083-
return retval;
2083+
retval |= func(t, c, p);
20842084
}
20852085
}
20862086
}
20872087
}
2088-
return 0;
2088+
return retval;
20892089
}
20902090

20912091
int is_cpu_first_thread_in_core(struct thread_data *t, struct core_data *c, struct pkg_data *p)
@@ -3620,12 +3620,10 @@ int delta_cpu(struct thread_data *t, struct core_data *c,
36203620

36213621
/* always calculate thread delta */
36223622
retval = delta_thread(t, t2, c2); /* c2 is core delta */
3623-
if (retval)
3624-
return retval;
36253623

36263624
/* calculate package delta only for 1st core in package */
36273625
if (is_cpu_first_core_in_package(t, c, p))
3628-
retval = delta_package(p, p2);
3626+
retval |= delta_package(p, p2);
36293627

36303628
return retval;
36313629
}
@@ -5748,6 +5746,8 @@ int for_all_cpus_2(int (func) (struct thread_data *, struct core_data *,
57485746
{
57495747
int retval, pkg_no, node_no, core_no, thread_no;
57505748

5749+
retval = 0;
5750+
57515751
for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
57525752
for (node_no = 0; node_no < topo.nodes_per_pkg; ++node_no) {
57535753
for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
@@ -5769,14 +5769,12 @@ int for_all_cpus_2(int (func) (struct thread_data *, struct core_data *,
57695769
p = GET_PKG(pkg_base, pkg_no);
57705770
p2 = GET_PKG(pkg_base2, pkg_no);
57715771

5772-
retval = func(t, c, p, t2, c2, p2);
5773-
if (retval)
5774-
return retval;
5772+
retval |= func(t, c, p, t2, c2, p2);
57755773
}
57765774
}
57775775
}
57785776
}
5779-
return 0;
5777+
return retval;
57805778
}
57815779

57825780
/*
@@ -9462,10 +9460,9 @@ int fork_it(char **argv)
94629460
timersub(&tv_odd, &tv_even, &tv_delta);
94639461
if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS))
94649462
fprintf(outf, "%s: Counter reset detected\n", progname);
9465-
else {
9466-
compute_average(EVEN_COUNTERS);
9467-
format_all_counters(EVEN_COUNTERS);
9468-
}
9463+
9464+
compute_average(EVEN_COUNTERS);
9465+
format_all_counters(EVEN_COUNTERS);
94699466

94709467
fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec / 1000000.0);
94719468

0 commit comments

Comments
 (0)