]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/apic: Remove pointless fence in lapic_next_deadline()
authorThomas Gleixner <tglx@kernel.org>
Tue, 24 Feb 2026 16:36:29 +0000 (17:36 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 27 Feb 2026 15:40:07 +0000 (16:40 +0100)
lapic_next_deadline() contains a fence before the TSC read and the write to
the TSC_DEADLINE MSR with a content free and therefore useless comment:

    /* This MSR is special and need a special fence: */

The MSR is not really special. It is just not a serializing MSR, but that
does not matter at all in this context as all of these operations are
strictly CPU local.

The only thing the fence prevents is that the RDTSC is speculated ahead,
but that's not really relevant as the delta is calculated way before based
on a previous TSC read and therefore inaccurate by definition.

So removing the fence is just making it slightly more inaccurate in the
worst case, but that is irrelevant as it's way below the actual system
immanent latencies and variations.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260224163429.809059527@kernel.org
arch/x86/kernel/apic/apic.c

index d93f87f29d03b447b75ae7eb51faaad70e12f04d..18208befcf8247893f33718e7a7d393828e9c6c1 100644 (file)
@@ -412,22 +412,20 @@ EXPORT_SYMBOL_GPL(setup_APIC_eilvt);
 /*
  * Program the next event, relative to now
  */
-static int lapic_next_event(unsigned long delta,
-                           struct clock_event_device *evt)
+static int lapic_next_event(unsigned long delta, struct clock_event_device *evt)
 {
        apic_write(APIC_TMICT, delta);
        return 0;
 }
 
-static int lapic_next_deadline(unsigned long delta,
-                              struct clock_event_device *evt)
+static int lapic_next_deadline(unsigned long delta, struct clock_event_device *evt)
 {
-       u64 tsc;
-
-       /* This MSR is special and need a special fence: */
-       weak_wrmsr_fence();
+       /*
+        * There is no weak_wrmsr_fence() required here as all of this is purely
+        * CPU local. Avoid the [ml]fence overhead.
+        */
+       u64 tsc = rdtsc();
 
-       tsc = rdtsc();
        wrmsrq(MSR_IA32_TSC_DEADLINE, tsc + (((u64) delta) * TSC_DIVISOR));
        return 0;
 }