Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1465938

Summary: Timer/clocking improvements for Windows guests
Product: Red Hat Enterprise Linux 7 Reporter: Ladi Prosek <lprosek>
Component: qemu-kvm-rhevAssignee: Vadim Rozenfeld <vrozenfe>
Status: CLOSED CURRENTRELEASE QA Contact: FuXiangChun <xfu>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.4CC: ailan, chayang, juzhang, knoel, michen, mtosatti, siliu, virt-maint, vrozenfe, wyu, xfu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-08-02 06:39:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
CPU usage pictures none

Description Ladi Prosek 2017-06-28 13:38:37 UTC
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);
inportb(0x71);

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:
100%

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 13:57:48 UTC
Vadim pointed me to the WAET ACPI table, documented by Microsoft in:
https://msdn.microsoft.com/en-us/windows/hardware/gg487524.aspx

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 14:03:00 UTC
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 14:36:25 UTC
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 23:24:10 UTC
Created attachment 1292712 [details]
CPU usage pictures

Comment 30 Vadim Rozenfeld 2018-08-02 06:39:15 UTC
Backport Hyper-V TSC page enlightenment support
(https://bugzilla.redhat.com/show_bug.cgi?id=1504524)
should significantly improve (Ke)QueryPerformanceCount performance.
There is no any other option to make it working better at the moment.

Closing this bug as CURRENTRELEASE.

Best regards,
Vadim.

Comment 31 Red Hat Bugzilla 2023-09-14 04:00:02 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 1000 days