kvm: x86 CPU power management
v2 cover kvm: x86 CPU power management
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:
6.452 sec
After:
4.382 sec
Baremetal:
4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
i386/cpu: make -cpu host support monitor/mwait
include/sysemu/sysemu.h | 1 + target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 30 ++++++++++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 6 files changed, 67 insertions(+), 7 deletions(-)
Signature · 1 line
MST
PATCH v2 1/2 kvm: support -realtime cpu-pm=on|off
With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU.
Follow-up patches will expose this capability to guest (using mwait leaf).
Based on a patch by Wanpeng Li <[email protected]> .
--- include/sysemu/sysemu.h | 1 + target/i386/kvm.c | 22 ++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 4 files changed, 36 insertions(+), 2 deletions(-)
include/sysemu/sysemu.h +1 -0
@@ -128,6 +128,7 @@ extern bool boot_strict;extern uint8_t *boot_splash_filedata;extern size_t boot_splash_filedata_size;extern bool enable_mlock; +extern bool enable_cpu_pm;extern uint8_t qemu_extra_params_fw[2 ];extern QEMUClockType rtc_clock;extern const char *mem_path;
target/i386/kvm.c +22 -0
@@ -1357,6 +1357,28 @@ int kvm_arch_init(MachineState *ms, KVMState *s) smram_machine_done.notify = register_smram_listener;qemu_add_machine_init_done_notifier (&smram_machine_done); } + +if (enable_cpu_pm) { +int disable_exits =kvm_check_extension (s,KVM_CAP_X86_DISABLE_EXITS ); +int ret; + +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL ) && !defined(KVM_X86_DISABLE_EXITS_HLT ) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif +if (disable_exits) { + disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | +KVM_X86_DISABLE_EXITS_HLT | +KVM_X86_DISABLE_EXITS_PAUSE ); + } + + ret =kvm_vm_enable_cap (s,KVM_CAP_X86_DISABLE_EXITS ,0 , + disable_exits); +if (ret <0 ) { +error_report ("kvm: guest stopping CPU not supported: %s" ,strerror (-ret)); + } + } +return 0 ; }
vl.c +6 -0
@@ -142,6 +142,7 @@ ram_addr_t ram_size;const char *mem_path =NULL ;int mem_prealloc =0 ;/* force preallocation of physical target memory */ bool enable_mlock = false; +bool enable_cpu_pm = false;int nb_nics;NICInfo nd_table[MAX_NICS ];int autostart;
@@ -386,6 +387,10 @@ static QemuOptsList qemu_realtime_opts = { .name = "mlock", .type = QEMU_OPT_BOOL, }, + { + .name = "cpu-pm", + .type = QEMU_OPT_BOOL, + }, {/* end of list */ } }, };
@@ -3904,6 +3909,7 @@ int main(int argc, char **argv, char **envp)exit (1 ); } enable_mlock =qemu_opt_get_bool (opts,"mlock" , true); + enable_cpu_pm =qemu_opt_get_bool (opts,"cpu-pm" , false);break ;case QEMU_OPTION_msg: opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
qemu-options.hx +7 -2
@@ -3325,16 +3325,21 @@ Do not start CPU at startup (you must type 'c' in the monitor). ETEXI DEF("realtime", HAS_ARG, QEMU_OPTION_realtime, - "-realtime [mlock=on|off]\n" + "-realtime [mlock=on|off][cpu-halt=on|off[\n" " run qemu with realtime features\n" - " mlock=on|off controls mlock support (default: on)\n", + " mlock=on|off controls mlock support (default: on)\n" + " cpu-pm=on|off controls cpu power management (default: off)\n", QEMU_ARCH_ALL) STEXI @item -realtime mlock=on|off +@item -realtime cpu-pm=on|off @findex -realtime Run qemu with realtime features. mlocking qemu and guest memory can be enabled via @option{mlock=on} (enabled by default). +guest ability to manage power state of host cpus (increasing latency for other +processes on the same host cpu, but decreasing latency for guest) +can be enabled via @option{cpu-pm=on} (disabled by default). ETEXI DEF("gdb", HAS_ARG, QEMU_OPTION_gdb, \
Signature · 1 line
MST
PATCH v2 2/2 i386/cpu: make -cpu host support monitor/mwait
In reply to Michael S. TsirkinWhen 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.
--- target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 8 ++++++++ 3 files changed, 31 insertions(+), 5 deletions(-)
target/i386/cpu.h +9 -0
@@ -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 ];
target/i386/cpu.c +14 -5
@@ -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 ;
target/i386/kvm.c +8 -0
@@ -366,6 +366,14 @@ 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 ) {
Signature · 1 line
MST
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2 0/2] kvm: x86 CPU power management
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'b92893898a i386/cpu: make -cpu host support monitor/mwait 26a0f862a2 kvm: support -realtime cpu-pm=on|off
=== OUTPUT BEGIN ===
Checking PATCH 1/2: kvm: support -realtime cpu-pm=on|off...
WARNING: line over 80 characters
#85: FILE: target/i386/kvm.c:1401:
+ error_report("kvm: guest stopping CPU not supported: %s", strerror(-ret));
ERROR: do not initialise globals to 0 or NULL
#100: FILE: vl.c:145:
+bool enable_cpu_pm = false;
total: 1 errors, 1 warnings, 82 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 2/2: i386/cpu: make -cpu host support monitor/mwait...
WARNING: line over 80 characters
#82: FILE: target/i386/kvm.c:371:
+ int disable_exits = kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS);
total: 0 errors, 1 warnings, 60 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 9 lines · On Tue, Jun 12, 2018 at 12:18:03PM -0700, [email protected] wrote:
Checking PATCH 1/2: kvm: support -realtime cpu-pm=on|off...
WARNING: line over 80 characters
#85: FILE:target/i386/kvm.c:1401:
+error_report("kvm: guest stopping CPU not supported: %s", strerror(-ret));ERROR: do not initialise globals to 0 or NULL
#100: FILE: vl.c:145:
+boolenable_cpu_pm= false;
Quoted 5 lines
total: 1 errors, 1 warnings, 82 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
We seem to violate this left and right. Let's drop this?
Signature · 1 line
MST
Re: [PATCH v2 1/2] kvm: support -realtime cpu-pm=on|off
In reply to Michael S. TsirkinQuoted 11 lines · Michael S. Tsirkin
With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU.
Follow-up patches will expose this capability to guest (using mwait leaf).
Based on a patch by Wanpeng Li <[email protected]> .
Signed-off-by Michael S. Tsirkin <[email protected]>
The interface makes sense to me, but:
Quoted 1 line
+extern bool
enable_cpu_pm;
Why do we need a global variable if initialization code can call qemu_opt_get_bool() directly?
Signature · 1 line
Eduardo
Re: [PATCH v2 1/2] kvm: support -realtime cpu-pm=on|off
In reply to Michael S. TsirkinQuoted 23 lines · Michael S. Tsirkin
With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU.
Follow-up patches will expose this capability to guest (using mwait leaf).
Based on a patch by Wanpeng Li <[email protected]> .
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/sysemu/sysemu.h | 1 + target/i386/kvm.c | 22 ++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 4 files changed, 36 insertions(+), 2 deletions(-)include/sysemu/sysemu.h +0
-0
include/sysemu/sysemu.h extern bool boot_strict; · line 131
Quoted 4 lines
include/sysemu/sysemu.h +1
-0@@ -128,6 +128,7 @@ extern bool boot_strict;extern uint8_t *boot_splash_filedata;extern size_t boot_splash_filedata_size;extern bool enable_mlock; +extern bool enable_cpu_pm;
After looking at patch 2/2, I see that the global variable is useful, and it's consistent with the existing enable_mlock variable.
Quoted 18 lines
include/sysemu/sysemu.h +0
-0extern uint8_t qemu_extra_params_fw[2 ];extern QEMUClockType rtc_clock;extern const char *mem_path;target/i386/kvm.c +7
-0@@ -1357,6 +1357,28 @@ int kvm_arch_init(MachineState *ms, KVMState *s) smram_machine_done.notify = register_smram_listener;qemu_add_machine_init_done_notifier (&smram_machine_done); } + +if (enable_cpu_pm) { +int disable_exits =kvm_check_extension (s,KVM_CAP_X86_DISABLE_EXITS ); +int ret; + +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL ) && !defined(KVM_X86_DISABLE_EXITS_HLT )
target/i386/kvm.c int kvm_arch_init(MachineState *ms, KVMState *s) · line 1376
Quoted 10 lines
target/i386/kvm.c +10
-0+#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif +if (disable_exits) { + disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | +KVM_X86_DISABLE_EXITS_HLT | +KVM_X86_DISABLE_EXITS_PAUSE ); + } + + ret =kvm_vm_enable_cap (s,KVM_CAP_X86_DISABLE_EXITS ,0 , + disable_exits);
Isn't the kvm_vm_enable_cap() call supposed to be inside the "if (disable_exits)" block?
Quoted 7 lines
target/i386/kvm.c +5
-0+if (ret <0 ) { +error_report ("kvm: guest stopping CPU not supported: %s" ,strerror (-ret)); + } + } +return 0 ; }
[...]
Signature · 1 line
Eduardo
Re: [PATCH v2 2/2] i386/cpu: make -cpu host support monitor/mwait
In reply to Michael S. TsirkinQuoted 7 lines · Michael S. Tsirkin
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 <[email protected]>
Signature · 1 line
Eduardo
Re: [PATCH v2 1/2] kvm: support -realtime cpu-pm=on|off
In reply to Eduardo HabkostQuoted 56 lines · Eduardo Habkost
Quoted 23 lines · Michael S. Tsirkin
With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU.
Follow-up patches will expose this capability to guest (using mwait leaf).
Based on a patch by Wanpeng Li <[email protected]> .
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/sysemu/sysemu.h | 1 + target/i386/kvm.c | 22 ++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 4 files changed, 36 insertions(+), 2 deletions(-)include/sysemu/sysemu.h +0
-0include/sysemu/sysemu.h extern bool boot_strict; · line 131
Quoted 4 lines
include/sysemu/sysemu.h +1
-0@@ -128,6 +128,7 @@ extern bool boot_strict;extern uint8_t *boot_splash_filedata;extern size_t boot_splash_filedata_size;extern bool enable_mlock; +extern bool enable_cpu_pm;After looking at patch 2/2, I see that the global variable is useful, and it's consistent with the existing
enable_mlockvariable.Quoted 23 lines
include/sysemu/sysemu.h +0
-0extern uint8_t qemu_extra_params_fw[2 ];extern QEMUClockType rtc_clock;extern const char *mem_path;target/i386/kvm.c +12
-0@@ -1357,6 +1357,28 @@ int kvm_arch_init(MachineState *ms, KVMState *s) smram_machine_done.notify = register_smram_listener;qemu_add_machine_init_done_notifier (&smram_machine_done); } + +if (enable_cpu_pm) { +int disable_exits =kvm_check_extension (s,KVM_CAP_X86_DISABLE_EXITS ); +int ret; + +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL ) && !defined(KVM_X86_DISABLE_EXITS_HLT ) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif +if (disable_exits) { + disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | + KVM_X86_DISABLE_EXITS_HLT |
Quoted 8 lines
target/i386/kvm.c int kvm_arch_init(MachineState *ms, KVMState *s) · line 1376
Quoted 5 lines
target/i386/kvm.c +5
-0+ KVM_X86_DISABLE_EXITS_PAUSE); + } + + ret =kvm_vm_enable_cap (s,KVM_CAP_X86_DISABLE_EXITS ,0 , + disable_exits);Isn't the
kvm_vm_enable_cap()call supposed to be inside the "if (disable_exits)" block?
Doing it like this causes a warning if pm is requested but disable halt is not supported.
But I can move it, sure - let me know.
Quoted 11 lines
Quoted 7 lines
target/i386/kvm.c +5
-0+if (ret <0 ) { +error_report ("kvm: guest stopping CPU not supported: %s" ,strerror (-ret)); + } + } +return 0 ; }[...]
Signature · 1 line
Eduardo
Quoted 24 lines · Michael S. Tsirkin
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:6.452 sec After: 4.382 sec Baremetal: 4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
i386/cpu: make -cpu host support monitor/mwait
Quoted 10 lines
include/sysemu/sysemu.h | 1 + target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 30 ++++++++++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 6 files changed, 67 insertions(+), 7 deletions(-)Signature · 1 line
MST
Hi Michael,
1) Command line option interface
Why is this not an optional cpu feature such as the other features?
-cpu CPU,+mwait
rather than a separate, architecture independent "-realtime cpu-pm=on|off" command line option?
2) Migration
Isnt it sufficient to check that both CPUID leafs are the same, to allow migration ?
1. Check that the processor supports MONITOR and MWAIT. If CPUID.01H:ECX.MONITOR[bit 3] = 1, MONITOR and MWAIT are available at ring 0.
2. Query the smallest and largest line size that MONITOR uses. Use CPUID.05H:EAX.smallest[bits 15:0];EBX.largest[bits15:0].
Quoted 40 lines · Marcelo Tosatti
Quoted 24 lines · Michael S. Tsirkin
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:6.452 sec After: 4.382 sec Baremetal: 4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
i386/cpu: make -cpu host support monitor/mwaitQuoted 10 lines
include/sysemu/sysemu.h | 1 + target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 30 ++++++++++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 6 files changed, 67 insertions(+), 7 deletions(-)Signature · 1 line
MSTHi Michael,
1) Command line option interface
Quoted 7 lines
Why is this not an optional cpu feature such as the other features?
-cpu CPU,+mwait
rather than a separate, architecture independent "-realtime cpu-pm=on|off" command line option?
Because it's not just a guest flag. With guest pm on, one guest can severely affect the latency of others on the same host CPU.
Quoted 4 lines
2) Migration
Isnt it sufficient to check that both CPUID leafs are the same, to allow migration ?
Not at the moment since linux guests use mwait hints and latency values from a table in intel_idle. If the host and guest models do not match, mwait will get a wrong hint.
It will not do the right thing then!
You want exactly the same host CPU for it to work.
This isn't different from how -host cpu works generally.
Quoted 7 lines
1. Check that the processor supports MONITOR and MWAIT. If CPUID.01H:ECX.MONITOR[bit 3] = 1, MONITOR and MWAIT are available at ring 0.
2. Query the smallest and largest line size that MONITOR uses. Use CPUID.05H:EAX.smallest[bits 15:0];EBX.largest[bits15:0].
Quoted 14 lines · Michael S. Tsirkin
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:
Quoted 8 lines
6.452 sec After: 4.382 sec Baremetal: 4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
IMHO this really shouldn't be under the -realtime flag. I don't think the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it.
"-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
IOW, I think we should just have this as an option under -cpu or some other *functionally* named option, not a option named after a specific usage scenario.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Paolo Bonzini
maintainerQuoted 4 lines · Daniel P. Berrangé
I don't think
the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it.
Quoted 8 lines
"-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
IOW, I think we should just have this as an option under -cpu or some other *functionally* named option, not a option named after a specific usage scenario.
"-cpu" is certainly wrong for KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".
A separate issue is whether the same flag should control both KVM_CAP_X86_DISABLE_EXITS and the monitor/mwait CPUID leaf. Eduardo, what do you think?
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Daniel P. Berrangé
I don't think
the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it."-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
Quoted 8 lines
Quoted 3 lines
IOW, I think we should just have this as an option under -cpu or some other *functionally* named option, not a option named after a specific usage scenario.
"-cpu" is certainly wrong for
KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".
If none of the existing ones are a suitable fit, then we should just introduce a new CLI arg instead stuffing it into somewhere odd.
IOW, why not just "--power-mgmt host|guest"
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 14 lines · Paolo Bonzini
Quoted 4 lines · Daniel P. Berrangé
I don't think
the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it.Quoted 8 lines
"-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
IOW, I think we should just have this as an option under -cpu or some other *functionally* named option, not a option named after a specific usage scenario.
Quoted 8 lines
"-cpu" is certainly wrong for
KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".A separate issue is whether the same flag should control both
KVM_CAP_X86_DISABLE_EXITSand the monitor/mwait CPUID leaf. Eduardo, what do you think?
Making "-cpu host" be affected by a host-side option is acceptable to me. A "-cpu" option would be more appropriate if we decide to allow monitor/mwait be enabled for other CPU models too.
Signature · 1 line
Eduardo
Paolo Bonzini
maintainerQuoted 6 lines · Daniel P. Berrangé
Quoted 4 lines
"-cpu" is certainly wrong for
KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".If none of the existing ones are a suitable fit, then we should just introduce a new CLI arg instead stuffing it into somewhere odd.
It is related to mlock in my opinion. Both options are about applying settings that reduce latency but may not be applicable in general. Maybe "-realtime" could be renamed to "-perftune" or something like that, but I'd like to keep the grouping.
Paolo
Quoted 1 line
IOW, why not just "--power-mgmt host|guest"
Paolo Bonzini
maintainerQuoted 8 lines · Eduardo Habkost
Quoted 4 lines
A separate issue is whether the same flag should control both
KVM_CAP_X86_DISABLE_EXITSand the monitor/mwait CPUID leaf. Eduardo, what do you think?Making "-cpu host" be affected by a host-side option is acceptable to me. A "-cpu" option would be more appropriate if we decide to allow monitor/mwait be enabled for other CPU models too.
Sounds fair enough, we should probably add a note in the documentation of "-cpu host" though.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Daniel P. Berrangé
I don't think
the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it."-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
Quoted 8 lines
Quoted 3 lines
IOW, I think we should just have this as an option under -cpu or some other *functionally* named option, not a option named after a specific usage scenario.
"-cpu" is certainly wrong for
KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".
I don't feel it's a good name. The new flag allows guest to put CPU into a low power state without host knowing about it. This will affect other guests on the same host CPU. It doesn't however limit power management to guest only, things like speedstep remain under host control.
Quoted 5 lines
A separate issue is whether the same flag should control both
KVM_CAP_X86_DISABLE_EXITSand the monitor/mwait CPUID leaf. Eduardo, what do you think?Paolo
It's just for -cpu host.
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Daniel P. Berrangé
Quoted 4 lines
"-cpu" is certainly wrong for
KVM_CAP_X86_DISABLE_EXITS. "-cpu" is a device option, while this is about host behavior. "-realtime"'s name is awful, but I still think it's the best place for this option. Maybe we could call it "-realtime power-mgmt={host|guest}".If none of the existing ones are a suitable fit, then we should just introduce a new CLI arg instead stuffing it into somewhere odd.
It is related to mlock in my opinion. Both options are about applying settings that reduce latency but may not be applicable in general.
I would add, it's also about host resource handling.
With mlock guest memory is locked so there's no memory overcommit. With cpu-pm guest does not give up host cpu which mostly disables host cpu overcommit.
Quoted 4 lines
Maybe "-realtime" could be renamed to "-perftune" or something like that, but I'd like to keep the grouping.
Paolo
-overcommit ?
Quoted 1 line
Quoted 1 line
IOW, why not just "--power-mgmt host|guest"
Quoted 44 lines · Michael S. Tsirkin
Quoted 43 lines · Marcelo Tosatti
Quoted 24 lines · Michael S. Tsirkin
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:6.452 sec After: 4.382 sec Baremetal: 4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
i386/cpu: make -cpu host support monitor/mwaitQuoted 10 lines
include/sysemu/sysemu.h | 1 + target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 30 ++++++++++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 6 files changed, 67 insertions(+), 7 deletions(-)Signature · 1 line
MSTHi Michael,
1) Command line option interface
Why is this not an optional cpu feature such as the other features?
Quoted 7 lines
Quoted 4 lines
-cpu CPU,+mwait
rather than a separate, architecture independent "-realtime cpu-pm=on|off" command line option?
Because it's not just a guest flag. With guest pm on, one guest can severely affect the latency of others on the same host CPU.
How so ?
Quoted 9 lines
Quoted 4 lines
2) Migration
Isnt it sufficient to check that both CPUID leafs are the same, to allow migration ?
Not at the moment since linux guests use mwait hints and latency values from a table in
intel_idle. If the host and guest models do not match, mwait will get a wrong hint.
Quoted 5 lines
It will not do the right thing then!
You want exactly the same host CPU for it to work.
This isn't different from how -host cpu works generally.
Ok, makes sense.
Quoted 7 lines
Quoted 7 lines
1. Check that the processor supports MONITOR and MWAIT. If CPUID.01H:ECX.MONITOR[bit 3] = 1, MONITOR and MWAIT are available at ring 0.
2. Query the smallest and largest line size that MONITOR uses. Use CPUID.05H:EAX.smallest[bits 15:0];EBX.largest[bits15:0].
Quoted 47 lines · Marcelo Tosatti
Quoted 46 lines · Michael S. Tsirkin
Quoted 45 lines · Marcelo Tosatti
Quoted 24 lines · Michael S. Tsirkin
This adds ability to expose host CPU power management capabilities to guests. For intel guests, this is sufficient for guest to enable low power CPU power management. For AMD guests it isn't sufficient, deeper C-states are entered using System-IO.
mwait based power management is tied closely to specifics of CPUID, making migration challenging. At this point only the non-migrateable -cpu host is supported.
With this patch applied, VM latency is within the noise of baremetal for some benchmarks.
perf bench sched pipe results:
Before:6.452 sec After: 4.382 sec Baremetal: 4.136 secMichael S. Tsirkin (2):
kvm: support -realtime cpu-pm=on|off
i386/cpu: make -cpu host support monitor/mwaitQuoted 10 lines
include/sysemu/sysemu.h | 1 + target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 19 ++++++++++++++----- target/i386/kvm.c | 30 ++++++++++++++++++++++++++++++ vl.c | 6 ++++++ qemu-options.hx | 9 +++++++-- 6 files changed, 67 insertions(+), 7 deletions(-)Signature · 1 line
MSTHi Michael,
1) Command line option interface
Why is this not an optional cpu feature such as the other features?
-cpu CPU,+mwait
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
rather than a separate, architecture independent "-realtime cpu-pm=on|off" command line option?
Because it's not just a guest flag. With guest pm on, one guest can severely affect the latency of others on the same host CPU.
How so ?
Look at drivers/idle/intel_idle.c
There are states with exit latencies of
10000
Quoted 24 lines
Quoted 9 lines
Quoted 4 lines
2) Migration
Isnt it sufficient to check that both CPUID leafs are the same, to allow migration ?
Not at the moment since linux guests use mwait hints and latency values from a table in
intel_idle. If the host and guest models do not match, mwait will get a wrong hint.Quoted 5 lines
It will not do the right thing then!
You want exactly the same host CPU for it to work.
This isn't different from how -host cpu works generally.
Ok, makes sense.
Quoted 7 lines
Quoted 7 lines
1. Check that the processor supports MONITOR and MWAIT. If CPUID.01H:ECX.MONITOR[bit 3] = 1, MONITOR and MWAIT are available at ring 0.
2. Query the smallest and largest line size that MONITOR uses. Use CPUID.05H:EAX.smallest[bits 15:0];EBX.largest[bits15:0].
(Cc: Thomas Huth)
On Thu, Jun 14, 2018 at 09:18:00AM +0100, Daniel P. Berrangé wrote:
[...]
Quoted 8 lines
IMHO this really shouldn't be under the -realtime flag. I don't think the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it.
"-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
Given what you say above, then it sounds like the "-realtime" QEMU option should be deprecated, and removed in a future release.
[...]
Signature · 1 line
/kashyap
Quoted 15 lines · Kashyap Chamarthy
(Cc: Thomas Huth)
On Thu, Jun 14, 2018 at 09:18:00AM +0100, Daniel P. Berrangé wrote:
[...]
Quoted 8 lines
IMHO this really shouldn't be under the -realtime flag. I don't think the -realtime flag should ever have been introduced, and we certainly shouldn't add more stuff under it.
"-realtime" is referring to a very specific use case, while the properties listed under it are all general purpose features. Real time guests just happen to be one possible use case, but it is valid to use them for non-real time guests.
Quoted 5 lines
Given what you say above, then it sounds like the "-realtime" QEMU option should be deprecated, and removed in a future release.
[...]
As a patch on top, sure.
Quoted 2 lines
Signature · 1 line
/kashyap