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: <CALCETrXjtZkmg1xRc8=U9i0-mqS_ftqcWuPeMYLdvONiv_fUTQ@mail.gmail.com>
Date:	Tue, 9 Jun 2015 09:46:52 -0700
From:	Andy Lutomirski <luto@...capital.net>
To:	Peter Zijlstra <peterz@...radead.org>
Cc:	Thomas Gleixner <tglx@...utronix.de>,
	John Stultz <john.stultz@...aro.org>,
	Aaron Lu <aaron.lu@...el.com>, Tony Li <tony.li@....com>,
	"Rafael J. Wysocki" <rjw@...ysocki.net>,
	Suravee Suthikulanit <suravee.suthikulpanit@....com>,
	Frédéric Weisbecker <fweisbec@...il.com>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	Borislav Petkov <bp@...e.de>,
	Fengguang Wu <fengguang.wu@...el.com>,
	Len Brown <lenb@...nel.org>, Ken Xue <ken.xue@....com>,
	Huang Rui <ray.huang@....com>, X86 ML <x86@...nel.org>
Subject: Re: [PATCH v2 3/4] x86, mwaitt: introduce mwaix delay with a
 configurable timer

On Jun 9, 2015 2:30 AM, "Peter Zijlstra" <peterz@...radead.org> 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@...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