Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1598922

Re: [PATCH] kvm: better MWAIT emulation for guests

From Wanpeng Li <kernellwp@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] kvm: better MWAIT emulation for guests
Date 2017-03-13 08:50 +0100
Message-ID <tksTT-5Fi-5@gated-at.bofh.it> (permalink)
References <tjeSZ-32y-13@gated-at.bofh.it> <tjh4u-4qP-29@gated-at.bofh.it> <tjhnP-4Ms-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Cc Peterz,
2017-03-10 9:12 GMT+08:00 Michael S. Tsirkin <mst@redhat.com>:
> On Thu, Mar 09, 2017 at 07:51:27PM -0500, Gabriel L. Somlo wrote:
>> On Fri, Mar 10, 2017 at 12:29:31AM +0200, Michael S. Tsirkin wrote:
>> > Some guests call mwait without checking the cpu flags.  We currently
>> > emulate that as a NOP but on VMX we can do better: let guest stop the
>> > CPU until timer or IPI.  CPU will be busy but that isn't any worse than
>> > a NOP emulation.
>>
>> Are you getting an IPI if another VCPU writes to the MONITOR-ed memory
>> location?
>
> In my testing yes.

Why there is still an IPI if monitor/mwait is used in guest?

>
>> If not, you'd be waking up too late and fail to meet the
>> specified behavior of the MONITOR/MWAIT instruction pair.
>>
>> > Note that mwait within guests is not the same as on real hardware
>> > because you must halt if you want to go deep into sleep.  Thus it isn't
>> > a good idea to use the regular MWAIT flag in CPUID for that.  Add a flag
>> > in the hypervisor leaf instead.
>>
>> Is it a good idea to advertise MWAIT capability to guests?
>
> I think it isn't so this patch does not do it.
>
>> The
>> misbehaving ones will call it willy-nilly, true, but aren't compliant
>> ones better off falling back to some alternative method (typically
>> using a HLT-based idle loop instead of a MONITOR/MWAIT based one) ?
>>
>> Thanks,
>> --Gabriel
>>

[...]

>> > @@ -594,6 +594,9 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
>> >             if (sched_info_on())
>> >                     entry->eax |= (1 << KVM_FEATURE_STEAL_TIME);
>> >
>> > +           if (this_cpu_has(X86_FEATURE_MWAIT))
>> > +                   entry->eax = (1 << KVM_FEATURE_MWAIT);

s/"="/"|=", otherwise you almost kill other features.

Regards,
Wanpeng Li

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] kvm: better MWAIT emulation for guests "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-09 23:40 +0100
  Re: [PATCH] kvm: better MWAIT emulation for guests "Gabriel L. Somlo" <gsomlo@gmail.com> - 2017-03-10 02:00 +0100
    Re: [PATCH] kvm: better MWAIT emulation for guests "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-10 02:20 +0100
      Re: [PATCH] kvm: better MWAIT emulation for guests Wanpeng Li <kernellwp@gmail.com> - 2017-03-13 08:50 +0100
  Re: [PATCH] kvm: better MWAIT emulation for guests Jim Mattson <jmattson@google.com> - 2017-03-11 00:50 +0100
    Re: [PATCH] kvm: better MWAIT emulation for guests "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-12 01:10 +0100
      Re: [PATCH] kvm: better MWAIT emulation for guests "Gabriel L. Somlo" <gsomlo@gmail.com> - 2017-03-12 22:20 +0100
  Re: [PATCH] kvm: better MWAIT emulation for guests Radim Krčmář <rkrcmar@redhat.com> - 2017-03-13 16:50 +0100
    Re: [PATCH] kvm: better MWAIT emulation for guests "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-13 17:10 +0100
      Re: [PATCH] kvm: better MWAIT emulation for guests Radim Krčmář <rkrcmar@redhat.com> - 2017-03-13 20:40 +0100
        Re: [PATCH] kvm: better MWAIT emulation for guests "Michael S. Tsirkin" <mst@redhat.com> - 2017-03-13 21:10 +0100
          Re: [PATCH] kvm: better MWAIT emulation for guests Radim Krčmář <rkrcmar@redhat.com> - 2017-03-13 22:50 +0100

csiph-web