Re: [PATCH v4 0/3] KVM: Dynamic Halt-Polling

From: Wanpeng Li
Date: Mon Aug 31 2015 - 03:44:47 EST

On 8/30/15 6:26 AM, Peter Kieser wrote:
Thanks, Wanpeng. Applied this to Linux 3.18 and seeing much higher CPU
usage (200%) for qemu 2.4.0 process on a Windows 10 x64 guest. qemu

Interesting. I test this against latest kvm tree and stable qemu 2.0.0, 4 vCPUs on pCPU0(other pCPUs are offline to easy observe %C0 and to avoid vCPUs schedule overhead influence). I just ignore the fluctuation and post the most common result of %C0 against the Windows 10 x86 guest.

| | | |
| w/o halt-poll | w/ halt-poll | dynamic(v4) halt-poll |
| | | |
| ~2.1% | ~3.0% | ~2.4% |

Wanpeng Li

qemu-system-x86_64 -enable-kvm -name arwan-20150704 -S -machine
pc-q35-2.2,accel=kvm,usb=off -cpu
Haswell,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1000 -m 8192
-realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid
7c2fc02d-2798-4fc9-ad04-db5f1af92723 -no-user-config -nodefaults
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime
-no-shutdown -boot strict=on -device
i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e -device
pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x1 -device
nec-usb-xhci,id=usb1,bus=pci.2,addr=0x4 -device
virtio-serial-pci,id=virtio-serial0,bus=pci.2,addr=0x5 -drive
-netdev tap,fds=31:32:33:34,id=hostnet0,vhost=on,vhostfds=35:36:37:38
-chardev spicevmc,id=charchannel1,name=vdagent -device
-vnc -device
-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x1 -msg

I revert patch, qemu shows 17% CPU usage on host. Thoughts?


On 2015-08-29 3:21 PM, Wanpeng Li wrote:
Hi Peter,
On 8/30/15 5:18 AM, Peter Kieser wrote:
Hi Wanpeng,

Do I need to set any module parameters to use your patch, or should
halt_poll_ns automatically tune with just your patch series applied?

You don't need any module parameters.

Wanpeng Li


On 2015-08-27 2:47 AM, Wanpeng Li wrote:
v3 -> v4:
* bring back grow vcpu->halt_poll_ns when interrupt arrives and
when idle VCPU is detected

v2 -> v3:
* grow/shrink vcpu->halt_poll_ns by *halt_poll_ns_grow or
* drop the macros and hard coding the numbers in the param
* update the comments "5-7 us"
* remove halt_poll_ns_max and use halt_poll_ns as the max
halt_poll_ns time,
vcpu->halt_poll_ns start at zero
* drop the wrappers
* move the grow/shrink logic before "out:" w/ "if (waited)"

v1 -> v2:
* change kvm_vcpu_block to read halt_poll_ns from the vcpu
instead of
the module parameter
* use the shrink/grow matrix which is suggested by David
* set halt_poll_ns_max to 2ms

There is a downside of halt_poll_ns since poll is still happen for
VCPU which can waste cpu usage. This patchset add the ability to
halt_poll_ns dynamically, grows halt_poll_ns if an interrupt
arrives and
shrinks halt_poll_ns when idle VCPU is detected.

There are two new kernel parameters for changing the halt_poll_ns:
halt_poll_ns_grow and halt_poll_ns_shrink.

Test w/ high cpu overcommit ratio, pin vCPUs, and the halt_poll_ns of
halt-poll is the default 500000ns, the max halt_poll_ns of dynamic
halt-poll is 2ms. Then watch the %C0 in the dump of Powertop tool.
The test method is almost from David.

| | | |
| w/o halt-poll | w/ halt-poll | dynamic halt-poll |
| | | |
| ~0.9% | ~1.8% | ~1.2% |
The always halt-poll
will increase ~0.9% cpu usage for idle vCPUs and the
dynamic halt-poll drop it to ~0.3% which means that reduce the 67%
introduced by always halt-poll.

Wanpeng Li (3):
KVM: make halt_poll_ns per-VCPU
KVM: dynamic halt_poll_ns adjustment
KVM: trace kvm_halt_poll_ns grow/shrink

include/linux/kvm_host.h | 1 +
include/trace/events/kvm.h | 30 ++++++++++++++++++++++++++++
virt/kvm/kvm_main.c | 50
3 files changed, 78 insertions(+), 3 deletions(-)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at