From: Peter Zijlstra <peterz@infradead.org>
To: Michael Kelley <mhklinux@outlook.com>
Cc: Thomas Gleixner <tglx@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
John Stultz <jstultz@google.com>, Stephen Boyd <sboyd@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [patch 19/48] clockevents: Provide support for clocksource coupled comparators
Date: Tue, 3 Mar 2026 20:14:02 +0100 [thread overview]
Message-ID: <20260303191402.GL1395266@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <SN6PR02MB4157675477F2598C42837FFDD47FA@SN6PR02MB4157.namprd02.prod.outlook.com>
On Tue, Mar 03, 2026 at 06:44:59PM +0000, Michael Kelley wrote:
> > +static inline bool clockevent_set_next_coupled(struct clock_event_device *dev, ktime_t expires)
> > +{
> > + u64 cycles;
> > +
> > + if (unlikely(!(dev->features & CLOCK_EVT_FEAT_CLOCKSOURCE_COUPLED)))
> > + return false;
> > +
> > + if (unlikely(!ktime_expiry_to_cycles(dev->cs_id, expires, &cycles)))
> > + return false;
> > +
> > + if (IS_ENABLED(CONFIG_GENERIC_CLOCKEVENTS_COUPLED_INLINE))
>
> Since COUPLED_INLINE is always selected for x64, there's no way to add the Hyper-V
> clockevent that is coupled but not inline. Adding the machinery to allow a second
> inline clockevent type may not be worth it, but adding a second coupled but not
> inline clockevent type on x64 should be supported. Thoughts?
>
> After fixing the u64 typo, and temporarily not always selecting COUPLED_INLINE in
> arch/x86/Kconfig, the coupled Hyper-V TSC page clocksource and timer seem to work
> correctly, though I'm still doing some testing. I'm also working on counting the number
> of time reads to confirm the expected benefit.
>
> Michael
>
> > + arch_inlined_clockevent_set_next_coupled(cycles, dev);
How about something deliciously insane like this? :-)
Then you can update the static_call to point to an asm function of your
choice that pretends to be WRMSR, while the 'native' case replaces the
CALL with CS CS CS WRMSR.
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 42447b1e1dff..5426c6fd8ec8 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1568,3 +1568,12 @@ SYM_FUNC_START(clear_bhb_loop)
SYM_FUNC_END(clear_bhb_loop)
EXPORT_SYMBOL_FOR_KVM(clear_bhb_loop)
STACK_FRAME_NON_STANDARD(clear_bhb_loop)
+
+.pushsection .text, "ax"
+SYM_CODE_START(x86_clockevent_set_next_coupled_thunk)
+ ANNOTATE_NOENDBR
+ UNWIND_HINT_FUNC
+ wrmsr
+ RET
+SYM_CODE_END(x86_clockevent_set_next_coupled_thunk)
+.popsection
diff --git a/arch/x86/include/asm/clock_inlined.h b/arch/x86/include/asm/clock_inlined.h
index b2dee8db2fb9..587f2005ef60 100644
--- a/arch/x86/include/asm/clock_inlined.h
+++ b/arch/x86/include/asm/clock_inlined.h
@@ -2,6 +2,9 @@
#ifndef _ASM_X86_CLOCK_INLINED_H
#define _ASM_X86_CLOCK_INLINED_H
+#include <linux/static_call_types.h>
+#include <asm/msr-index.h>
+#include <asm/asm.h>
#include <asm/tsc.h>
struct clocksource;
@@ -13,10 +16,18 @@ static __always_inline u64 arch_inlined_clocksource_read(struct clocksource *cs)
struct clock_event_device;
+extern void x86_clockevent_set_next_coupled_thunk(void);
+
+DECLARE_STATIC_CALL(x86_clockevent_set_next_coupled, x86_clockevent_set_next_coupled_thunk);
+
static __always_inline void
arch_inlined_clockevent_set_next_coupled(u64 cycles, struct clock_event_device *evt)
{
- native_wrmsrq(MSR_IA32_TSC_DEADLINE, cycles);
+ asm volatile("1: call " STATIC_CALL_TRAMP_STR(x86_clockevent_set_next_coupled) " \n"
+ "2:\n"
+ _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR)
+ : ASM_CALL_CONSTRAINT
+ : "c" (MSR_IA32_TSC_DEADLINE), "a" ((u32)cycles), "d" ((u32)(cycles >> 32)) : "memory");
}
#endif
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 60cab20b7901..194209f857b0 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -67,6 +67,7 @@
#include <asm/intel-family.h>
#include <asm/irq_regs.h>
#include <asm/cpu.h>
+#include <asm/clock_inlined.h>
#include "local.h"
@@ -430,6 +431,8 @@ static int lapic_next_deadline(unsigned long delta, struct clock_event_device *e
return 0;
}
+DEFINE_STATIC_CALL(x86_clockevent_set_next_coupled, x86_clockevent_set_next_coupled_thunk);
+
static int lapic_timer_shutdown(struct clock_event_device *evt)
{
unsigned int v;
diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
index 61592e41a6b1..4821d155102f 100644
--- a/arch/x86/kernel/static_call.c
+++ b/arch/x86/kernel/static_call.c
@@ -3,6 +3,7 @@
#include <linux/memory.h>
#include <linux/bug.h>
#include <asm/text-patching.h>
+#include <asm/clock_inlined.h>
enum insn_type {
CALL = 0, /* site call */
@@ -31,6 +32,11 @@ static const u8 retinsn[] = { RET_INSN_OPCODE, 0xcc, 0xcc, 0xcc, 0xcc };
*/
static const u8 warninsn[] = { 0x67, 0x48, 0x0f, 0xb9, 0x3a };
+/*
+ * cs cs cs wrmsr
+ */
+static const u8 wrmsrinsn[] = { 0x2e, 0x2e, 0x2e, 0x0f, 0x30 };
+
static u8 __is_Jcc(u8 *insn) /* Jcc.d32 */
{
u8 ret = 0;
@@ -78,6 +84,10 @@ static void __ref __static_call_transform(void *insn, enum insn_type type,
emulate = code;
code = &warninsn;
}
+ if (func == x86_clockevent_set_next_coupled_thunk) {
+ emulate = code;
+ code = &wrmsrinsn;
+ }
break;
case NOP:
next prev parent reply other threads:[~2026-03-03 19:14 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 16:35 [patch 00/48] hrtimer,sched: General optimizations and hrtick enablement Thomas Gleixner
2026-02-24 16:35 ` [patch 01/48] sched/eevdf: Fix HRTICK duration Thomas Gleixner
2026-02-28 15:37 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-03-20 14:59 ` Shrikanth Hegde
2026-03-20 15:38 ` Peter Zijlstra
2026-03-20 15:40 ` Shrikanth Hegde
2026-02-24 16:35 ` [patch 02/48] sched/fair: Simplify hrtick_update() Thomas Gleixner
2026-02-28 15:37 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra (Intel)
2026-02-24 16:35 ` [patch 03/48] sched/fair: Make hrtick resched hard Thomas Gleixner
2026-02-28 15:37 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra (Intel)
2026-02-24 16:35 ` [patch 04/48] sched: Avoid ktime_get() indirection Thomas Gleixner
2026-02-28 15:37 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:35 ` [patch 05/48] hrtimer: Avoid pointless reprogramming in __hrtimer_start_range_ns() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:35 ` [patch 06/48] hrtimer: Provide a static branch based hrtimer_hres_enabled() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:35 ` [patch 07/48] sched: Use hrtimer_highres_enabled() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:35 ` [patch 08/48] sched: Optimize hrtimer handling Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:35 ` [patch 09/48] sched/hrtick: Avoid tiny hrtick rearms Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 10/48] hrtimer: Provide LAZY_REARM mode Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:36 ` [patch 11/48] sched/hrtick: Mark hrtick timer LAZY_REARM Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:36 ` [patch 12/48] tick/sched: Avoid hrtimer_cancel/start() sequence Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 13/48] clockevents: Remove redundant CLOCK_EVT_FEAT_KTIME Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 14/48] timekeeping: Allow inlining clocksource::read() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 15/48] x86: Inline TSC reads in timekeeping Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 16/48] x86/apic: Remove pointless fence in lapic_next_deadline() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 17/48] x86/apic: Avoid the PVOPS indirection for the TSC deadline timer Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-07-10 13:25 ` [patch 17/48] " Artem Bityutskiy
2026-07-10 14:12 ` Juergen Gross
2026-02-24 16:36 ` [patch 18/48] timekeeping: Provide infrastructure for coupled clockevents Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 19/48] clockevents: Provide support for clocksource coupled comparators Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-03-03 18:44 ` [patch 19/48] " Michael Kelley
2026-03-03 19:14 ` Peter Zijlstra [this message]
2026-03-23 4:24 ` Michael Kelley
2026-03-23 21:36 ` Thomas Gleixner
2026-03-24 0:22 ` mhklkml
2026-03-24 3:37 ` Michael Kelley
2026-03-24 17:24 ` Thomas Gleixner
2026-03-24 17:34 ` Peter Zijlstra
2026-02-24 16:36 ` [patch 20/48] x86/apic: Enable TSC coupled programming mode Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-03-03 1:29 ` [patch 20/48] " Nathan Chancellor
2026-03-03 14:37 ` Thomas Gleixner
2026-03-03 14:45 ` Thomas Gleixner
2026-03-03 17:38 ` Nathan Chancellor
2026-03-03 20:21 ` Thomas Gleixner
2026-03-03 21:30 ` Nathan Chancellor
2026-03-04 18:40 ` Thomas Gleixner
2026-03-04 18:49 ` [patch 20/48] clocksource: Update clocksource::freq_khz on registration Thomas Gleixner
2026-03-04 19:10 ` Borislav Petkov
2026-03-04 22:57 ` Nathan Chancellor
2026-03-05 16:47 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-03-03 21:56 ` [PATCH] Subject: timekeeping: Initialize the coupled clocksource conversion completely Thomas Gleixner
2026-03-03 23:16 ` John Stultz
2026-03-05 16:47 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 21/48] hrtimer: Add debug object init assertion Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:36 ` [patch 22/48] hrtimer: Reduce trace noise in hrtimer_start() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 23/48] hrtimer: Use guards where appropriate Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 24/48] hrtimer: Cleanup coding style and comments Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 25/48] hrtimer: Evaluate timer expiry only once Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 26/48] hrtimer: Replace the bitfield in hrtimer_cpu_base Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 27/48] hrtimer: Convert state and properties to boolean Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 28/48] hrtimer: Optimize for local timers Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 29/48] hrtimer: Use NOHZ information for locality Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 30/48] hrtimer: Separate remove/enqueue handling for local timers Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 31/48] hrtimer: Add hrtimer_rearm tracepoint Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 32/48] hrtimer: Re-arrange hrtimer_interrupt() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:37 ` [patch 33/48] hrtimer: Rename hrtimer_cpu_base::in_hrtirq to deferred_rearm Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:37 ` [patch 34/48] hrtimer: Prepare stubs for deferred rearming Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:38 ` [patch 35/48] entry: Prepare for deferred hrtimer rearming Thomas Gleixner
2026-02-27 15:57 ` Christian Loehle
2026-02-27 16:25 ` Peter Zijlstra
2026-02-27 16:32 ` Christian Loehle
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:38 ` [patch 36/48] softirq: " Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:38 ` [patch 37/48] sched/core: " Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:38 ` [patch 38/48] hrtimer: Push reprogramming timers into the interrupt return path Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-24 16:38 ` [patch 39/48] hrtimer: Avoid re-evaluation when nothing changed Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 40/48] hrtimer: Keep track of first expiring timer per clock base Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 41/48] hrtimer: Rework next event evaluation Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 42/48] hrtimer: Simplify run_hrtimer_queues() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 43/48] hrtimer: Optimize for_each_active_base() Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 44/48] rbtree: Provide rbtree with links Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 45/48] timerqueue: Provide linked timerqueue Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:38 ` [patch 46/48] hrtimer: Use " Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:39 ` [patch 47/48] hrtimer: Try to modify timers in place Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Thomas Gleixner
2026-02-24 16:39 ` [patch 48/48] sched: Default enable HRTICK when deferred rearming is enabled Thomas Gleixner
2026-02-28 15:36 ` [tip: sched/hrtick] " tip-bot2 for Peter Zijlstra
2026-02-25 15:25 ` [patch 00/48] hrtimer,sched: General optimizations and hrtick enablement Peter Zijlstra
2026-02-25 16:02 ` Thomas Gleixner
2026-03-04 15:59 ` Christian Loehle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303191402.GL1395266@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=anna-maria@linutronix.de \
--cc=bsegall@google.com \
--cc=daniel.lezcano@linaro.org \
--cc=dietmar.eggemann@arm.com \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mhklinux@outlook.com \
--cc=rostedt@goodmis.org \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome