The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Avi Kivity <avi@qumranet.com>,
	Arjan van de Ven <arjan@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	akpm@linux-foundation.org
Subject: Re: [patch] x86: make delay_tsc() preemptible again
Date: Fri, 16 Nov 2007 10:39:02 +0100	[thread overview]
Message-ID: <1195205942.3059.1.camel@twins> (raw)
In-Reply-To: <20071116084741.GA20011@elte.hu>


On Fri, 2007-11-16 at 09:47 +0100, Ingo Molnar wrote:
> * Ingo Molnar <mingo@elte.hu> wrote:
> 
> > but that should not be needed in this case. Why doesnt the TSC using 
> > delay loop simply poll the CPU it is on and fix up the TSC?
> 
> something like the patch below.
> 
> 	Ingo
> 
> --------------->
> Subject: x86: make delay_tsc() preemptible again
> From: Ingo Molnar <mingo@elte.hu>
> 
> make delay_tsc() preemptible again.
> 
> Signed-off-by: Ingo Molnar <mingo@elte.hu>
> ---
>  arch/x86/lib/delay_32.c |   28 +++++++++++++++++++++++-----
>  arch/x86/lib/delay_64.c |   30 ++++++++++++++++++++++++------
>  2 files changed, 47 insertions(+), 11 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,35 @@ static void delay_loop(unsigned long loo
>  		:"0" (loops));
>  }
>  
> -/* TSC based delay: */
> +/*
> + * TSC based delay:
> + *
> + * We are careful about preemption as TSC's are per-CPU.
> + */
>  static void delay_tsc(unsigned long loops)
>  {
> -	unsigned long bclock, now;
> +	unsigned long prev, now;
> +	long left = loops;
> +	int prev_cpu, cpu;
>  
> -	preempt_disable();		/* TSC's are per-cpu */
> -	rdtscl(bclock);
> +	preempt_disable();
> +	rdtscl(prev);
>  	do {
> +		prev_cpu = smp_processor_id();
>  		rep_nop();
> +		preempt_enable();

Why not have the rep_nop() here between the enable, and disable ?

> +
> +		preempt_disable();
> +		cpu = smp_processor_id();
>  		rdtscl(now);
> -	} while ((now-bclock) < loops);
> +		/*
> +		 * If we preempted we skip this small amount of time:
                           ^ migrated, perhaps?

> +		 */
> +		if (prev_cpu != cpu)
> +			prev = now;
> +		left -= now - prev;
> +		prev = now;
> +	} while (left > 0);
>  	preempt_enable();
>  }


Otherwise, looks like a very nice patch :-)



  reply	other threads:[~2007-11-16  9:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200711150400.lAF40lIr020160@hera.kernel.org>
2007-11-16  3:41 ` x86: disable preemption in delay_tsc() Arjan van de Ven
2007-11-16  3:52   ` Andrew Morton
2007-11-16  6:13     ` Ingo Molnar
2007-11-16  7:08       ` Andrew Morton
2007-11-16  7:17         ` Ingo Molnar
2007-11-16  7:26           ` Andrew Morton
2007-11-16  8:08   ` Avi Kivity
2007-11-16  8:36     ` Ingo Molnar
2007-11-16  8:47       ` [patch] x86: make delay_tsc() preemptible again Ingo Molnar
2007-11-16  9:39         ` Peter Zijlstra [this message]
2007-11-16 10:50           ` 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=1195205942.3059.1.camel@twins \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=avi@qumranet.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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