All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] sched/clock: Fix local_clock() before sched_clock_init()
@ 2023-04-13 17:50 Aaron Thompson
  2023-04-14  8:24 ` Peter Zijlstra
  2023-04-22  7:43 ` [tip: sched/core] " tip-bot2 for Aaron Thompson
  0 siblings, 2 replies; 3+ messages in thread
From: Aaron Thompson @ 2023-04-13 17:50 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Daniel Bristot de Oliveira,
	Valentin Schneider, Ingo Molnar, linux-kernel, Aaron Thompson

Have local_clock() return sched_clock() if sched_clock_init() has not
yet run. sched_clock_cpu() has this check but it was not included in the
new noinstr implementation of local_clock().

The effect can be seen on x86 with CONFIG_PRINTK_TIME enabled, for
instance. scd->clock quickly reaches the value of TICK_NSEC and that
value is returned until sched_clock_init() runs.

dmesg without this patch:

    [    0.000000] kvm-clock: ...
    [    0.000002] kvm-clock: ...
    [    0.000672] clocksource: ...
    [    0.001000] tsc: ...
    [    0.001000] e820: ...
    [    0.001000] e820: ...
     ...
    [    0.001000] ..TIMER: ...
    [    0.001000] clocksource: ...
    [    0.378956] Calibrating delay loop ...
    [    0.379955] pid_max: ...

dmesg with this patch:

    [    0.000000] kvm-clock: ...
    [    0.000001] kvm-clock: ...
    [    0.000675] clocksource: ...
    [    0.002685] tsc: ...
    [    0.003331] e820: ...
    [    0.004190] e820: ...
     ...
    [    0.421939] ..TIMER: ...
    [    0.422842] clocksource: ...
    [    0.424582] Calibrating delay loop ...
    [    0.425580] pid_max: ...

Fixes: 776f22913b8e ("sched/clock: Make local_clock() noinstr")
Signed-off-by: Aaron Thompson <dev@aaront.org>
---
 kernel/sched/clock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 5732fa75ebab..b5cc2b53464d 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -300,6 +300,9 @@ noinstr u64 local_clock(void)
 	if (static_branch_likely(&__sched_clock_stable))
 		return sched_clock() + __sched_clock_offset;
 
+	if (!static_branch_likely(&sched_clock_running))
+		return sched_clock();
+
 	preempt_disable_notrace();
 	clock = sched_clock_local(this_scd());
 	preempt_enable_notrace();
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] sched/clock: Fix local_clock() before sched_clock_init()
  2023-04-13 17:50 [RESEND PATCH] sched/clock: Fix local_clock() before sched_clock_init() Aaron Thompson
@ 2023-04-14  8:24 ` Peter Zijlstra
  2023-04-22  7:43 ` [tip: sched/core] " tip-bot2 for Aaron Thompson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2023-04-14  8:24 UTC (permalink / raw)
  To: Aaron Thompson
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, Ingo Molnar,
	linux-kernel

On Thu, Apr 13, 2023 at 05:50:12PM +0000, Aaron Thompson wrote:
> Have local_clock() return sched_clock() if sched_clock_init() has not
> yet run. sched_clock_cpu() has this check but it was not included in the
> new noinstr implementation of local_clock().
> 
> The effect can be seen on x86 with CONFIG_PRINTK_TIME enabled, for
> instance. scd->clock quickly reaches the value of TICK_NSEC and that
> value is returned until sched_clock_init() runs.
> 
> dmesg without this patch:
> 
>     [    0.000000] kvm-clock: ...
>     [    0.000002] kvm-clock: ...
>     [    0.000672] clocksource: ...
>     [    0.001000] tsc: ...
>     [    0.001000] e820: ...
>     [    0.001000] e820: ...
>      ...
>     [    0.001000] ..TIMER: ...
>     [    0.001000] clocksource: ...
>     [    0.378956] Calibrating delay loop ...
>     [    0.379955] pid_max: ...
> 
> dmesg with this patch:
> 
>     [    0.000000] kvm-clock: ...
>     [    0.000001] kvm-clock: ...
>     [    0.000675] clocksource: ...
>     [    0.002685] tsc: ...
>     [    0.003331] e820: ...
>     [    0.004190] e820: ...
>      ...
>     [    0.421939] ..TIMER: ...
>     [    0.422842] clocksource: ...
>     [    0.424582] Calibrating delay loop ...
>     [    0.425580] pid_max: ...
> 
> Fixes: 776f22913b8e ("sched/clock: Make local_clock() noinstr")
> Signed-off-by: Aaron Thompson <dev@aaront.org>

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: sched/core] sched/clock: Fix local_clock() before sched_clock_init()
  2023-04-13 17:50 [RESEND PATCH] sched/clock: Fix local_clock() before sched_clock_init() Aaron Thompson
  2023-04-14  8:24 ` Peter Zijlstra
@ 2023-04-22  7:43 ` tip-bot2 for Aaron Thompson
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Aaron Thompson @ 2023-04-22  7:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Aaron Thompson, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     f31dcb152a3d0816e2f1deab4e64572336da197d
Gitweb:        https://git.kernel.org/tip/f31dcb152a3d0816e2f1deab4e64572336da197d
Author:        Aaron Thompson <dev@aaront.org>
AuthorDate:    Thu, 13 Apr 2023 17:50:12 
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 21 Apr 2023 13:24:21 +02:00

sched/clock: Fix local_clock() before sched_clock_init()

Have local_clock() return sched_clock() if sched_clock_init() has not
yet run. sched_clock_cpu() has this check but it was not included in the
new noinstr implementation of local_clock().

The effect can be seen on x86 with CONFIG_PRINTK_TIME enabled, for
instance. scd->clock quickly reaches the value of TICK_NSEC and that
value is returned until sched_clock_init() runs.

dmesg without this patch:

    [    0.000000] kvm-clock: ...
    [    0.000002] kvm-clock: ...
    [    0.000672] clocksource: ...
    [    0.001000] tsc: ...
    [    0.001000] e820: ...
    [    0.001000] e820: ...
     ...
    [    0.001000] ..TIMER: ...
    [    0.001000] clocksource: ...
    [    0.378956] Calibrating delay loop ...
    [    0.379955] pid_max: ...

dmesg with this patch:

    [    0.000000] kvm-clock: ...
    [    0.000001] kvm-clock: ...
    [    0.000675] clocksource: ...
    [    0.002685] tsc: ...
    [    0.003331] e820: ...
    [    0.004190] e820: ...
     ...
    [    0.421939] ..TIMER: ...
    [    0.422842] clocksource: ...
    [    0.424582] Calibrating delay loop ...
    [    0.425580] pid_max: ...

Fixes: 776f22913b8e ("sched/clock: Make local_clock() noinstr")
Signed-off-by: Aaron Thompson <dev@aaront.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230413175012.2201-1-dev@aaront.org
---
 kernel/sched/clock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 5732fa7..b5cc2b5 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -300,6 +300,9 @@ noinstr u64 local_clock(void)
 	if (static_branch_likely(&__sched_clock_stable))
 		return sched_clock() + __sched_clock_offset;
 
+	if (!static_branch_likely(&sched_clock_running))
+		return sched_clock();
+
 	preempt_disable_notrace();
 	clock = sched_clock_local(this_scd());
 	preempt_enable_notrace();

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-22  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 17:50 [RESEND PATCH] sched/clock: Fix local_clock() before sched_clock_init() Aaron Thompson
2023-04-14  8:24 ` Peter Zijlstra
2023-04-22  7:43 ` [tip: sched/core] " tip-bot2 for Aaron Thompson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.