From: "Michael S. Tsirkin" <mst@redhat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini <pbonzini@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, kvm@vger.kernel.org, Richard Henderson <rth@twiddle.net> Subject: [PATCH v6 2/2] i386/cpu: make -cpu host support monitor/mwait Date: Fri, 22 Jun 2018 22:22:05 +0300 [thread overview] Message-ID: <20180622192148.178309-3-mst@redhat.com> (raw) In-Reply-To: <20180622192148.178309-1-mst@redhat.com> When guest CPU PM is enabled, and with -cpu host, expose the host CPU MWAIT leaf in the CPUID so guest can make good PM decisions. Note: the result is 100% CPU utilization reported by host as host no longer knows that the CPU is halted. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> --- target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 9 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 664504610e..309f804573 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1378,6 +1378,15 @@ struct X86CPU { /* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough; + /* if true the CPUID code directly forwards + * host monitor/mwait leaves to the guest */ + struct { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; + } mwait; + /* Features that were filtered out because of missing host capabilities */ uint32_t filtered_features[FEATURE_WORDS]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 94260412e2..a4fb856d58 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3760,11 +3760,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } break; case 5: - /* mwait info: needed for Core compatibility */ - *eax = 0; /* Smallest monitor-line size in bytes */ - *ebx = 0; /* Largest monitor-line size in bytes */ - *ecx = CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; - *edx = 0; + /* MONITOR/MWAIT Leaf */ + *eax = cpu->mwait.eax; /* Smallest monitor-line size in bytes */ + *ebx = cpu->mwait.ebx; /* Largest monitor-line size in bytes */ + *ecx = cpu->mwait.ecx; /* flags */ + *edx = cpu->mwait.edx; /* mwait substates */ break; case 6: /* Thermal and Power Leaf */ @@ -4595,6 +4595,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } + if (xcc->host_cpuid_required && enable_cpu_pm) { + host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx, + &cpu->mwait.ecx, &cpu->mwait.edx); + env->features[FEAT_1_ECX] |= CPUID_EXT_MONITOR; + } + /* mwait extended info: needed for Core compatibility */ + /* We always wake on interrupt even if host does not have the capability */ + cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; + if (cpu->apic_id == UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index cf9107be4b..805968d5b7 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -366,6 +366,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, if (!kvm_irqchip_in_kernel()) { ret &= ~CPUID_EXT_X2APIC; } + + if (enable_cpu_pm) { + int disable_exits = kvm_check_extension(s, + KVM_CAP_X86_DISABLE_EXITS); + + if (disable_exits & KVM_X86_DISABLE_EXITS_MWAIT) { + ret |= CPUID_EXT_MONITOR; + } + } } else if (function == 6 && reg == R_EAX) { ret |= CPUID_6_EAX_ARAT; /* safe to allow because of emulated APIC */ } else if (function == 7 && index == 0 && reg == R_EBX) { -- MST
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, Eduardo Habkost <ehabkost@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH v6 2/2] i386/cpu: make -cpu host support monitor/mwait Date: Fri, 22 Jun 2018 22:22:05 +0300 [thread overview] Message-ID: <20180622192148.178309-3-mst@redhat.com> (raw) In-Reply-To: <20180622192148.178309-1-mst@redhat.com> When guest CPU PM is enabled, and with -cpu host, expose the host CPU MWAIT leaf in the CPUID so guest can make good PM decisions. Note: the result is 100% CPU utilization reported by host as host no longer knows that the CPU is halted. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> --- target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 9 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 664504610e..309f804573 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1378,6 +1378,15 @@ struct X86CPU { /* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough; + /* if true the CPUID code directly forwards + * host monitor/mwait leaves to the guest */ + struct { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; + } mwait; + /* Features that were filtered out because of missing host capabilities */ uint32_t filtered_features[FEATURE_WORDS]; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 94260412e2..a4fb856d58 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3760,11 +3760,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } break; case 5: - /* mwait info: needed for Core compatibility */ - *eax = 0; /* Smallest monitor-line size in bytes */ - *ebx = 0; /* Largest monitor-line size in bytes */ - *ecx = CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; - *edx = 0; + /* MONITOR/MWAIT Leaf */ + *eax = cpu->mwait.eax; /* Smallest monitor-line size in bytes */ + *ebx = cpu->mwait.ebx; /* Largest monitor-line size in bytes */ + *ecx = cpu->mwait.ecx; /* flags */ + *edx = cpu->mwait.edx; /* mwait substates */ break; case 6: /* Thermal and Power Leaf */ @@ -4595,6 +4595,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } + if (xcc->host_cpuid_required && enable_cpu_pm) { + host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx, + &cpu->mwait.ecx, &cpu->mwait.edx); + env->features[FEAT_1_ECX] |= CPUID_EXT_MONITOR; + } + /* mwait extended info: needed for Core compatibility */ + /* We always wake on interrupt even if host does not have the capability */ + cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; + if (cpu->apic_id == UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index cf9107be4b..805968d5b7 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -366,6 +366,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, if (!kvm_irqchip_in_kernel()) { ret &= ~CPUID_EXT_X2APIC; } + + if (enable_cpu_pm) { + int disable_exits = kvm_check_extension(s, + KVM_CAP_X86_DISABLE_EXITS); + + if (disable_exits & KVM_X86_DISABLE_EXITS_MWAIT) { + ret |= CPUID_EXT_MONITOR; + } + } } else if (function == 6 && reg == R_EAX) { ret |= CPUID_6_EAX_ARAT; /* safe to allow because of emulated APIC */ } else if (function == 7 && index == 0 && reg == R_EBX) { -- MST
next prev parent reply other threads:[~2018-06-22 19:22 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-22 19:22 [PATCH v6 0/2] kvm: limited x86 CPU power management Michael S. Tsirkin 2018-06-22 19:22 ` [Qemu-devel] " Michael S. Tsirkin 2018-06-22 19:22 ` [PATCH v6 1/2] kvm: support -overcommit cpu-pm=on|off Michael S. Tsirkin 2018-06-22 19:22 ` [Qemu-devel] " Michael S. Tsirkin 2018-06-25 9:40 ` Igor Mammedov 2018-06-25 9:40 ` [Qemu-devel] " Igor Mammedov 2018-06-26 14:06 ` Michael S. Tsirkin 2018-06-26 14:06 ` [Qemu-devel] " Michael S. Tsirkin 2018-06-26 15:13 ` Igor Mammedov 2018-06-26 15:13 ` [Qemu-devel] " Igor Mammedov 2018-06-26 15:16 ` Michael S. Tsirkin 2018-06-26 15:16 ` [Qemu-devel] " Michael S. Tsirkin 2018-06-27 13:42 ` Eduardo Habkost 2018-06-27 13:42 ` [Qemu-devel] " Eduardo Habkost 2018-06-27 13:43 ` Eduardo Habkost 2018-06-27 13:43 ` [Qemu-devel] " Eduardo Habkost 2018-06-22 19:22 ` Michael S. Tsirkin [this message] 2018-06-22 19:22 ` [Qemu-devel] [PATCH v6 2/2] i386/cpu: make -cpu host support monitor/mwait Michael S. Tsirkin 2018-06-22 21:55 ` [PATCH v6 0/2] kvm: limited x86 CPU power management no-reply 2018-06-22 21:55 ` [Qemu-devel] " no-reply 2018-06-22 22:03 ` no-reply 2018-06-22 22:03 ` [Qemu-devel] " no-reply 2018-06-22 22:16 ` no-reply 2018-06-22 22:16 ` [Qemu-devel] " no-reply 2018-06-27 15:08 ` Paolo Bonzini 2018-06-27 15:08 ` [Qemu-devel] " Paolo Bonzini
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=20180622192148.178309-3-mst@redhat.com \ --to=mst@redhat.com \ --cc=ehabkost@redhat.com \ --cc=kvm@vger.kernel.org \ --cc=mtosatti@redhat.com \ --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: linkBe 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.