[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 52/60] i386/cpu: make -cpu host support monitor/mwait
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 52/60] i386/cpu: make -cpu host support monitor/mwait |
Date: |
Thu, 28 Jun 2018 22:05:02 +0200 |
From: "Michael S. Tsirkin" <address@hidden>
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 <address@hidden>
Reviewed-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
target/i386/cpu.c | 19 ++++++++++++++-----
target/i386/cpu.h | 9 +++++++++
target/i386/kvm.c | 9 +++++++++
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index e6c2f8a..b54f36a 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3959,11 +3959,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 */
@@ -4811,6 +4811,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/cpu.h b/target/i386/cpu.h
index 16c59b7..8eaefee 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1382,6 +1382,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/kvm.c b/target/i386/kvm.c
index dc991f6..c5f72d6 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) {
--
1.8.3.1
- [Qemu-devel] [PULL 41/60] WHPX: register for unrecognized MSR exits, (continued)
- [Qemu-devel] [PULL 41/60] WHPX: register for unrecognized MSR exits, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 43/60] target-i386: Add NMI interception to SVM, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 42/60] memory/hmp: Print owners/parents in "info mtree", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 48/60] ioapic: some proper indents when dump info, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 46/60] doc: another fix to "info pic", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 44/60] target-i386: Allow interrupt injection after STGI, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 45/60] target-i386: Mark cpu_vmexit noreturn, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 47/60] ioapic: support "info pic", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 49/60] ioapic: support "info irq", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 51/60] kvm: support -overcommit cpu-pm=on|off, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 52/60] i386/cpu: make -cpu host support monitor/mwait,
Paolo Bonzini <=
- [Qemu-devel] [PULL 54/60] dump: use system context in Windows dump, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 56/60] dump: add Windows live system dump, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 53/60] dump: add Windows dump format to dump-guest-memory, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 55/60] dump: add fallback KDBG using in Windows dump, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 50/60] hmp: obsolete "info ioapic", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 58/60] hw/scsi: centralize SG_IO calls into single function, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 60/60] tests/boot-serial: Do not delete the output file in case of errors, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 59/60] hw/scsi: add VPD Block Limits emulation, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 57/60] hw/scsi: cleanups before VPD BL emulation, Paolo Bonzini, 2018/06/28
- Re: [Qemu-devel] [PULL 00/60] Misc patches for soft freeze, Peter Maydell, 2018/06/29