[Qemu-devel] [PATCH v2 0/5] mc146818rtc: fix Windows VM clock faster

guangrong.xiao@gmail.com posted 5 patches 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170504115948.3048-1-xiaoguangrong@tencent.com
Test checkpatch failed
Test docker passed
Test s390x passed
There is a newer version of this series
hw/timer/mc146818rtc.c | 204 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 144 insertions(+), 60 deletions(-)
[Qemu-devel] [PATCH v2 0/5] mc146818rtc: fix Windows VM clock faster
Posted by guangrong.xiao@gmail.com 6 years, 11 months ago
From: Xiao Guangrong <xiaoguangrong@tencent.com>

Changelog in v2:
Thanks to Paolo's review, the changes in this version are:
1) merge patch 2, 3, 4 together
2) use a nice way ((value ^ new_value) & BIT_MASK) to check if updating
   for periodic timer is needed
3) use a smarter way to calculate coalesced irqs and lost_clock
4) make sure only x86 can enable LOST_TICK_POLICY_SLEW
5) make the code depends on LOST_TICK_POLICY_SLEW rather than
   TARGET_I386

We noticed that the clock on some windows VMs, e.g, Window7 and window8
is really faster and the issue can be easily reproduced by staring the
VM with '-rtc base=localtime,clock=vm,driftfix=slew -no-hpet' and 
running attached code in the guest

The root cause is that the clock will be lost if the periodic period is
changed as currently code counts the next periodic time like this:
      next_irq_clock = (cur_clock & ~(period - 1)) + period;

consider the case if cur_clock = 0x11FF and period = 0x100, then the
next_irq_clock is 0x1200, however, there is only 1 clock left to trigger
the next irq. Unfortunately, Windows guests (at least Windows7) change
the period very frequently if it runs the attached code, so that the
lost clock is accumulated, the wall-time become faster and faster

The main idea to fix the issue is we use a accurate clock period to
calculate the next irq:
    next_irq_clock = cur_clock + period;

After that, it is really convenient to compensate clock if it is needed 

The code running in windows VM is attached:
// TimeInternalTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#pragma comment(lib, "winmm")
#include <stdio.h>
#include <windows.h>

#define SWITCH_PEROID  13

int _tmain(int argc, _TCHAR* argv[])
{
	if (argc != 2)
	{
		printf("parameter error!\n");
		printf("USAGE: *.exe time(ms)\n");
		printf("example: *.exe 40\n");
		return 0;
	}
	else
	{
		DWORD internal = atoi((char *)argv[1]);
		DWORD count = 0;

		while (1)
		{
			count++;
			timeBeginPeriod(1);
			DWORD start = timeGetTime();
			Sleep(internal);
			timeEndPeriod(1);
			if ((count % SWITCH_PEROID) == 0) {
				Sleep(1);
			}
		}
	}
	return 0;
}

Tai Yunfang (1):
  mc146818rtc: precisely count the clock for periodic timer

Xiao Guangrong (4):
  mc146818rtc: update periodic timer only if it is needed
  mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on
    TARGET_I386
  mc146818rtc: drop unnecessary '#ifdef TARGET_I386'
  mc146818rtc: embrace all x86 specific code

 hw/timer/mc146818rtc.c | 204 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 144 insertions(+), 60 deletions(-)

-- 
2.9.3


Re: [Qemu-devel] [PATCH v2 0/5] mc146818rtc: fix Windows VM clock faster
Posted by no-reply@patchew.org 6 years, 11 months ago
Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PATCH v2 0/5] mc146818rtc: fix Windows VM clock faster
Message-id: 20170504115948.3048-1-xiaoguangrong@tencent.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20170504125432.21653-1-marcandre.lureau@redhat.com -> patchew/20170504125432.21653-1-marcandre.lureau@redhat.com
Switched to a new branch 'test'
f61e071 mc146818rtc: embrace all x86 specific code
dec1091 mc146818rtc: drop unnecessary '#ifdef TARGET_I386'
9d50ad1 mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on TARGET_I386
d192a0f mc146818rtc: precisely count the clock for periodic timer
21b28e7 mc146818rtc: update periodic timer only if it is needed

=== OUTPUT BEGIN ===
Checking PATCH 1/5: mc146818rtc: update periodic timer only if it is needed...
Checking PATCH 2/5: mc146818rtc: precisely count the clock for periodic timer...
ERROR: do not use assignment in if condition
#143: FILE: hw/timer/mc146818rtc.c:230:
+            if ((cur_irq_coalesced != s->irq_coalesced) ||

total: 1 errors, 0 warnings, 174 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 3/5: mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on TARGET_I386...
Checking PATCH 4/5: mc146818rtc: drop unnecessary '#ifdef TARGET_I386'...
Checking PATCH 5/5: mc146818rtc: embrace all x86 specific code...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org