Skip to contentSkip to conversation

Host latency peaks due to kvm-intel

DISCUSSION Jan Kiszka 7 participants 18 messages Jul 23, 2009 – Jul 27, 2009

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

Hi,

did anyone recently tried current KVM for Intel over some real-time Linux? I'm seeing more than 500 us latency peaks on the host, specifically during VM startup. This applies to both 2.6.29.6-rt23 and Xenomai/I-pipe. For -rt, I both tried the included (patched) KVM modules as well as kvm.git head with some additionally required -rt fixes. Xenomai ran over a 2.6.30 kernel with my own KVM-enabler patch.

Early instrumentation actually points to the guest exit itself: I added markers right before and after the assembly part of vmx_vcpu_run, and further instrumentation reports that the next host APIC tick should go off right inside guest mode. But KVM leaves the switching part 500 us too late in that case - as if guest exit on external IRQs was disabled.

Will debug this further, but I'm also curious to hear other user experiences.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#1 lore raw
Quoted 15 lines · Jan Kiszka

Hi,

did anyone recently tried current KVM for Intel over some real-time Linux? I'm seeing more than 500 us latency peaks on the host, specifically during VM startup. This applies to both 2.6.29.6-rt23 and Xenomai/I-pipe. For -rt, I both tried the included (patched) KVM modules as well as kvm.git head with some additionally required -rt fixes. Xenomai ran over a 2.6.30 kernel with my own KVM-enabler patch.

Early instrumentation actually points to the guest exit itself: I added markers right before and after the assembly part of vmx_vcpu_run, and further instrumentation reports that the next host APIC tick should go off right inside guest mode. But KVM leaves the switching part 500 us too late in that case - as if guest exit on external IRQs was disabled.

Quoted 6 lines

Will debug this further, but I'm also curious to hear other user experiences.

Jan

Hi Jan,
Did you try to run with latency-tracer enabled? If not, this may
pinpoint the source for you.

Regards,
-Greg

author
#2 lore raw
Quoted 19 lines · Gregory Haskins
Quoted 18 lines · Jan Kiszka

Hi,

did anyone recently tried current KVM for Intel over some real-time Linux? I'm seeing more than 500 us latency peaks on the host, specifically during VM startup. This applies to both 2.6.29.6-rt23 and Xenomai/I-pipe. For -rt, I both tried the included (patched) KVM modules as well as kvm.git head with some additionally required -rt fixes. Xenomai ran over a 2.6.30 kernel with my own KVM-enabler patch.

Early instrumentation actually points to the guest exit itself: I added markers right before and after the assembly part of vmx_vcpu_run, and further instrumentation reports that the next host APIC tick should go off right inside guest mode. But KVM leaves the switching part 500 us too late in that case - as if guest exit on external IRQs was disabled.

Will debug this further, but I'm also curious to hear other user experiences.

Quoted 6 lines
Quoted 3 lines

Jan

Hi Jan,
Did you try to run with latency-tracer enabled? If not, this may
pinpoint the source for you.

I did, see above.

It finally turned out that I got burned once again by wbinvd: My test CPUs (and likely also some of my customer) are too "old" to support SECONDARY_VM_EXEC_CONTROL, which includes trapping guest's wbinvd invocations. Too bad.

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Jan (who is now patching his guest to avoid wbinvd where possible)

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 26 lines · Jan Kiszka
Quoted 24 lines · Gregory Haskins
Quoted 22 lines · Jan Kiszka

Hi,

did anyone recently tried current KVM for Intel over some real-time Linux? I'm seeing more than 500 us latency peaks on the host, specifically during VM startup. This applies to both 2.6.29.6-rt23 and Xenomai/I-pipe. For -rt, I both tried the included (patched) KVM modules as well as kvm.git head with some additionally required -rt fixes. Xenomai ran over a 2.6.30 kernel with my own KVM-enabler patch.

Early instrumentation actually points to the guest exit itself: I added markers right before and after the assembly part of vmx_vcpu_run, and further instrumentation reports that the next host APIC tick should go off right inside guest mode. But KVM leaves the switching part 500 us too late in that case - as if guest exit on external IRQs was disabled.

Will debug this further, but I'm also curious to hear other user experiences.

Jan

Quoted 7 lines
Quoted 4 lines

Hi Jan,
Did you try to run with latency-tracer enabled? If not, this may
pinpoint the source for you.

I did, see above.

Ah, sorry. It wasn't clear what "instrumenation" was or if you felt it was definitively pinpointed. :P

Regards,
-Greg

#4 lore raw
In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#5 lore raw
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Quoted 3 lines

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

------------>

From: Jan Kiszka <[email protected]>
Subject: [PATCH] x86: Report VMX feature vwbinvd

