All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	kvm@vger.kernel.org
Subject: Re: [PATCH] i386: Allow monitor / mwait cpuid override
Date: Mon, 27 Mar 2017 18:42:49 +0200	[thread overview]
Message-ID: <164e6c5d-ca36-b92d-2831-468a54cd3efe@suse.de> (raw)
In-Reply-To: <20170327163333.GL28530@thinpad.lan.raisama.net>



On 27/03/2017 18:33, Eduardo Habkost wrote:
> On Mon, Mar 27, 2017 at 06:10:43PM +0200, Alexander Graf wrote:
>>
>>
>> On 27/03/2017 17:46, Eduardo Habkost wrote:
>>> On Mon, Mar 27, 2017 at 04:26:50PM +0200, Alexander Graf wrote:
>>>> KVM allows trap and emulate (read: NOP) of the MONITOR and MWAIT
>>>> instructions. There is work undergoing to enable actual execution
>>>> of these inside of KVM, but nobody really wants to expose the feature
>>>> to the guest by default, as it would eat up all of the host CPU.
>>>
>>> Isn't this something that should be reported using
>>> KVM_GET_EMULATED_CPUID? (QEMU still doesn't know how to use
>>> KVM_GET_EMULATED_CPUID, however.)
>>
>> Depends how you look at it. In KVM land there are basically 3 ways to deal
>> with MONITOR/MWAIT:
>>
>>   1) #VMEXIT on every execution, treat them as NOP
>>   2) let the guest natively execute them (looks like a busy loop for the
>> host, but saves power)
>>   3) be smart in KVM about it, add actual emulation and adaptively allow for
>> native mwait execution or emulated mwait which means we can run inside host
>> context
>
> Which case is going to be enabled when using your patch? Don't
> you want to make that configurable?
>
> This looks like configuration that can't be easily represented
> using the GET_SUPPORTED_CPUID/KVM_SET_CPUID abstraction, as the
> ability to enable the feature can't be represented by a single
> bit.
>
> We already have a few cases where we make
> kvm_arch_get_supported_cpuid() look at something other than just
> GET_SUPPORTED_CPUID return values (most cases are related to
> in-kernel irqchip). We can change kvm_arch_get_supported_cpuid()
> to look at other flags (like one that would configure mwait
> behavior), and decide to report CPUID_EXT_MONITOR on those cases.
>
> Would something like the following make sense?
>
> * Having a "mwait=(none|nop|native|smart)" option, to choose
>   mwait behavior
> * Making kvm_arch_get_supported_cpuid() return CPUID_EXT_MONITOR
>   as supported only if the "mwait" option is not "none".
>
> Then:
> * "-cpu ...,monitor=on" would fail, because mwait=none would be
>   the default
> * "-cpu ...,mwait=none,monitor=on" would fail
> * "-cpu ...,mwait=(nop|native|smart)" would fail if
>   host KVM doesn't report the corresponding mwait behavior as
>   supported
> * "-cpu ...,mwait=(nop|native|smart),monitor=on" would work
> * "-cpu ...,mwait=(nop|native|smart)" would also work, and
>   probably should enable CPUID_EXT_MONITOR flag by default
>
> We could still implement "monitor=force" for debugging, but I
> think we need something safer than "just ignore what KVM is
> telling us" for production.

I personally think we want the =force for any cpuid bit that we want to 
randomly poke into the expose CPUID bitmap and if a customer is daring 
enough, leave that to him as an option.

For anything else, I wouldn't overengineer this interface. I think 
eventually we want to just natively support emulated mwait with proper 
adaptive logic on when to trap vs execute mwait inside the guest (as 
mentioned in the kvm thread on this). Once that's implemented, KVM can 
just expose the MONITOR bit as supported and everyone gets it automatically.

If at that point, the adaptive interface performs much worse than the 
naive one, we can still think about pushing this into an enable_cap and 
add a specific mwait= option.


Alex

WARNING: multiple messages have this Message-ID (diff)
From: Alexander Graf <agraf@suse.de>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH] i386: Allow monitor / mwait cpuid override
Date: Mon, 27 Mar 2017 18:42:49 +0200	[thread overview]
Message-ID: <164e6c5d-ca36-b92d-2831-468a54cd3efe@suse.de> (raw)
In-Reply-To: <20170327163333.GL28530@thinpad.lan.raisama.net>



