From: "Guo, Wangyang" <wangyang.guo@intel.com>
To: Shrikanth Hegde <sshegde@linux.ibm.com>,
K Prateek Nayak <kprateek.nayak@amd.com>
Cc: linux-kernel@vger.kernel.org,
Benjamin Lei <benjamin.lei@intel.com>,
Tim Chen <tim.c.chen@linux.intel.com>,
Tianyou Li <tianyou.li@intel.com>, Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.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>
Subject: Re: [PATCH v7] sched/clock: Avoid false sharing for sched_clock_irqtime
Date: Wed, 28 Jan 2026 10:19:21 +0800 [thread overview]
Message-ID: <3b69443c-f82c-4b73-8384-2a039d730213@intel.com> (raw)
In-Reply-To: <7c6236a5-82b7-4d1b-9bb2-3f0d2ac186f8@linux.ibm.com>
On 1/27/2026 7:04 PM, Shrikanth Hegde wrote:
> Hi Wangyang, Prateek.
>
> On 1/27/26 12:55 PM, Wangyang Guo wrote:
>> Read-mostly sched_clock_irqtime may share the same cacheline with
>> frequently updated nohz struct. Make it as static_key to avoid
>> false sharing issue.
>>
>> The only user of disable_sched_clock_irqtime()
>> is tsc_.*mark_unstable() which may be invoked under atomic context
>> and require a workqueue to disable static_key. But both of them
>> calls clear_sched_clock_stable() just before doing
>> disable_sched_clock_irqtime(). We can reuse
>> "sched_clock_work" to also disable sched_clock_irqtime().
>>
>> One additional case need to handle is if the tsc is marked unstable
>> before late_initcall() phase, sched_clock_work will not be invoked
>> and sched_clock_irqtime will stay enabled although clock is unstable:
>> tsc_init()
>> enable_sched_clock_irqtime() # irqtime accounting is enabled here
>> ...
>> if (unsynchronized_tsc()) # true
>> mark_tsc_unstable()
>> clear_sched_clock_stable()
>> __sched_clock_stable_early = 0;
>> ...
>> if (static_key_count(&sched_clock_running.key) == 2)
>> # Only happens at sched_clock_init_late()
>> __clear_sched_clock_stable(); # Never executed
>> ...
>>
>> # late_initcall() phase
>> sched_clock_init_late()
>> if (__sched_clock_stable_early) # Already false
>> __set_sched_clock_stable(); # sched_clock is never marked stable
>> # TSC unstable, but sched_clock_work won't run to disable irqtime
>>
>> So we need to disable_sched_clock_irqtime() in sched_clock_init_late()
>> if clock is unstable.
>>
>
> Do you this as a valid case? have you tested with CONFIG_PARAVIRT?
>
> Lets say you have a non native sched clock such as kvm_sched_clock_read.
> tsc_init -> sets enable_sched_clock_irqtime()
> ->mark_tsc_unstable -> if using_native_sched_clock ->
> clear_sched_clock_stable
>
> In this case, since clear_sched_clock_stable won't be called you may not
> disable the
> sched clock irqtime since __sched_clock_stable_early is reset only in
> clear_sched_clock_stable
For hypervisor, I see this path may call clear_sched_clock_stable when
clock is unstable at init:
kvm_init_platform() ->
kvmclock_init() -> kvm_sched_clock_init(stable):
if (!stable) clear_sched_clock_stable()
paravirt_set_sched_clock(kvm_sched_clock_read)
>
> Bigger concern(maybe) is clock source marked as stable still, though
> called mark_tsc_unstable in
> non native sched clock?
>
> Disclaimer: (just curious, seeing this x86 code for first time, so may
> not know all paths)
>
Yes, when clock mark unstable through tsc_.*mark_unstable() with
non-native_sched_clock, clear_sched_clock_stable won't be called, thus
sched_clock_irqtime still keep enabled.
Maybe the dedicated workqueue for sched_clock_irqtime is still needed
considering this case.
next prev parent reply other threads:[~2026-01-28 2:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 7:25 Wangyang Guo
2026-01-27 11:04 ` Shrikanth Hegde
2026-01-28 2:19 ` Guo, Wangyang [this message]
2026-01-28 3:05 ` K Prateek Nayak
2026-01-28 6:26 ` Shrikanth Hegde
2026-01-28 7:18 ` K Prateek Nayak
2026-01-28 7:32 ` Shrikanth Hegde
2026-01-28 7:50 ` K Prateek Nayak
2026-01-28 7:56 ` Shrikanth Hegde
2026-02-03 9:55 ` Vincent Guittot
2026-02-03 11:18 ` [tip: sched/core] " tip-bot2 for Wangyang Guo
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=3b69443c-f82c-4b73-8384-2a039d730213@intel.com \
--to=wangyang.guo@intel.com \
--cc=benjamin.lei@intel.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sshegde@linux.ibm.com \
--cc=tianyou.li@intel.com \
--cc=tim.c.chen@linux.intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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
all inboxes | Powered by JetHome®