All of lore.kernel.org
 help / color / mirror / Atom feed
* sched_clock.c change to -stable?
@ 2010-01-16  8:55 David Miller
  2010-01-16 11:36 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2010-01-16  8:55 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel


Ingo, I need commit:

commit b9f8fcd55bbdb037e5332dbdb7b494f0b70861ac
Author: David Miller <davem@davemloft.net>
Date:   Sun Dec 13 18:25:02 2009 -0800

    sched: Fix cpu_clock() in NMIs, on !CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
    
as a dependency on some sparc perf bug fixes I'd like to
submit to -stable.

Therefore, do you mind if I send this commit to -stable?

Thanks.

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

* Re: sched_clock.c change to -stable?
  2010-01-16  8:55 sched_clock.c change to -stable? David Miller
@ 2010-01-16 11:36 ` Ingo Molnar
  2010-01-18  3:02   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2010-01-16 11:36 UTC (permalink / raw)
  To: David Miller, stable kernel team; +Cc: linux-kernel


* David Miller <davem@davemloft.net> wrote:

> 
> Ingo, I need commit:
> 
> commit b9f8fcd55bbdb037e5332dbdb7b494f0b70861ac
> Author: David Miller <davem@davemloft.net>
> Date:   Sun Dec 13 18:25:02 2009 -0800
> 
>     sched: Fix cpu_clock() in NMIs, on !CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
>     
> as a dependency on some sparc perf bug fixes I'd like to
> submit to -stable.
> 
> Therefore, do you mind if I send this commit to -stable?
> 
> Thanks.

Sure!

I've attached the commit for the -stable team's convenience.

	Ingo

------------------>
>From b9f8fcd55bbdb037e5332dbdb7b494f0b70861ac Mon Sep 17 00:00:00 2001
From: David Miller <davem@davemloft.net>
Date: Sun, 13 Dec 2009 18:25:02 -0800
Subject: [PATCH] sched: Fix cpu_clock() in NMIs, on !CONFIG_HAVE_UNSTABLE_SCHED_CLOCK

Relax stable-sched-clock architectures to not save/disable/restore
hardirqs in cpu_clock().

The background is that I was trying to resolve a sparc64 perf
issue when I discovered this problem.

On sparc64 I implement pseudo NMIs by simply running the kernel
at IRQ level 14 when local_irq_disable() is called, this allows
performance counter events to still come in at IRQ level 15.

This doesn't work if any code in an NMI handler does
local_irq_save() or local_irq_disable() since the "disable" will
kick us back to cpu IRQ level 14 thus letting NMIs back in and
we recurse.

The only path which that does that in the perf event IRQ
handling path is the code supporting frequency based events.  It
uses cpu_clock().

cpu_clock() simply invokes sched_clock() with IRQs disabled.

And that's a fundamental bug all on it's own, particularly for
the HAVE_UNSTABLE_SCHED_CLOCK case.  NMIs can thus get into the
sched_clock() code interrupting the local IRQ disable code
sections of it.

Furthermore, for the not-HAVE_UNSTABLE_SCHED_CLOCK case, the IRQ
disabling done by cpu_clock() is just pure overhead and
completely unnecessary.

So the core problem is that sched_clock() is not NMI safe, but
we are invoking it from NMI contexts in the perf events code
(via cpu_clock()).

A less important issue is the overhead of IRQ disabling when it
isn't necessary in cpu_clock().

CONFIG_HAVE_UNSTABLE_SCHED_CLOCK architectures are not
affected by this patch.

Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <20091213.182502.215092085.davem@davemloft.net>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched_clock.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c
index 479ce56..5b49613 100644
--- a/kernel/sched_clock.c
+++ b/kernel/sched_clock.c
@@ -236,6 +236,18 @@ void sched_clock_idle_wakeup_event(u64 delta_ns)
 }
 EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
 
+unsigned long long cpu_clock(int cpu)
+{
+	unsigned long long clock;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	clock = sched_clock_cpu(cpu);
+	local_irq_restore(flags);
+
+	return clock;
+}
+
 #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
 
 void sched_clock_init(void)
@@ -251,17 +263,12 @@ u64 sched_clock_cpu(int cpu)
 	return sched_clock();
 }
 
-#endif /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
 
 unsigned long long cpu_clock(int cpu)
 {
-	unsigned long long clock;
-	unsigned long flags;
+	return sched_clock_cpu(cpu);
+}
 
-	local_irq_save(flags);
-	clock = sched_clock_cpu(cpu);
-	local_irq_restore(flags);
+#endif /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
 
-	return clock;
-}
 EXPORT_SYMBOL_GPL(cpu_clock);

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

* Re: sched_clock.c change to -stable?
  2010-01-16 11:36 ` Ingo Molnar
@ 2010-01-18  3:02   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2010-01-18  3:02 UTC (permalink / raw)
  To: mingo; +Cc: stable, linux-kernel

From: Ingo Molnar <mingo@elte.hu>
Date: Sat, 16 Jan 2010 12:36:47 +0100

>> Therefore, do you mind if I send this commit to -stable?
>> 
>> Thanks.
> 
> Sure!
> 
> I've attached the commit for the -stable team's convenience.

Great, I'll submit it also as part of my sparc -stable submission
to make sure they really get it :-)

Thanks!

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

end of thread, other threads:[~2010-01-18  3:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-16  8:55 sched_clock.c change to -stable? David Miller
2010-01-16 11:36 ` Ingo Molnar
2010-01-18  3:02   ` David Miller

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.