]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/aperfmperf: Make parts of the frequency invariance code unconditional
authorThomas Gleixner <tglx@linutronix.de>
Fri, 15 Apr 2022 19:19:59 +0000 (21:19 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 27 Apr 2022 18:22:19 +0000 (20:22 +0200)
The frequency invariance support is currently limited to x86/64 and SMP,
which is the vast majority of machines.

arch_scale_freq_tick() is called every tick on all CPUs and reads the APERF
and MPERF MSRs. The CPU frequency getters function do the same via dedicated
IPIs.

While it could be argued that on systems where frequency invariance support
is disabled (32bit, !SMP) the per tick read of the APERF and MPERF MSRs can
be avoided, it does not make sense to keep the extra code and the resulting
runtime issues of mass IPIs around.

As a first step split out the non frequency invariance specific
initialization code and the read MSR portion of arch_scale_freq_tick(). The
rest of the code is still conditional and guarded with a static key.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://lore.kernel.org/r/20220415161206.761988704@linutronix.de
arch/x86/include/asm/cpu.h
arch/x86/include/asm/topology.h
arch/x86/kernel/cpu/aperfmperf.c
arch/x86/kernel/smpboot.c

index 86e5e4e26fcbefc68c961d9395e163f6d840a878..e89772dc17f10e1643e6bc973d9e486c59381eff 100644 (file)
@@ -36,6 +36,8 @@ extern int _debug_hotplug_cpu(int cpu, int action);
 #endif
 #endif
 
+extern void ap_init_aperfmperf(void);
+
 int mwait_usable(const struct cpuinfo_x86 *);
 
 unsigned int x86_family(unsigned int sig);
index cc317077e73eef65dc146bfdd72b4b941185c4d5..1b2553dd3c64b691f4600ad13383231004aded7a 100644 (file)
@@ -217,13 +217,9 @@ extern void arch_scale_freq_tick(void);
 
 extern void arch_set_max_freq_ratio(bool turbo_disabled);
 extern void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled);
-extern void bp_init_freq_invariance(void);
-extern void ap_init_freq_invariance(void);
 #else
 static inline void arch_set_max_freq_ratio(bool turbo_disabled) { }
 static inline void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled) { }
-static inline void bp_init_freq_invariance(void) { }
-static inline void ap_init_freq_invariance(void) { }
 #endif
 
 #ifdef CONFIG_ACPI_CPPC_LIB
index 6220503af26a6b082e5ee554f62b2b154eedb24c..df528a4f6de33059343d70072be87052e84018cc 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/smp.h>
 #include <linux/syscore_ops.h>
 
+#include <asm/cpu.h>
 #include <asm/cpu_device_id.h>
 #include <asm/intel-family.h>
 
@@ -164,6 +165,17 @@ unsigned int arch_freq_get_on_cpu(int cpu)
        return per_cpu(samples.khz, cpu);
 }
 
+static void init_counter_refs(void)
+{
+       u64 aperf, mperf;
+
+       rdmsrl(MSR_IA32_APERF, aperf);
+       rdmsrl(MSR_IA32_MPERF, mperf);
+
+       this_cpu_write(cpu_samples.aperf, aperf);
+       this_cpu_write(cpu_samples.mperf, mperf);
+}
+
 #if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
 /*
  * APERF/MPERF frequency ratio computation.
@@ -405,17 +417,6 @@ out:
        return true;
 }
 
-static void init_counter_refs(void)
-{
-       u64 aperf, mperf;
-
-       rdmsrl(MSR_IA32_APERF, aperf);
-       rdmsrl(MSR_IA32_MPERF, mperf);
-
-       this_cpu_write(cpu_samples.aperf, aperf);
-       this_cpu_write(cpu_samples.mperf, mperf);
-}
-
 #ifdef CONFIG_PM_SLEEP
 static struct syscore_ops freq_invariance_syscore_ops = {
        .resume = init_counter_refs,
@@ -447,13 +448,8 @@ void freq_invariance_set_perf_ratio(u64 ratio, bool turbo_disabled)
        freq_invariance_enable();
 }
 
-void __init bp_init_freq_invariance(void)
+static void __init bp_init_freq_invariance(void)
 {
-       if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF))
-               return;
-
-       init_counter_refs();
-
        if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
                return;
 
@@ -461,12 +457,6 @@ void __init bp_init_freq_invariance(void)
                freq_invariance_enable();
 }
 
-void ap_init_freq_invariance(void)
-{
-       if (cpu_feature_enabled(X86_FEATURE_APERFMPERF))
-               init_counter_refs();
-}
-
 static void disable_freq_invariance_workfn(struct work_struct *work)
 {
        static_branch_disable(&arch_scale_freq_key);
@@ -481,6 +471,9 @@ static void scale_freq_tick(u64 acnt, u64 mcnt)
 {
        u64 freq_scale;
 
+       if (!arch_scale_freq_invariant())
+               return;
+
        if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))
                goto error;
 
@@ -501,13 +494,17 @@ error:
        pr_warn("Scheduler frequency invariance went wobbly, disabling!\n");
        schedule_work(&disable_freq_invariance_work);
 }
+#else
+static inline void bp_init_freq_invariance(void) { }
+static inline void scale_freq_tick(u64 acnt, u64 mcnt) { }
+#endif /* CONFIG_X86_64 && CONFIG_SMP */
 
 void arch_scale_freq_tick(void)
 {
        struct aperfmperf *s = this_cpu_ptr(&cpu_samples);
        u64 acnt, mcnt, aperf, mperf;
 
-       if (!arch_scale_freq_invariant())
+       if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF))
                return;
 
        rdmsrl(MSR_IA32_APERF, aperf);
@@ -520,4 +517,20 @@ void arch_scale_freq_tick(void)
 
        scale_freq_tick(acnt, mcnt);
 }
-#endif /* CONFIG_X86_64 && CONFIG_SMP */
+
+static int __init bp_init_aperfmperf(void)
+{
+       if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF))
+               return 0;
+
+       init_counter_refs();
+       bp_init_freq_invariance();
+       return 0;
+}
+early_initcall(bp_init_aperfmperf);
+
+void ap_init_aperfmperf(void)
+{
+       if (cpu_feature_enabled(X86_FEATURE_APERFMPERF))
+               init_counter_refs();
+}
index b1ba7ddfe930738d41b9a12df2ded903a3d87144..eb7de776a2a6659590358688f4d0cfc42c53beda 100644 (file)
@@ -186,7 +186,7 @@ static void smp_callin(void)
         */
        set_cpu_sibling_map(raw_smp_processor_id());
 
-       ap_init_freq_invariance();
+       ap_init_aperfmperf();
 
        /*
         * Get our bogomips.
@@ -1396,7 +1396,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
 {
        smp_prepare_cpus_common();
 
-       bp_init_freq_invariance();
        smp_sanity_check();
 
        switch (apic_intr_mode) {