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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161209052203.GA32246@gmail.com>
Date:   Fri, 9 Dec 2016 06:22:03 +0100
From:   Ingo Molnar <mingo@...nel.org>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Thomas Gleixner <tglx@...utronix.de>,
        LKML <linux-kernel@...r.kernel.org>,
        John Stultz <john.stultz@...aro.org>,
        David Gibson <david@...son.dropbear.id.au>,
        Liav Rehana <liavr@...lanox.com>,
        Chris Metcalf <cmetcalf@...lanox.com>,
        Richard Cochran <richardcochran@...il.com>,
        Parit Bhargava <prarit@...hat.com>,
        Laurent Vivier <lvivier@...hat.com>,
        "Christopher S. Hall" <christopher.s.hall@...el.com>
Subject: Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math


* Peter Zijlstra <peterz@...radead.org> wrote:

> On Fri, Dec 09, 2016 at 05:08:26AM +0100, Ingo Molnar wrote:
> > > +#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
> > > +static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr, u64 delta)
> > > +{
> > > +	unsigned __int128 nsec;
> > > +
> > > +	nsec = ((unsigned __int128)delta * tkr->mult) + tkr->xtime_nsec;
> > > +	return (u64) (nsec >> tkr->shift);
> > > +}
> > 
> > Actually, 128-bit multiplication shouldn't be too horrible - at least on 64-bit 
> > architectures. (128-bit division is another matter, but there's no division here.)
> 
> IIRC there are 64bit architectures that do not have a 64x64->128 mult,
> only a 64x64->64 mult instruction. Its not immediately apparent using
> __int128 will generate optimal code for those, nor is it a given GCC
> will not require libgcc functions for those.

Well, if the overflow case is rare (which it is in this case) then it should still 
be relatively straightforward, something like:

        X and Y are 64-bit:

	X = Xh*2^32 + Xl
	Y = Yh*2^32 + Yl

	X*Y = (Xh*2^32 + Xl)*(Yh*2^32 + Yl)

	    =   Xh*2^32*(Yh*2^32 + Yl)
	      +      Xl*(Yh*2^32 + Yl)

	    =   Xh*Yh*2^64
	      + Xh*Yl*2^32
	      + Xl*Yh*2^32
	      + XL*Yl

Which is four 32x32->64 multiplications in the worst case.

Where a valid overflow threshold is relatively easy to determine in a hot path 
compatible fashion:

	if (Xh != 0 || Yh != 0)
		slow_path();

And this simple and fast overflow check should still cover the overwhelming 
majority of 'sane' systems. (A more involved 'could it overflow' check of counting 
the high bits with 8 bit granularity by looking at the high bytes not at the words 
could be done in the slow path - to still avoid the 4 multiplications in most 
cases.)

Am I missing something?

Thanks,

	Ingo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