All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: stefano.brivio@polimi.it
Cc: Nick Piggin <nickpiggin@yahoo.com.au>,
	Robert Love <rml@tech9.net>,
	linux-kernel@vger.kernel.org, Dave Jones <davej@redhat.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>, Michael Buesch <mb@bu3sch.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Len Brown <lenb@kernel.org>
Subject: Re: [PATCH] scheduler: fix x86 regression in native_sched_clock
Date: Fri, 7 Dec 2007 13:11:07 +0100	[thread overview]
Message-ID: <20071207121107.GA21049@elte.hu> (raw)
In-Reply-To: <20071207122310.maqkoxlb4gsg4ggc@webmail.polimi.it>


* stefano.brivio@polimi.it <stefano.brivio@polimi.it> wrote:

>> It's a single CPU box, so sched_clock() jumping would still be 
>> problematic, no?
>
> I guess so. Definitely, it didn't look like a printk issue. Drivers 
> don't read logs, usually. But they got confused anyway (it seems that 
> udelay's get scaled or fail or somesuch - I can't test it right now, 
> will provide more feedback in a few hours).

no, i think it's just another aspect of the broken TSC on that hardware. 
Does the patch below improve things?

	Ingo

------------------->
Subject: x86: cpu_clock() based udelay
From: Ingo Molnar <mingo@elte.hu>

use cpu_clock() for TSC based udelay - it's more reliable than raw
TSC based delay loops.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/lib/delay_32.c |   20 ++++++++++++--------
 arch/x86/lib/delay_64.c |   27 ++++++++++++++++++---------
 2 files changed, 30 insertions(+), 17 deletions(-)

Index: linux/arch/x86/lib/delay_32.c
===================================================================
--- linux.orig/arch/x86/lib/delay_32.c
+++ linux/arch/x86/lib/delay_32.c
@@ -38,17 +38,21 @@ static void delay_loop(unsigned long loo
 		:"0" (loops));
 }
 
-/* TSC based delay: */
+/* cpu_clock() [TSC] based delay: */
 static void delay_tsc(unsigned long loops)
 {
-	unsigned long bclock, now;
+	unsigned long long start, stop, now;
+	int this_cpu;
+
+	preempt_disable();
+
+	this_cpu = smp_processor_id();
+	start = now = cpu_clock(this_cpu);
+	stop = start + loops;
+
+	while ((long long)(stop - now) > 0)
+		now = cpu_clock(this_cpu);
 
-	preempt_disable();		/* TSC's are per-cpu */
-	rdtscl(bclock);
-	do {
-		rep_nop();
-		rdtscl(now);
-	} while ((now-bclock) < loops);
 	preempt_enable();
 }
 
Index: linux/arch/x86/lib/delay_64.c
===================================================================
--- linux.orig/arch/x86/lib/delay_64.c
+++ linux/arch/x86/lib/delay_64.c
@@ -26,19 +26,28 @@ int read_current_timer(unsigned long *ti
 	return 0;
 }
 
-void __delay(unsigned long loops)
+/* cpu_clock() [TSC] based delay: */
+static void delay_tsc(unsigned long loops)
 {
-	unsigned bclock, now;
+	unsigned long long start, stop, now;
+	int this_cpu;
+
+	preempt_disable();
+
+	this_cpu = smp_processor_id();
+	start = now = cpu_clock(this_cpu);
+	stop = start + loops;
+
+	while ((long long)(stop - now) > 0)
+		now = cpu_clock(this_cpu);
 
-	preempt_disable();		/* TSC's are pre-cpu */
-	rdtscl(bclock);
-	do {
-		rep_nop(); 
-		rdtscl(now);
-	}
-	while ((now-bclock) < loops);
 	preempt_enable();
 }
+
+void __delay(unsigned long loops)
+{
+	delay_tsc(loops);
+}
 EXPORT_SYMBOL(__delay);
 
 inline void __const_udelay(unsigned long xloops)

  reply	other threads:[~2007-12-07 12:12 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-07  1:19 [PATCH] scheduler: fix x86 regression in native_sched_clock Stefano Brivio
2007-12-07  5:29 ` Nick Piggin
2007-12-07  5:51 ` Thomas Gleixner
2007-12-07  7:18   ` Guillaume Chazarain
2007-12-07  8:02     ` Guillaume Chazarain
2007-12-07  8:51       ` Ingo Molnar
2007-12-07  9:29         ` Guillaume Chazarain
2007-12-07  9:59           ` Ingo Molnar
2007-12-07 13:55       ` [patch] x86: scale cyc_2_nsec according to CPU frequency Ingo Molnar
2007-12-07 14:27         ` Guillaume Chazarain
2007-12-07 14:52           ` Ingo Molnar
2007-12-08 15:57             ` Arjan van de Ven
2007-12-08 19:16               ` Ingo Molnar
2007-12-08 20:18                 ` Arjan van de Ven
2007-12-07 10:37   ` [PATCH] scheduler: fix x86 regression in native_sched_clock Andi Kleen
2007-12-07  8:45 ` Ingo Molnar
2007-12-07 10:32   ` Andrew Morton
2007-12-07 10:40     ` Ingo Molnar
2007-12-07 11:07       ` Ingo Molnar
2007-12-07 11:09       ` Andrew Morton
2007-12-07 11:12         ` Ingo Molnar
2007-12-07 11:13   ` Nick Piggin
2007-12-07 11:17     ` Ingo Molnar
2007-12-07 16:48       ` Nick Piggin
2007-12-08  0:50         ` Nick Piggin
2007-12-08  0:57           ` Nick Piggin
2007-12-08  8:52             ` Ingo Molnar
2007-12-08 23:37               ` Guillaume Chazarain
2007-12-12  4:42               ` Nick Piggin
2007-12-12 10:44                 ` Ingo Molnar
2007-12-07 11:18     ` Guillaume Chazarain
2007-12-07 11:57       ` Guillaume Chazarain
2007-12-07 11:23     ` stefano.brivio
2007-12-07 12:11       ` Ingo Molnar [this message]
2007-12-07 12:25       ` Ingo Molnar
2007-12-07 12:35         ` Ingo Molnar
2007-12-07 12:40           ` Ingo Molnar
2007-12-07 14:54             ` Ingo Molnar
2007-12-07 16:46               ` Guillaume Chazarain
2007-12-07 17:57                 ` Ingo Molnar
2007-12-08 15:06                   ` Mark Lord
2007-12-08 15:13                     ` Ingo Molnar
2007-12-08 15:27                       ` Michael Buesch
2007-12-08 15:33                         ` Ingo Molnar
2007-12-08 15:36                           ` Michael Buesch
2007-12-08 15:41                             ` Ingo Molnar
2007-12-07 11:24     ` Ingo Molnar

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=20071207121107.GA21049@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@linux-foundation.org \
    --cc=davej@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mb@bu3sch.de \
    --cc=nickpiggin@yahoo.com.au \
    --cc=rjw@sisk.pl \
    --cc=rml@tech9.net \
    --cc=stefano.brivio@polimi.it \
    --cc=tglx@linutronix.de \
    /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 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.