Skip to content

Commit fb4c77c

Browse files
committed
x86/aperfmperf: Integrate the fallback code from show_cpuinfo()
Due to the avoidance of IPIs to idle CPUs arch_freq_get_on_cpu() can return 0 when the last sample was too long ago. show_cpuinfo() has a fallback to cpufreq_quick_get() and if that fails to return cpu_khz, but the readout code for the per CPU scaling frequency in sysfs does not. Move that fallback into arch_freq_get_on_cpu() so the behaviour is the same when reading /proc/cpuinfo and /sys/..../cur_scaling_freq. Suggested-by: "Rafael J. Wysocki" <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Doug Smythies <[email protected]> Link: https://lore.kernel.org/r/87pml5180p.ffs@tglx
1 parent f3eca38 commit fb4c77c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

arch/x86/kernel/cpu/aperfmperf.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,12 @@ void arch_scale_freq_tick(void)
405405
unsigned int arch_freq_get_on_cpu(int cpu)
406406
{
407407
struct aperfmperf *s = per_cpu_ptr(&cpu_samples, cpu);
408+
unsigned int seq, freq;
408409
unsigned long last;
409-
unsigned int seq;
410410
u64 acnt, mcnt;
411411

412412
if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF))
413-
return 0;
413+
goto fallback;
414414

415415
do {
416416
seq = raw_read_seqcount_begin(&s->seq);
@@ -424,9 +424,13 @@ unsigned int arch_freq_get_on_cpu(int cpu)
424424
* which covers idle and NOHZ full CPUs.
425425
*/
426426
if (!mcnt || (jiffies - last) > MAX_SAMPLE_AGE)
427-
return 0;
427+
goto fallback;
428428

429429
return div64_u64((cpu_khz * acnt), mcnt);
430+
431+
fallback:
432+
freq = cpufreq_quick_get(cpu);
433+
return freq ? freq : cpu_khz;
430434
}
431435

432436
static int __init bp_init_aperfmperf(void)

arch/x86/kernel/cpu/proc.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
8686
if (cpu_has(c, X86_FEATURE_TSC)) {
8787
unsigned int freq = arch_freq_get_on_cpu(cpu);
8888

89-
if (!freq)
90-
freq = cpufreq_quick_get(cpu);
91-
if (!freq)
92-
freq = cpu_khz;
93-
seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
94-
freq / 1000, (freq % 1000));
89+
seq_printf(m, "cpu MHz\t\t: %u.%03u\n", freq / 1000, (freq % 1000));
9590
}
9691

9792
/* Cache size */

0 commit comments

Comments
 (0)