Not all VMX-capable CPUs support guest exists on wbinvd execution. If this is not supported, the instruction will run natively on behalf of the guest. This can cause multi-millisecond latencies to the host which is very problematic in real-time scenarios.

Report the wbinvd trapping feature along with other VMX feature flags, calling it 'vwbinvd' ('virtual wbinvd').

---

 arch/x86/include/asm/cpufeature.h |    1 +
 arch/x86/kernel/cpu/intel.c       |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/include/asm/cpufeature.h +1 -0
index 4a28d22..8647524 100644
@@ -165,6 +165,7 @@
 #define X86_FEATURE_FLEXPRIORITY (8*32+ 2) /* Intel FlexPriority */
 #define X86_FEATURE_EPT         (8*32+ 3) /* Intel Extended Page Table */
 #define X86_FEATURE_VPID        (8*32+ 4) /* Intel Virtual Processor ID */
+#define X86_FEATURE_VWBINVD     (8*32+ 5) /* Guest Exiting on WBINVD */
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 
arch/x86/kernel/cpu/intel.c +4 -0
index 3260ab0..2d921b0 100644
@@ -297,6 +297,7 @@ static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
 #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC	0x00000001
 #define X86_VMX_FEATURE_PROC_CTLS2_EPT		0x00000002
 #define X86_VMX_FEATURE_PROC_CTLS2_VPID		0x00000020
+#define X86_VMX_FEATURE_PROC_CTLS2_VWBINVD	0x00000040
 
 	u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
 
@@ -305,6 +306,7 @@ static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
 	clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
 	clear_cpu_cap(c, X86_FEATURE_EPT);
 	clear_cpu_cap(c, X86_FEATURE_VPID);
+	clear_cpu_cap(c, X86_FEATURE_VWBINVD);
 
 	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
 	msr_ctl = vmx_msr_high | vmx_msr_low;
@@ -323,6 +325,8 @@ static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
 			set_cpu_cap(c, X86_FEATURE_EPT);
 		if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
 			set_cpu_cap(c, X86_FEATURE_VPID);
+		if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VWBINVD)
+			set_cpu_cap(c, X86_FEATURE_VWBINVD);
 	}
 }
 
#6 lore raw
Quoted 24 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Quoted 4 lines

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

------------>

From: Jan Kiszka<[email protected]>
Subject: [PATCH] x86: Report VMX feature vwbinvd

Quoted 9 lines

Not all VMX-capable CPUs support guest exists on wbinvd execution. If this is not supported, the instruction will run natively on behalf of the guest. This can cause multi-millisecond latencies to the host which is very problematic in real-time scenarios.

Report the wbinvd trapping feature along with other VMX feature flags, calling it 'vwbinvd' ('virtual wbinvd').

What about AMD cpus that can always trap wbinvd? do we set the bit or do we trust the user to know that it isn't needed on AMD (I suppose the latter)?

This should go in via tip.git, it isn't really kvm related (except that kvm should start reading these caps one day instead of querying the hardware directly).

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#7 lore raw
Quoted 32 lines · Avi Kivity
Quoted 31 lines · Jan Kiszka
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs
as there seem to be many of them out there with restrictions for special
use cases - like real-time.

Quoted 4 lines

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

------------>

From: Jan Kiszka<[email protected]>
Subject: [PATCH] x86: Report VMX feature vwbinvd

Not all VMX-capable CPUs support guest exists on wbinvd execution. If this is not supported, the instruction will run natively on behalf of the guest. This can cause multi-millisecond latencies to the host which is very problematic in real-time scenarios.

Quoted 8 lines
Quoted 4 lines

Report the wbinvd trapping feature along with other VMX feature flags, calling it 'vwbinvd' ('virtual wbinvd').

What about AMD cpus that can always trap wbinvd? do we set the bit or do we trust the user to know that it isn't needed on AMD (I suppose the latter)?

I also think that the feature flags should remain vendor-specific.

Quoted 5 lines

This should go in via tip.git, it isn't really kvm related (except that kvm should start reading these caps one day instead of querying the hardware directly).

OK, will go that way. Probably I will also add some flags for AMD's NPT, Intel's EPT and they new unrestricted guest mode at this chance.

Jan

#8 lore raw
In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Quoted 6 lines
Quoted 3 lines

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

Fine with me.

However, I guess the real question if we shouldn't export ALL VMX features in a consistent way instead?

-hpa

#9 lore raw
Quoted 13 lines · On Monday 27 July 2009 03:16:27 H. Peter Anvin wrote:
Quoted 12 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 6 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Quoted 9 lines
Quoted 1 line

Ah, nice. Then we just need this?

Fine with me.

