Re: [PATCH v2 3/4] x86, mwaitt: introduce mwaix delay with a configurable timer

From: Andy Lutomirski
Date: Tue Jun 09 2015 - 12:47:35 EST


On Jun 9, 2015 2:30 AM, "Peter Zijlstra" <peterz@xxxxxxxxxxxxx> wrote:
>
> On Tue, Jun 09, 2015 at 11:13:40AM +0800, Huang Rui wrote:
> > +static void delay_mwaitx(unsigned long __loops)
> > +{
> > + u32 end, now, delay, addr;
> > +
> > + delay = __loops;
> > + rdtsc_barrier();
> > + rdtscl(end);
> > + end += delay;
> > +
> > + while (1) {
> > + __monitorx(&addr, 0, 0);
> > + mwaitx(delay, true);
> > +
> > + rdtsc_barrier();
> > + rdtscl(now);
> > + if (end <= now)
> > + break;
> > + delay = end - now;
> > + }
>
> How about you think instead and do something like:
>
> rdtsc(start);
> rdtsc_barrier();

Other way around. We really need a function static inline u64
rdtsc_with_barrier().

>
> for (;;) {
> delay = min(MWAIT_MAX_LOOPS, loops);
>
> __monitorx(&addr, 0, 0);
> mwaitx(delay, true);

I don't like this hack. The compiler is entirely within is rights to
poke addr's cacheline (i.e. the stack) between the two instructions.
I'd suggest either making the thing a full cacheline long or using a
single asm statement.

Also, "addr" is a bad name for a dummy variable that isn't an address
at all. How about "dummy"?

>
> rdtsc_barrier();
> rdtsc(end);
> rdtsc_barrier();

The second barrier is unnecessary.

>
> loops -= end - start;
> if (loops <= 0)
> break;
>
> start = end;
> }

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