Re: [RFC PATCH 2/4] x86, mwaitt: introduce mwaitx idle with a configurable timer

From: Andy Lutomirski
Date: Thu May 21 2015 - 12:45:38 EST


On Thu, May 21, 2015 at 9:02 AM, Borislav Petkov <bp@xxxxxxx> wrote:
> On Thu, May 21, 2015 at 10:56:32PM +0800, Huang Rui wrote:
>> Looks like good use case. Boris, could we try to implement it?
>
> Andy had some suggestions on how to do it here:
>
> https://lkml.kernel.org/r/555D3629.8080002@xxxxxxxxxx
>
> which should be doable. Also, you'd probably need to set ECX[0]=0b too,
> so that MWAITX doesn't get woken up by interrupts while MWAIT-ing with
> interrupts disabled. I.e., this sequence:
>
> cli
> rdtsc
> shove the computed timeout into ebx
> mov $2,%ecx # this enables the timer and disables IRQs while MWAITing
> mwaitx
> sti

I must be missing something. In this sequence, you're sleeping with
IF=0 and ECX[0] = 0, so an IRQ won't get handled. Don't we want
ECX[0] = 1?

>
> The NMI argument is a problem though - if and NMI gets you out of
> MWAITX, a simple perf tool workload would kill all MWAITX executions.
> Which is bad. :-\

I'm not sure it's a show-stopper. NMI handlers are meant to be fast.
If an NMI comes in between rdtsc and mwaitx, then we oversleep, but by
at most the time it takes to handle an NMI, and nothing would have
stopped us from oversleeping that long if an NMI came in right after
mwaitx returned.

--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/