Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1539114
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math |
| Date | 2016-12-09 06:50 +0100 |
| Message-ID | <sMmed-7Op-17@gated-at.bofh.it> (permalink) |
| References | <sMdXk-2rQ-13@gated-at.bofh.it> <sMdXl-2rQ-43@gated-at.bofh.it> <sMkFr-6X5-1@gated-at.bofh.it> <sMli9-7cd-19@gated-at.bofh.it> <sMlUR-7HU-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Dec 09, 2016 at 06:22:03AM +0100, Ingo Molnar wrote:
>
> * Peter Zijlstra <peterz@infradead.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.
Yeah, that's the full 64x64->128 mult on 3bit. Luckily we only need
64x32->96, which reduces to 2 32x32->64 mults.
But my point was that unconditionally using __int128 might not be the
right thing.
> 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?
Yeah, the fact that we only need the 2 mults and that the fallback
already does the second multiply conditionally :-) But then look at the
email where I said that that condition actually makes the thing vastly
more expensive on some archs (like tilegx).
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[patch 0/6] timekeeping: Cure the signed/unsigned wreckage Thomas Gleixner <tglx@linutronix.de> - 2016-12-08 22:00 +0100
[patch 5/6] [RFD] timekeeping: Provide optional 128bit math Thomas Gleixner <tglx@linutronix.de> - 2016-12-08 22:00 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Ingo Molnar <mingo@kernel.org> - 2016-12-09 05:10 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Ingo Molnar <mingo@kernel.org> - 2016-12-09 05:30 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math John Stultz <john.stultz@linaro.org> - 2016-12-09 05:50 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 05:50 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Ingo Molnar <mingo@kernel.org> - 2016-12-09 06:30 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 06:50 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 06:20 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 07:10 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 06:30 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 07:40 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 09:40 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 10:20 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 11:10 +0100
Re: [patch 5/6] [RFD] timekeeping: Provide optional 128bit math Peter Zijlstra <peterz@infradead.org> - 2016-12-09 11:20 +0100
[patch 3/6] timekeeping: Get rid of pointless typecasts Thomas Gleixner <tglx@linutronix.de> - 2016-12-08 22:00 +0100
Re: [patch 3/6] timekeeping: Get rid of pointless typecasts David Gibson <david@gibson.dropbear.id.au> - 2016-12-09 00:50 +0100
[tip:timers/core] timekeeping: Get rid of pointless typecasts tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2016-12-09 12:20 +0100
Re: [patch 0/6] timekeeping: Cure the signed/unsigned wreckage John Stultz <john.stultz@linaro.org> - 2016-12-09 06:00 +0100
Re: [patch 0/6] timekeeping: Cure the signed/unsigned wreckage Peter Zijlstra <peterz@infradead.org> - 2016-12-09 06:40 +0100
csiph-web