Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupower: mperf monitor: fix output in MAX_FREQ_SYSFS mode

There is clearly wrong output when mperf monitor runs in MAX_FREQ_SYSFS mode:
average frequency shows in kHz unit (despite the intended output to be in MHz),
and percentages for C state information are all wrong (including high/negative
values shown).

The problem is that the max_frequency read on initialization isn't used where it
should have been used on mperf_get_count_percent (to estimate the number of
ticks in the given time period), and the value we read from sysfs is in kHz, so
we must divide it to get the MHz value to use in current calculations.

While at it, also I fixed another small issues in the debug output of
max_frequency value in mperf_get_count_freq.

Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Acked-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Herton R. Krzesinski and committed by
Rafael J. Wysocki
47b98c74 ba155e2d

+3 -2
+3 -2
tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
··· 135 135 dprint("%s: TSC Ref - mperf_diff: %llu, tsc_diff: %llu\n", 136 136 mperf_cstates[id].name, mperf_diff, tsc_diff); 137 137 } else if (max_freq_mode == MAX_FREQ_SYSFS) { 138 - timediff = timespec_diff_us(time_start, time_end); 138 + timediff = max_frequency * timespec_diff_us(time_start, time_end); 139 139 *percent = 100.0 * mperf_diff / timediff; 140 140 dprint("%s: MAXFREQ - mperf_diff: %llu, time_diff: %llu\n", 141 141 mperf_cstates[id].name, mperf_diff, timediff); ··· 176 176 dprint("%s: Average freq based on %s maximum frequency:\n", 177 177 mperf_cstates[id].name, 178 178 (max_freq_mode == MAX_FREQ_TSC_REF) ? "TSC calculated" : "sysfs read"); 179 - dprint("%max_frequency: %lu", max_frequency); 179 + dprint("max_frequency: %lu\n", max_frequency); 180 180 dprint("aperf_diff: %llu\n", aperf_diff); 181 181 dprint("mperf_diff: %llu\n", mperf_diff); 182 182 dprint("avg freq: %llu\n", *count); ··· 279 279 return -1; 280 280 } 281 281 max_freq_mode = MAX_FREQ_SYSFS; 282 + max_frequency /= 1000; /* Default automatically to MHz value */ 282 283 return 0; 283 284 } 284 285