public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Prarit Bhargava <prarit@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	John Stultz <john.stultz@linaro.org>, Dave Hansen <dave@sr71.net>,
	x86@kernel.org
Subject: Re: [PATCH] x86, tsc add an initial read offset to __cycles_2_ns() calculations
Date: Fri, 26 Jul 2013 11:12:45 +0200	[thread overview]
Message-ID: <20130726091245.GF27075@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1374681800-7237-1-git-send-email-prarit@redhat.com>

On Wed, Jul 24, 2013 at 12:03:20PM -0400, Prarit Bhargava wrote:
> 
> The TSC can have non-zero values at boot time on Intel Xeon E5 (family 6,
> model 45) aka "SandyBridge" processors.  This is documented in the Errata
> for the E5 processors as BT81.
> 
> The __cycles_2_ns() calculation is known to overflow if a large value of
> cycles is passed into the function.  This is done by design to improve
> precision for smaller significant digits in the calculation.  Since the E5
> processor can pass in a large value,  we need to snapshot the TSC's
> initial value to avoid calculation overflows in the conversions of cycles
> to nanoseconds.
> 
> Tested successfully on various Sandybridge systems as well as a few older
> and newer systems without any issues.
> 
> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Dave Hansen <dave@sr71.net>
> Cc: x86@kernel.org
> ---
>  arch/x86/include/asm/timer.h |   15 +++------------
>  arch/x86/kernel/tsc.c        |   13 +++++++++++++
>  2 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h
> index 34baa0e..f9d666b 100644
> --- a/arch/x86/include/asm/timer.h
> +++ b/arch/x86/include/asm/timer.h
> @@ -12,6 +12,8 @@ extern int recalibrate_cpu_khz(void);
>  
>  extern int no_timer_check;
>  
> +extern unsigned long long tsc_initial_value;
> +
>  /* Accelerators for sched_clock()
>   * convert from cycles(64bits) => nanoseconds (64bits)
>   *  basic equation:
> @@ -59,21 +61,10 @@ static inline unsigned long long __cycles_2_ns(unsigned long long cyc)
>  {
>  	int cpu = smp_processor_id();
>  	unsigned long long ns = per_cpu(cyc2ns_offset, cpu);
> +	cyc -= tsc_initial_value;
>  	ns += mult_frac(cyc, per_cpu(cyc2ns, cpu),
>  			(1UL << CYC2NS_SCALE_FACTOR));
>  	return ns;
>  }

Hurm.. but eventually the TSC value _will_ get that large again, right?
So shouldn't we fix the actual problem?


  reply	other threads:[~2013-07-26  9:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-24 16:03 [PATCH] x86, tsc add an initial read offset to __cycles_2_ns() calculations Prarit Bhargava
2013-07-26  9:12 ` Peter Zijlstra [this message]
2013-07-26 10:26 ` Borislav Petkov

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=20130726091245.GF27075@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dave@sr71.net \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prarit@redhat.com \
    --cc=x86@kernel.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