Re: [PATCH] sched/clock: Avoid false sharing for sched_clock_irqtime
From: Guo, Wangyang
Date: Tue Jan 13 2026 - 02:54:48 EST
On 1/13/2026 12:26 PM, K Prateek Nayak wrote:
Hello Wangyang,
On 1/13/2026 8:36 AM, Wangyang Guo wrote:
Read-mostly sched_clock_irqtime may share the same cacheline with
frequently updated nohz struct. Make it as cache aligned to avoid
false sharing issue.
nit.
Since you mention this is a "Read-mostly" data ...
[..snip..]
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 7097de2c8cda..34d15972f5fb 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -25,7 +25,7 @@
*/
DEFINE_PER_CPU(struct irqtime, cpu_irqtime);
-int sched_clock_irqtime;
+int sched_clock_irqtime __cacheline_aligned;
Have you tried annotating it with "__ro_after_init" or "__read_mostly"?
That should also ensure "sched_clock_irqtime" doesn't have false-sharing
with the nohz struct without using an entire cacheline worth of space.
__read_mostly works and avoids wasting spaces. It's better than __cacheline_aligned, patch v2 is sent out as:
https://lore.kernel.org/all/20260113074807.3404180-1-wangyang.guo@xxxxxxxxx/
BR
Wangyang