Re: [RFC] KVM: x86: Allow userspace exit on HLT and MWAIT, else yield on MWAIT
From: Peter Zijlstra
Date: Tue Sep 19 2023 - 05:05:17 EST
On Mon, Sep 18, 2023 at 01:59:50PM +0200, Alexander Graf wrote:
> The problem with MWAIT is that you don't really know when it's done.
This isn't really a problem. MWAIT is allowed (expected even) to return
early.
REP;NOP is a valid implementation of MWAIT.
MWAIT must not delay waking (much) after either:
- write to monitored address
- interrupt pending
But it doesn't say anything about not waking up sooner.
Now, obviously on real hardware you prefer if MWAIT were to also do the
whole C-state thing and safe your some actual power, but this is virt,
real hardware is not a concern and wakeup-timeliness also not much.
IIRC the ARM64 WFE thing has a 10khz timer or something it wakes from if
nothing else. So I suppose what I'm saying is that: nanosleep(100000)
might be a suitable MWAIT implementation.
It's virt, it sucks anyway :-)