All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] mc146818rtc: fix Windows VM clock faster
@ 2017-04-12  9:51 ` guangrong.xiao
  0 siblings, 0 replies; 59+ messages in thread
From: guangrong.xiao @ 2017-04-12  9:51 UTC (permalink / raw)
  To: pbonzini, mst, mtosatti; +Cc: qemu-devel, kvm, yunfangtai, Xiao Guangrong

From: Xiao Guangrong <xiaoguangrong@tencent.com>

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: properly count the time for the next interrupt

Xiao Guangrong (4):
  mc146818rtc: update periodic timer only if it is needed
  mc146818rtc: fix clock lost after scaling coalesced irq
  mc146818rtc: move x86 specific code out of periodic_timer_update
  mc146818rtc: embrace all x86 specific code

 hw/timer/mc146818rtc.c | 370 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 272 insertions(+), 98 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2017-05-04 12:02 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12  9:51 [PATCH 0/5] mc146818rtc: fix Windows VM clock faster guangrong.xiao
2017-04-12  9:51 ` [Qemu-devel] " guangrong.xiao
2017-04-12  9:51 ` [PATCH 1/5] mc146818rtc: update periodic timer only if it is needed guangrong.xiao
2017-04-12  9:51   ` [Qemu-devel] " guangrong.xiao
2017-05-03 15:42   ` Paolo Bonzini
2017-05-03 15:42     ` [Qemu-devel] " Paolo Bonzini
2017-05-04  3:27     ` Xiao Guangrong
2017-05-04  3:27       ` [Qemu-devel] " Xiao Guangrong
2017-04-12  9:51 ` [PATCH 2/5] mc146818rtc: fix clock lost after scaling coalesced irq guangrong.xiao
2017-04-12  9:51   ` [Qemu-devel] " guangrong.xiao
2017-05-03 15:15   ` Paolo Bonzini
2017-05-03 15:15     ` [Qemu-devel] " Paolo Bonzini
2017-05-04  2:51     ` Xiao Guangrong
2017-05-04  2:51       ` [Qemu-devel] " Xiao Guangrong
2017-04-12  9:51 ` [PATCH 3/5] mc146818rtc: properly count the time for the next interrupt guangrong.xiao
2017-04-12  9:51   ` [Qemu-devel] " guangrong.xiao
2017-05-03 15:32   ` Paolo Bonzini
2017-05-03 15:32     ` [Qemu-devel] " Paolo Bonzini
2017-05-04  2:54     ` Xiao Guangrong
2017-05-04  2:54       ` [Qemu-devel] " Xiao Guangrong
2017-05-04 12:02       ` Paolo Bonzini
2017-05-04 12:02         ` [Qemu-devel] " Paolo Bonzini
2017-04-12  9:51 ` [PATCH 4/5] mc146818rtc: move x86 specific code out of periodic_timer_update guangrong.xiao
2017-04-12  9:51   ` [Qemu-devel] " guangrong.xiao
2017-05-03 15:39   ` Paolo Bonzini
2017-05-03 15:39     ` [Qemu-devel] " Paolo Bonzini
2017-05-04  3:25     ` Xiao Guangrong
2017-05-04  3:25       ` [Qemu-devel] " Xiao Guangrong
2017-05-04  7:08       ` Paolo Bonzini
2017-05-04  7:08         ` [Qemu-devel] " Paolo Bonzini
2017-04-12  9:51 ` [PATCH 5/5] mc146818rtc: embrace all x86 specific code guangrong.xiao
2017-04-12  9:51   ` [Qemu-devel] " guangrong.xiao
2017-04-13  6:37 ` [PATCH 0/5] mc146818rtc: fix Windows VM clock faster Paolo Bonzini
2017-04-13  6:37   ` [Qemu-devel] " Paolo Bonzini
2017-04-13  8:39   ` Xiao Guangrong
2017-04-13  8:39     ` [Qemu-devel] " Xiao Guangrong
2017-04-13  8:52     ` Xiao Guangrong
2017-04-13  8:52       ` [Qemu-devel] " Xiao Guangrong
2017-04-13  9:05       ` 答复: " Zhanghailiang
2017-04-13  9:05         ` [Qemu-devel] " Zhanghailiang
2017-04-13  9:18         ` Xiao Guangrong
2017-04-13  9:18           ` [Qemu-devel] " Xiao Guangrong
2017-04-13  9:29           ` Hailiang Zhang
2017-04-13  9:29             ` [Qemu-devel] " Hailiang Zhang
2017-04-13  9:35             ` Xiao Guangrong
2017-04-13  9:35               ` [Qemu-devel] " Xiao Guangrong
2017-04-13  9:38               ` Hailiang Zhang
2017-04-13  9:38                 ` [Qemu-devel] " Hailiang Zhang
2017-04-19  2:02                 ` Xiao Guangrong
2017-04-19  2:02                   ` [Qemu-devel] " Xiao Guangrong
2017-04-19 10:41                   ` Hailiang Zhang
2017-04-19 10:41                     ` [Qemu-devel] " Hailiang Zhang
2017-04-19 11:13                     ` Xiao Guangrong
2017-04-19 11:13                       ` [Qemu-devel] " Xiao Guangrong
2017-04-19 16:44                       ` Paolo Bonzini
2017-04-19 16:44                         ` [Qemu-devel] " Paolo Bonzini
2017-04-14  5:09       ` Paolo Bonzini
2017-04-14  5:09         ` [Qemu-devel] " Paolo Bonzini
2017-04-14  6:07         ` Xiao Guangrong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.