Re: [PATCH v2] target-i386: add KVM_HINTS_DEDICATED performance hint

From: Paolo Bonzini
Date: Tue Apr 10 2018 - 08:04:13 EST


On 10/04/2018 13:57, Eduardo Habkost wrote:
> On Tue, Apr 10, 2018 at 05:13:21PM +0800, Wanpeng Li wrote:
>> Hi Eduardo,
>> 2018-03-09 22:16 GMT+08:00 Eduardo Habkost <ehabkost@xxxxxxxxxx>:
>>> On Fri, Feb 09, 2018 at 06:15:25AM -0800, Wanpeng Li wrote:
>>>> From: Wanpeng Li <wanpengli@xxxxxxxxxxx>
>>>>
>>>> Add KVM_HINTS_DEDICATED performance hint, guest checks this feature bit
>>>> to determine if they run on dedicated vCPUs, allowing optimizations such
>>>> as usage of qspinlocks.
>>>>
>>>> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
>>>> Cc: Radim KrÄmÃÅ <rkrcmar@xxxxxxxxxx>
>>>> Cc: Eduardo Habkost <ehabkost@xxxxxxxxxx>
>>>> Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx>
>>>> ---
>>>> v1 -> v2:
>>>> * add a new feature word
>>>>
>>>> target/i386/cpu.c | 14 ++++++++++++++
>>>> target/i386/cpu.h | 3 +++
>>>> target/i386/kvm.c | 4 ++++
>>>> 3 files changed, 21 insertions(+)
>>>>
>>>> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
>>>> index d70954b..e2974ad 100644
>>>> --- a/target/i386/cpu.c
>>>> +++ b/target/i386/cpu.c
>>>> @@ -358,6 +358,20 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
>>>> .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EAX,
>>>> .tcg_features = TCG_KVM_FEATURES,
>>>> },
>>>> + [FEAT_KVM_HINTS] = {
>>>> + .feat_names = {
>>>> + "hint-dedicated", NULL, NULL, NULL,
>>>
>>> I suggest naming it "kvm-hint-dedicated", to indicate it's
>>> KVM-specific.
>>
>> I found this feature is enabled by default w/o kvm-hint-dedicated
>> parameter, any idea how to make it disabled by default?
>
> You mean on "-cpu host", right?
>
> The assumption in most of the code is that anything enabled on
> GET_SUPPORTED_CPUID should be enabled on "-cpu host". This
> shouldn't be the case for FEAT_KVM_HINTS.
>
> Untested fix below.
>
> Signed-off-by: Eduardo Habkost <ehabkost@xxxxxxxxxx>
> ---
> target/i386/cpu.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 1a6b082b6f..a20fe26573 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -295,6 +295,8 @@ typedef struct FeatureWordInfo {
> uint32_t tcg_features; /* Feature flags supported by TCG */
> uint32_t unmigratable_flags; /* Feature flags known to be unmigratable */
> uint32_t migratable_flags; /* Feature flags known to be migratable */
> + /* Features that shouldn't be auto-enabled by "-cpu host" */
> + uint32_t no_autoenable_flags;
> } FeatureWordInfo;
>
> static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
> @@ -400,6 +402,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
> },
> .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EDX,
> .tcg_features = TCG_KVM_FEATURES,
> + /*
> + * KVM hints aren't auto-enabled by -cpu host, they need to be
> + * explicitly enabled in the command-line.
> + */
> + .no_autoenable_flags = ~0U,
> },
> [FEAT_HYPERV_EAX] = {
> .feat_names = {
> @@ -4062,7 +4069,8 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
> */
> env->features[w] |=
> x86_cpu_get_supported_feature_word(w, cpu->migratable) &
> - ~env->user_features[w];
> + ~env->user_features[w] & \
> + ~feature_word_info[w].no_autoenable_flags;
> }
> }
>
>

Reviewed-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>