Re: [PATCH v6] sched/clock: Avoid false sharing for sched_clock_irqtime
From: Guo, Wangyang
Date: Tue Jan 27 2026 - 02:30:27 EST
On 1/27/2026 2:30 PM, K Prateek Nayak wrote:
Hello Wangyang,
On 1/27/2026 10:11 AM, Wangyang Guo wrote:
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -173,6 +173,7 @@ notrace static void __sched_clock_work(struct work_struct *work)
scd->tick_gtod, __gtod_offset,
scd->tick_raw, __sched_clock_offset);
+ disable_sched_clock_irqtime();
We can come here with !irqtime_enabled() but this is a slowpath so I
don't really mind calling disable_sched_clock_irqtime() unconditionally
here. Feel free to include:
Reviewed-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Tested-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Tested with a bunch of fake cases of sched_clock going unstable by
hacking the kernel and the irqtime was disabled correctly in both cases
- pre-lateinit and post-lateinit.
I think we can put irqtime_enabled check in disable_sched_lock_irqtime() which will benefit in both scenario:
void disable_sched_clock_irqtime(void)
{
- sched_clock_irqtime = 0;
+ if (irqtime_enabled())
+ static_branch_disable(&sched_clock_irqtime);
}
v7: https://lore.kernel.org/all/20260127072509.2627346-1-wangyang.guo@xxxxxxxxx/