Red Hat Bugzilla – Bug 1465938
Timer/clocking improvements for Windows guests
Last modified: 2017-11-21 09:13:01 EST
Description of problem:
With the currently recommended CPU flags:
modern Windows guests use the Hyper-V TSC page as a timestamp source and the RTC chip (MC146818) for timer interrupts.
The TSC page is fine but the RTC chip doesn't have a virt-friendly access protocol. One timer interrupt usually costs four extra VM exits as Windows executes this sequence twice:
the first inportb returns the contents of register C (usually 0xC0 - periodic timer interrupt) and clears it. Second inportb returns 0.
Version-Release number of selected component (if applicable):
kernel-3.10.0-686.el7 or 4.10.11 upstream
qemu-kvm-rhev-2.9.0-12.el7 or 2.9 upstream
Windows Server 2016 (en_windows_server_2016_x64_dvd_9327751.iso)
Steps to Reproduce:
1. Install Windows Server 2016 with -cpu ...,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff
2. Wait for it to become idle
3. Watch VM exit statistics using e.g. kvm_stat
~450 VM exits a second
out of which ~290 are I/O exits
Fewer VM exits :)
Vadim pointed me to the WAET ACPI table, documented by Microsoft in:
I have tried providing this table to Windows guests using:
where waet_data is four bytes long and contains 0x01, 0x00, 0x00, 0x00.
Windows Vista and Win7 really picks it up but fails to boot because the MC146818 implementation in QEMU is not compatible with the "RTC good" flag.
Newer Windows completely ignores the "RTC good" flag. This has been verified by disassembling hal.dll.
Even new Windows seem to pick up the other documented flag "ACPI PM timer good". Windows uses it only for HW detection and not for actual PM timer reads though. Even if it affected PM timer reads, it is of dubious value as Windows correctly prefers the TSC MSR / TSC page if available and doesn't use the PM timer except during boot.
We should consider adding hv_synic,hv_stimer to the recommended cpu flags for Windows guests. Using the synthetic timer instead of RTC chip significantly reduces the number of VM exits.
RTC timer: ~450 VM exits/second
Synthetic timer: ~130 exits/second
Created attachment 1292712 [details]
CPU usage pictures