13 November 2013, 12:02 | #1 | ||
Registered User
Join Date: Jul 2008
Location: Netherlands
Posts: 485
|
Some findings on Windows timer functions accuracy, that may benefit WinUAE
Hi Toni,
A somewhat long post coming up, but please bear with me as it contains relevant information for WinUAE when it comes to the reliability of timer functions in Windows. While looking into this matter I found some interesting things about the (un)reliability of QueryPerformanceCounter and the High Precision Event Timer (HPET). I'll start with the bottom line conclusions and end with a suggestion for a possible solution for WinUAE (a suggestion since you'll know better). Bottom line conclusions on the (un)reliability of the timer function in Windows 1. The HPET hardware timer is disabled by default in Windows 7 (and possibly 8), even if a user has it enabled in the BIOS! Summarizing, apparently there where unexpected problems with the HPET implementation on motherboards a number of years ago, which apparently made Microsoft decide to disable the HPET timer alltogether on Windows 7. This even when you have a state of the art new motherboard with proper HPET implementation!
As shown in the blog, it's easily tested whether the HPET is really active by doing a query via QueryPerformanceFrequency. If it returns 14Mhz then it's enabled, if it's returning some value in the 3Mhz range then it's disabled. I'm using quite a new mainboard, an Asus P8Z77-V, running Windows 7 and guess what? The HPET is indeed disabled in Windows 7, even though I have set it to enabled in the BIOS. Quote:
2. QueryPerformanceCounter may perform poorly or unexpectedly leap forward Please see the following two pages by Microsoft, detailing the issues with QPC on some platforms / setups:
See also the following blog describing the poorly performing timing Beware of QueryPerformanceCounter() : http://www.virtualdub.org/blog/pivot/entry.php?id=106 Given this information, we now know that especially for some "older" systems the QPC method may perform poorly and why. My guess is that this may be causing some of the issues that people with older hardware setups may have with WinUAE's (low latency) vsync implementation. 3. Possible route to an improved timer implementation I've been thinking how this could be addressed from the software side. I guess one of the possible routes is to create an automated implementation: If QPF does return a value of 14Mhz (HPET is really active) then use QPC. Else use the more robust TimeGetTime() routine as a "second best" method. Even though the latter "only" has a resolution of 1ms, I guess it may be multiple times better than using a broken QPC. Of course automated implementations may have their drawbacks, so possibly a manual configuration option would be more desirable? When I look in my WinUAE log, while having HPET properly enabled as descibed previously, I see that its dividing the new found (correct) 14.32Mhz value by two. I'm not sure why that's done? Quote:
|
||
13 November 2013, 13:11 | #2 | ||
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,534
|
Quote:
Also I don't support broken hardware, buy a better PC is the correct choice! There is also small real world reason, fastest possible + low latency vsync requires timer resolution that is much less than length of 1 scanline. Quote:
|
||
13 November 2013, 15:03 | #3 | |||
Registered User
Join Date: Jul 2008
Location: Netherlands
Posts: 485
|
Quote:
Quote:
Quote:
I assume the HPET should be working at full resolution in the 64-bit WinUAE then? It would be great if you could address that, as currently it does the same division by two in 2.6.1 64-bit. Would that then also be the first -good- reason to start using the 64-bit version from now on then? ---------------------------------------------------------------------- WinUAE 2.6.1 (2013.06.19) 64-bit (6.1 Service Pack 1 [1]) 64-bit 9.6.3A09 8 10:15 [...] Reserved: 0x000007FF3FEB0000-0x000007FFFFFB0000 (c0100000 3073M) CLOCKFREQ: QPF 14.32MHz (7.16MHz, DIV=2) ---------------------------------------------------------------------- |
|||
13 November 2013, 17:25 | #4 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,534
|
It checks every few scanlines how big is the difference between emulated time and current time, if gap is big enough, some extra CPU time is emulated until times are back in sync.
Quote:
|
|
14 November 2013, 10:35 | #5 | |
Registered User
Join Date: Jul 2008
Location: Netherlands
Posts: 485
|
Quote:
Is it generally so that as long as the timer is accurate and has a resolution of at least a scanline, ~0.015Mhz, it's enough? |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Memwatch functions in Action Replay III don't work in WinUAE | Galahad/FLT | support.WinUAE | 12 | 11 May 2014 13:42 |
Benefit of 3.9 roms? | desantii | support.Hardware | 38 | 09 October 2013 08:36 |
[WinUAE/A500] CIA A - Timer A INT2 problem | leoha | Coders. Asm / Hardware | 2 | 22 October 2012 10:18 |
Lost F key Functions on WINuae startup | breadbaker | support.WinUAE | 8 | 06 December 2005 20:09 |
WinUAE blitter <-> bitplane DMA timing accuracy? | Photon | Coders. General | 1 | 24 November 2004 18:06 |
|
|