Re: [PATCH RFC hack dont apply] intel_idle: support running within a VM

From: Jacob Pan
Date: Wed Oct 04 2017 - 13:07:11 EST


On Wed, 4 Oct 2017 05:09:09 +0300
"Michael S. Tsirkin" <mst@xxxxxxxxxx> wrote:

> On Mon, Oct 02, 2017 at 10:12:49AM -0700, Jacob Pan wrote:
> > On Sat, 30 Sep 2017 01:21:43 +0200
> > "Rafael J. Wysocki" <rafael@xxxxxxxxxx> wrote:
> >
> > > On Sat, Sep 30, 2017 at 12:01 AM, Michael S. Tsirkin
> > > <mst@xxxxxxxxxx> wrote:
> > > > intel idle driver does not DTRT when running within a VM:
> > > > when going into a deep power state, the right thing to
> > > > do is to exit to hypervisor rather than to keep polling
> > > > within guest using mwait.
> > > >
> > > > Currently the solution is just to exit to hypervisor each time
> > > > we go idle - this is why kvm does not expose the mwait leaf to
> > > > guests even when it allows guests to do mwait.
> > > >
> > > > But that's not ideal - it seems better to use the idle driver to
> > > > guess when will the next interrupt arrive.
> > >
> > > The idle driver alone is not sufficient for that, though.
> > >
> > I second that. Why try to solve this problem at vendor specific
> > driver level?
>
> Well we still want to e.g. mwait if possible - saves power.
>
> > perhaps just a pv idle driver that decide whether to vmexit
> > based on something like local per vCPU timer expiration? I guess we
> > can't predict other wake events such as interrupts.
> > e.g.
> > if (get_next_timer_interrupt() > kvm_halt_target_residency)
> > vmexit
> > else
> > poll
> >
> > Jacob
>
> It's not always a poll, on x86 putting the CPU in a low power state
> is possible within a VM.
>
Are you talking about using mwait/monitor in the user space which are
available on some Intel CPUs, such as Xeon Phi? I guess if the guest
can identify host CPU id, it is doable.

> Does not seem possible on other CPUs that's why it's vendor specific.
>

[Jacob Pan]