lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1321398123.2352.29.camel@work-vm>
Date:	Tue, 15 Nov 2011 15:02:03 -0800
From:	john stultz <johnstul@...ibm.com>
To:	Salman Qazi <sqazi@...gle.com>
Cc:	Ingo Molnar <mingo@...e.hu>, LKML <linux-kernel@...r.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH] sched: avoid unnecessary overflow in sched_clock

On Tue, 2011-11-15 at 14:12 -0800, Salman Qazi wrote:
> (Added the missing signed-off-by line)
> 
> In hundreds of days, the __cycles_2_ns calculation in sched_clock
> has an overflow.  cyc * per_cpu(cyc2ns, cpu) exceeds 64 bits, causing
> the final value to become zero.  We can solve this without losing
> any precision.
> 
> We can decompose TSC into quotient and remainder of division by the
> scale factor, and then use this to convert TSC into nanoseconds.
> 
> Signed-off-by: Salman Qazi <sqazi@...gle.com>

Acked-by: John Stultz <johnstul@...ibm.com>


> ---
>  arch/x86/include/asm/timer.h |   23 ++++++++++++++++++++++-
>  1 files changed, 22 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h
> index fa7b917..431793e 100644
> --- a/arch/x86/include/asm/timer.h
> +++ b/arch/x86/include/asm/timer.h
> @@ -32,6 +32,22 @@ extern int no_timer_check;
>   *  (mathieu.desnoyers@...ymtl.ca)
>   *
>   *			-johnstul@...ibm.com "math is hard, lets go shopping!"
> + *
> + * In:
> + *
> + * ns = cycles * cyc2ns_scale / SC
> + *
> + * Although we may still have enough bits to store the value of ns,
> + * in some cases, we may not have enough bits to store cycles * cyc2ns_scale,
> + * leading to an incorrect result.
> + *
> + * To avoid this, we can decompose 'cycles' into quotient and remainder
> + * of division by SC.  Then,
> + *
> + * ns = (quot * SC + rem) * cyc2ns_scale / SC
> + *    = quot * cyc2ns_scale + (rem * cyc2ns_scale) / SC
> + *
> + *			- sqazi@...gle.com
>   */
> 
>  DECLARE_PER_CPU(unsigned long, cyc2ns);
> @@ -41,9 +57,14 @@ DECLARE_PER_CPU(unsigned long long, cyc2ns_offset);
> 
>  static inline unsigned long long __cycles_2_ns(unsigned long long cyc)
>  {
> +	unsigned long long quot;
> +	unsigned long long rem;
>  	int cpu = smp_processor_id();
>  	unsigned long long ns = per_cpu(cyc2ns_offset, cpu);
> -	ns += cyc * per_cpu(cyc2ns, cpu) >> CYC2NS_SCALE_FACTOR;
> +	quot = (cyc >> CYC2NS_SCALE_FACTOR);
> +	rem = cyc & ((1ULL << CYC2NS_SCALE_FACTOR) - 1);
> +	ns += quot * per_cpu(cyc2ns, cpu) +
> +		((rem * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR);
>  	return ns;
>  }
> 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