However, I guess the real question if we shouldn't export ALL VMX features in a consistent way instead?

When I add feature reporting to cpuinfo, I just put highlight features there, otherwise the VMX feature list would at least as long as CPU one.

I have also suggested another field for virtualization feature for it, but some concern again userspace tools raised.

For we got indeed quite a lot features, and would get more, would it better to export the part of struct vmcs_config entries(that's pin_based_exec_ctrl, cpu_based_exec_ctrl, and cpu_based_2nd_exec_ctrl) through sys/module/kvm_intel/? Put every feature to cpuinfo seems not that necessary for such a big list.

Signature · 2 lines
regards
Yang, Sheng
author
#10 lore raw

cpuinfo and HVM features (was: Host latency peaks due to kvm-intel)

[ carrying this to LKML ]

Quoted 15 lines · Sheng
Quoted 14 lines · On Monday 27 July 2009 03:16:27 H. Peter Anvin wrote:
Quoted 11 lines · Jan Kiszka
Quoted 9 lines · Avi Kivity
Quoted 6 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

Fine with me.

Quoted 7 lines
Quoted 5 lines

However, I guess the real question if we shouldn't export ALL VMX features in a consistent way instead?

When I add feature reporting to cpuinfo, I just put highlight features there, otherwise the VMX feature list would at least as long as CPU one.

That could become true. But the question is always what the highlights are. Often this depends on the hypervisor as it may implement workarounds for missing features differently (or not at all). So I'm also for exposing feature information consistently.

Quoted 9 lines

I have also suggested another field for virtualization feature for it, but some concern again userspace tools raised.

For we got indeed quite a lot features, and would get more, would it better to export the part of struct vmcs_config entries(that's pin_based_exec_ctrl, cpu_based_exec_ctrl, and cpu_based_2nd_exec_ctrl) through sys/module/kvm_intel/? Put every feature to cpuinfo seems not that necessary for such a big list.

I don't think this information should only come from KVM. Consider you didn't build it into some kernel but still want to find out what your system is able to provide.

What about adding some dedicated /proc entry for CPU virtualization features, say /proc/hvminfo?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#11 lore raw

Re: cpuinfo and HVM features (was: Host latency peaks due to kvm-intel)

Quoted 26 lines · On Monday 27 July 2009 17:08:42 Jan Kiszka wrote:

[ carrying this to LKML ]

Quoted 23 lines · Sheng
Quoted 21 lines · On Monday 27 July 2009 03:16:27 H. Peter Anvin wrote:
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 6 lines · Jan Kiszka

I vaguely recall that someone promised to add a feature reporting facility for all those nice things, modern VM-extensions may or may not support (something like or even an extension of /proc/cpuinfo). What is the state of this plan? Would be specifically interesting for Intel CPUs as there seem to be many of them out there with restrictions for special use cases - like real-time.

Quoted 4 lines
Quoted 2 lines

Newer kernels do report some vmx features (like flexpriority) in /proc/cpuinfo but not all.

Ah, nice. Then we just need this?

Fine with me.

However, I guess the real question if we shouldn't export ALL VMX features in a consistent way instead?

Quoted 7 lines
Quoted 2 lines

When I add feature reporting to cpuinfo, I just put highlight features there, otherwise the VMX feature list would at least as long as CPU one.

That could become true. But the question is always what the highlights are. Often this depends on the hypervisor as it may implement workarounds for missing features differently (or not at all). So I'm also for exposing feature information consistently.

(CC Andi and Ingo)

The highlight means the feature we would gain a lot, like FlexPriority, EPT, VPID. They can be vendor specific. And I am talking about hardware capability here, so what's hypervisor did for workaround is not in scope.

Quoted 11 lines
Quoted 10 lines

I have also suggested another field for virtualization feature for it, but some concern again userspace tools raised.

For we got indeed quite a lot features, and would get more, would it better to export the part of struct vmcs_config entries(that's pin_based_exec_ctrl, cpu_based_exec_ctrl, and cpu_based_2nd_exec_ctrl) through
sys/module/kvm_intel/? Put every feature to cpuinfo seems not that necessary for such a big list.

Quoted 3 lines

I don't think this information should only come from KVM. Consider you didn't build it into some kernel but still want to find out what your system is able to provide.

Yes, agree.

Quoted 3 lines

What about adding some dedicated /proc entry for CPU virtualization features, say /proc/hvminfo?

Well, compared to this, I may still prefer a new item in /proc/cpuinfo, for it's still CPU feature, like Andi did for power management(IIRC).

Any more preferred location?

Signature · 2 lines
regards
Yang, Sheng
#12 lore raw

Re: cpuinfo and HVM features

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 3 lines

When I add feature reporting to cpuinfo, I just put highlight features there, otherwise the VMX feature list would at least as long as CPU one.

That could become true. But the question is always what the highlights are. Often this depends on the hypervisor as it may implement workarounds for missing features differently (or not at all). So I'm also for exposing feature information consistently.

I'd put everything in there. It's information that is often useful. Even minor features can expose bugs in the hypervisor.

Quoted 10 lines
Quoted 9 lines

I have also suggested another field for virtualization feature for it, but some concern again userspace tools raised.

For we got indeed quite a lot features, and would get more, would it better to export the part of struct vmcs_config entries(that's pin_based_exec_ctrl, cpu_based_exec_ctrl, and cpu_based_2nd_exec_ctrl) through sys/module/kvm_intel/? Put every feature to cpuinfo seems not that necessary for such a big list.

Quoted 7 lines

I don't think this information should only come from KVM. Consider you didn't build it into some kernel but still want to find out what your system is able to provide.

What about adding some dedicated /proc entry for CPU virtualization features, say /proc/hvminfo?

The flags line is already very long, and already has some virt features, so I see no problem extending it. If we don't want that. I'd prefer a virtualization line in /proc/cpuinfo rather than a new file.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#13 lore raw
In reply to Jan Kiszka
Quoted 3 lines · Jan Kiszka

Jan (who is now patching his guest to avoid wbinvd where possible)

Is there ever a case where it is required? What about under a hypervisor (i.e. check the hypervisor enabled bit).

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#14 lore raw
Quoted 2 lines

Do not meddle in the internals of kernels, for they are subtle and quick to panic.

Also the kvm code. Are you sure that the processor supports KVM Extension. I know of a lot of intel architectures where KVM is not support. Especially the HW_CHECK_SUM. Might not be sure, but this sure seems an problem. Also there is no dependency check with the KVM on Linux. What I mean by this is that KVM Install on an Architecture that donot support the extension without problem. So compiling KVM alone does not mean it works on an architecture.

Signature · 3 lines
-- Sujit K M

blog(http://kmsujit.blogspot.com/)
#15 lore raw
In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 3 lines · Jan Kiszka

Jan (who is now patching his guest to avoid wbinvd where possible)

Is there ever a case where it is required? What about under a hypervisor (i.e. check the hypervisor enabled bit).

Reminds me of the discussion in '07 when I first stumbled over this :) :
Yes, the bochs bios could safely skip the wbinvd in qemu mode. But that won't safe us from Linux and - far more problematic - Windows or any binary-only guest which think they have to issue it.

One may the close eyes, fire up the guest and then start the time-critical host application in the hope that the guest remains calm as long as it's up and running. But, well...

Jan

#16 lore raw
Quoted 13 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 4 lines · Jan Kiszka

Jan (who is now patching his guest to avoid wbinvd where possible)

Is there ever a case where it is required? What about under a hypervisor (i.e. check the hypervisor enabled bit).

Quoted 9 lines

Reminds me of the discussion in '07 when I first stumbled over this :) :
Yes, the bochs bios could safely skip the wbinvd in qemu mode. But that won't safe us from Linux and - far more problematic - Windows or any binary-only guest which think they have to issue it.

One may the close eyes, fire up the guest and then start the time-critical host application in the hope that the guest remains calm as long as it's up and running. But, well...

Given that it's now '09, how critical is the problem? Don't most cpus have vwbinvd now?

If so, the real-time management application can simply refuse to run on such an old processor.

Signature · 1 line
error compiling committee.c: too many arguments to function
#17 lore raw
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 4 lines · Jan Kiszka

Jan (who is now patching his guest to avoid wbinvd where possible)

Is there ever a case where it is required? What about under a hypervisor (i.e. check the hypervisor enabled bit).

Reminds me of the discussion in '07 when I first stumbled over this :) :
Yes, the bochs bios could safely skip the wbinvd in qemu mode. But that won't safe us from Linux and - far more problematic - Windows or any binary-only guest which think they have to issue it.

Quoted 7 lines
Quoted 4 lines

One may the close eyes, fire up the guest and then start the time-critical host application in the hope that the guest remains calm as long as it's up and running. But, well...

Given that it's now '09, how critical is the problem? Don't most cpus have vwbinvd now?

Sadly, in (embedded) industry you have to live with "old" hardware for quite a long time. And I would have to throw my only 2-years-old notebook from the table to have a more decent portable test environment.

Quoted 4 lines

If so, the real-time management application can simply refuse to run on such an old processor.

At least one could go and collect the cpuinfo from some box that suffers from high latencies. Normally, you go through extensive testing anyway, also checking for issues like crazy SMI BIOS code that runs for eternities.

Jan