Now that all PV clocksources override the sched_clock save/restore hooks
when overriding sched_clock, WARN if the "default" TSC hooks are invoked
when using a PV sched_clock, e.g. to guard against regressions.

Reviewed-by: David Woodhouse <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
---
 arch/x86/kernel/tsc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index a762cb5cec0f..7473dcab4775 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -947,9 +947,17 @@ EXPORT_SYMBOL_FOR_MODULES(recalibrate_cpu_khz, 
"p4-clockmod,powernow-k7");
 
 static unsigned long long cyc2ns_suspend;
 
+static __always_inline bool tsc_is_save_restore_needed(void)
+{
+       if (WARN_ON_ONCE(!using_native_sched_clock()))
+               return false;
+
+       return static_branch_likely(&__use_tsc) || sched_clock_stable();
+}
+
 void tsc_save_sched_clock_state(void)
 {
-       if (!static_branch_likely(&__use_tsc) && !sched_clock_stable())
+       if (!tsc_is_save_restore_needed())
                return;
 
        cyc2ns_suspend = sched_clock();
@@ -969,7 +977,7 @@ void tsc_restore_sched_clock_state(void)
        unsigned long flags;
        int cpu;
 
-       if (!static_branch_likely(&__use_tsc) && !sched_clock_stable())
+       if (!tsc_is_save_restore_needed())
                return;
 
        local_irq_save(flags);
-- 
2.55.0.rc0.799.gd6f94ed593-goog


Reply via email to