From: Pavel Machek <pavel@ucw.cz>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-rt-users <linux-rt-users@vger.kernel.org>,
akpm@osdl.org, Ingo Molnar <mingo@elte.hu>,
Clark Williams <clark.williams@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
"Luis Claudio R. Goncalves" <lclaudio@uudg.org>,
Gregory Haskins <ghaskins@novell.com>, Andi Kleen <ak@suse.de>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] x86: enable preemption in delay
Date: Sun, 25 May 2008 20:01:23 +0200 [thread overview]
Message-ID: <20080525180122.GA4247@ucw.cz> (raw)
In-Reply-To: <alpine.LFD.1.10.0805251406260.3295@apollo.tec.linutronix.de>
Hi!
> > + if (unlikely(cpu != smp_processor_id())) {
>
> Eeek, once you migrated you do this all the time. you need to update
> cpu here.
>
> > + if ((now-bclock) >= loops)
> > + break;
>
> Also this is really dangerous with unsynchronized TSCs. You might get
> migrated and return immediately because the TSC on the other CPU is
> far ahead.
>
> What you really want is something like the patch below, but we should
> reuse the sched_clock_cpu() thingy to make that simpler. Looking into
> that right now.
> @@ -40,17 +40,51 @@ static void delay_loop(unsigned long loops)
> :"0" (loops));
> }
>
> +/*
> + * 5 usec on a 1GHZ machine. Not necessarily correct, but not too long
> + * either.
> + */
> +#define TSC_MIGRATE_COUNT 5000
> +
> /* TSC based delay: */
> static void delay_tsc(unsigned long loops)
> {
> unsigned long bclock, now;
> + int cpu;
>
> - preempt_disable(); /* TSC's are per-cpu */
> + preempt_disable();
> + cpu = smp_processor_id();
> rdtscl(bclock);
> do {
> rep_nop();
> - rdtscl(now);
> - } while ((now-bclock) < loops);
> +
> + /* Allow RT tasks to run */
> + preempt_enable();
> + preempt_disable();
> +
> + /*
> + * It is possible that we moved to another CPU, and
> + * since TSC's are per-cpu we need to calculate
> + * that. The delay must guarantee that we wait "at
> + * least" the amount of time. Being moved to another
> + * CPU could make the wait longer but we just need to
> + * make sure we waited long enough. Rebalance the
> + * counter for this CPU.
> + */
> + if (unlikely(cpu != smp_processor_id())) {
> + if (loops <= TSC_MIGRATE_COUNT)
> + break;
> + cpu = smp_processor_id();
> + rdtscl(bclock);
> + loops -= TSC_MIGRATE_COUNT;
> + } else {
> + rdtscl(now);
> + if ((now - bclock) >= loops)
> + break;
> + loops -= (now - bclock);
> + bclock = now;
What happens with different cpus running on different frequencies...?
Cpufreq?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2008-05-28 11:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-25 3:11 Steven Rostedt
2008-05-25 12:44 ` Thomas Gleixner
2008-05-25 13:07 ` Steven Rostedt
2008-05-25 13:17 ` Steven Rostedt
2008-05-25 13:19 ` Alan Cox
2008-05-25 13:40 ` Steven Rostedt
2008-05-25 20:21 ` Thomas Gleixner
2008-05-25 13:35 ` [PATCH -v2] " Steven Rostedt
2008-05-25 13:44 ` Steven Rostedt
2008-05-25 13:51 ` [PATCH -v3] " Steven Rostedt
2008-05-25 15:04 ` Steven Rostedt
2008-05-25 15:13 ` [PATCH -v4] " Steven Rostedt
2008-05-25 18:01 ` Pavel Machek [this message]
2008-05-28 13:01 ` [PATCH] " Steven Rostedt
2008-05-31 7:18 ` Pavel Machek
2008-05-25 18:53 ` Arjan van de Ven
2008-05-25 19:01 ` Thomas Gleixner
2008-05-25 19:28 ` Arjan van de Ven
2008-05-25 19:32 ` Steven Rostedt
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=20080525180122.GA4247@ucw.cz \
--to=pavel@ucw.cz \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=clark.williams@gmail.com \
--cc=ghaskins@novell.com \
--cc=lclaudio@uudg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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®