On 27/03/2017 18:33, Eduardo Habkost wrote:
> On Mon, Mar 27, 2017 at 06:10:43PM +0200, Alexander Graf wrote:
>>
>>
>> On 27/03/2017 17:46, Eduardo Habkost wrote:
>>> On Mon, Mar 27, 2017 at 04:26:50PM +0200, Alexander Graf wrote:
>>>> KVM allows trap and emulate (read: NOP) of the MONITOR and MWAIT
>>>> instructions. There is work undergoing to enable actual execution
>>>> of these inside of KVM, but nobody really wants to expose the feature
>>>> to the guest by default, as it would eat up all of the host CPU.
>>>
>>> Isn't this something that should be reported using
>>> KVM_GET_EMULATED_CPUID? (QEMU still doesn't know how to use
>>> KVM_GET_EMULATED_CPUID, however.)
>>
>> Depends how you look at it. In KVM land there are basically 3 ways to deal
>> with MONITOR/MWAIT:
>>
>>   1) #VMEXIT on every execution, treat them as NOP
>>   2) let the guest natively execute them (looks like a busy loop for the
>> host, but saves power)
>>   3) be smart in KVM about it, add actual emulation and adaptively allow for
>> native mwait execution or emulated mwait which means we can run inside host
>> context
>
> Which case is going to be enabled when using your patch? Don't
> you want to make that configurable?
>
> This looks like configuration that can't be easily represented
> using the GET_SUPPORTED_CPUID/KVM_SET_CPUID abstraction, as the
> ability to enable the feature can't be represented by a single
> bit.
>
> We already have a few cases where we make
> kvm_arch_get_supported_cpuid() look at something other than just
> GET_SUPPORTED_CPUID return values (most cases are related to
> in-kernel irqchip). We can change kvm_arch_get_supported_cpuid()
> to look at other flags (like one that would configure mwait
> behavior), and decide to report CPUID_EXT_MONITOR on those cases.
>
> Would something like the following make sense?
>
> * Having a "mwait=(none|nop|native|smart)" option, to choose
>   mwait behavior
> * Making kvm_arch_get_supported_cpuid() return CPUID_EXT_MONITOR
>   as supported only if the "mwait" option is not "none".
>
> Then:
> * "-cpu ...,monitor=on" would fail, because mwait=none would be
>   the default
> * "-cpu ...,mwait=none,monitor=on" would fail
> * "-cpu ...,mwait=(nop|native|smart)" would fail if
>   host KVM doesn't report the corresponding mwait behavior as
>   supported
> * "-cpu ...,mwait=(nop|native|smart),monitor=on" would work
> * "-cpu ...,mwait=(nop|native|smart)" would also work, and
>   probably should enable CPUID_EXT_MONITOR flag by default
>
> We could still implement "monitor=force" for debugging, but I
> think we need something safer than "just ignore what KVM is
> telling us" for production.

I personally think we want the =force for any cpuid bit that we want to 
randomly poke into the expose CPUID bitmap and if a customer is daring 
enough, leave that to him as an option.

For anything else, I wouldn't overengineer this interface. I think 
eventually we want to just natively support emulated mwait with proper 
adaptive logic on when to trap vs execute mwait inside the guest (as 
mentioned in the kvm thread on this). Once that's implemented, KVM can 
just expose the MONITOR bit as supported and everyone gets it automatically.

If at that point, the adaptive interface performs much worse than the 
naive one, we can still think about pushing this into an enable_cap and 
add a specific mwait= option.


Alex

  reply	other threads:[~2017-03-27 16:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 14:26 [Qemu-devel] [PATCH] i386: Allow monitor / mwait cpuid override Alexander Graf
2017-03-27 15:46 ` Eduardo Habkost
2017-03-27 15:46   ` [Qemu-devel] " Eduardo Habkost
2017-03-27 16:10   ` Alexander Graf
2017-03-27 16:10     ` [Qemu-devel] " Alexander Graf
2017-03-27 16:33     ` Eduardo Habkost
2017-03-27 16:33       ` [Qemu-devel] " Eduardo Habkost
2017-03-27 16:42       ` Alexander Graf [this message]
2017-03-27 16:42         ` Alexander Graf
2017-03-27 18:06         ` Eduardo Habkost
2017-03-27 18:06           ` [Qemu-devel] " Eduardo Habkost
2017-03-27 16:22   ` Alexander Graf
2017-03-27 16:22     ` [Qemu-devel] " Alexander Graf
2017-03-27 16:27     ` Paolo Bonzini
2017-03-27 16:27       ` [Qemu-devel] " Paolo Bonzini
2018-02-27  9:52 ` Gonglei (Arei)
2018-02-27 23:55   ` Alexander Graf
2018-02-28 11:50     ` Paolo Bonzini
2018-02-28 12:24       ` Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=164e6c5d-ca36-b92d-2831-468a54cd3efe@suse.de \
    --to=agraf@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.