Bug 1465938 - Timer/clocking improvements for Windows guests [NEEDINFO]
Timer/clocking improvements for Windows guests
Status: NEW
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: qemu-kvm-rhev (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Vadim Rozenfeld
Depends On:
  Show dependency treegraph
Reported: 2017-06-28 09:38 EDT by Ladi Prosek
Modified: 2018-06-20 22:27 EDT (History)
11 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
ailan: needinfo? (huding)

Attachments (Terms of Use)
CPU usage pictures (290.05 KB, application/zip)
2017-06-28 19:24 EDT, Vadim Rozenfeld
no flags Details

  None (edit)
Description Ladi Prosek 2017-06-28 09:38:37 EDT
Description of problem:
With the currently recommended CPU flags:

-cpu ...,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff

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:
outportb(0x70, 0x0C);

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)

How reproducible:

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

Actual results:
~450 VM exits a second
out of which ~290 are I/O exits

Expected results:
Fewer VM exits :)
Comment 2 Ladi Prosek 2017-06-28 09:57:48 EDT
Vadim pointed me to the WAET ACPI table, documented by Microsoft in:

I have tried providing this table to Windows guests using:

-acpitable sig=WAET,data=waet_data

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.
Comment 3 Ladi Prosek 2017-06-28 10:03:00 EDT
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.
Comment 4 Ladi Prosek 2017-06-28 10:36:25 EDT
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
Comment 7 Vadim Rozenfeld 2017-06-28 19:24 EDT
Created attachment 1292712 [details]
CPU usage pictures

Note You need to log in before you can comment on or make changes to this bug.