Timers, Timer Resolution, and Development of Efficient Code

Updated: June 16, 2010

File name: Timer-Resolution.docx
130 KB
Microsoft Word file
Get Office File Viewers

About This Download

This paper provides information about high-resolution timers and periodic timers for Windows operating systems. It provides guidelines for developers to use timers efficiently with platform power management. It assumes that the reader is familiar with concepts of periodic activity and scheduled timers.

This information applies to the following operating systems:
Windows Server 2008 R2
Windows 7

-------------------------------------

첨부파일의 중요 본문

·         Update the timer tick count if a full tick has elapsed.

·         Check whether a scheduled timer object has expired.

 

A timer tick is a notion of elapsed time that Windows uses to track the time of day and thread quantum times. By default, the clock interrupt and timer tick are the same, but Windows or an application can change the clock interrupt period.

The default timer resolution on Windows 7 is 15.6 milliseconds (ms). Some applications reduce this to 1 ms, which reduces the battery run time on mobile systems by as much as 25 percent.

Such a dramatic reduction in battery life is not desirable, yet the effect of changing timer resolution on desktop or server systems can be equally problematic. Decreased battery life on a mobile system makes increased power consumption visible. A system that is running on AC power incurs the same increased power usage, which may not be as simple to detect. The cost increase to a facility that has several thousand systems is significant.

=================================
출처: http://www.lucashale.com/timer-resolution/

Timer Resolution

TimerResolution is an application to change the resolution of the default windows timer. The standard timer on Windows XP can vary between 10 and 25 milliseconds. Therefore if your code uses a timer or sleep value less than the timer resolution on your system you won’t be getting the results you expect.

The timer resolution will be globally changed while the application is running and will revert to the previous value when it is closed.


Timer ResolutionVersion 1.2Version 2.0
OS Support Windows XP 32-bit Windows XP 32-bit, Vista 32-bit, Vista 64-bit, Windows7 32-bit, Windows7 64-bit
Maximum Resolution ~1.0ms (depends on OS and Hardware) ~0.5ms (depends on OS and Hardware)
Command Line Functions None TimerResolution [-max] [-hide]
-max : Sets timer period to the maximum (fastest) value
-hide : Hides the GUI window
Price Free AUD$10.00
Download TimerResolution.zip (7 kb)


Timer Resolution XP Timer Resolution Windows 7

[Download] TimerResolution.zip (7Kb) Limited Free Version 1.2


How did this application get created?

I had a need for a program to run every 5 milliseconds but I found that no matter what I did the best I could get was 12ms. I tried different values for my timer and found that a value above 12ms would also produce results with jitter up to 12ms. What was so special about 12ms? I tried a different computer and found that the magic value was 15ms… what was windows doing? Time to Google the answer.

I left the program running to see if the value changed with time or CPU load. Suddenly the program started to produce 5ms results with very little jitter! By trial and error I found that if I loaded a particular web page the program worked as expected. What was so special about this page? It turns out that it had a Flash based advertisement on it so I had my next clue. As a guess I closed the web page and started Media Player and got the same result. It seems that when an application requests a high resolution timer for multimedia purposes it changes the resolution of the timer for the entire system.

So now I had a solution but it required linking to the winmm.lib which as a programmer didn’t sit well with me since my application had nothing to do with multimedia. A little more research and I was onto the undocumented native API. Now I had the lightweight solution I was looking for. I hope you find that the program answers some questions for you. I’ve found that it can improve the performance and responsiveness of all sorts of applications.

Chromium Project uses Timer Resolution to debug battery life issue
Lag Free Counter Strike?
Nokia uses TimerResolution for LTE Network Tuning

Useful Links on the Windows Timers
MSDN – Windows Multimedia SDK Obtaining and Setting Timer Resolution
The Code Project – Timers tutorial – System

Note: This page was located at http://users.tpg.com.au/lucash/ until October 2007 when it moved to its new home here


https://code.google.com/p/chromium/issues/detail?id=46531
http://www.shoot-em.com/forum/viewtopic.php?t=3981
http://forums.guru3d.com/showthread.php?t=332395#2
http://forums.guru3d.com/showthread.php?t=327922
http://forums.steampowered.com/forums/showthread.php?t=1315790
http://forums.guru3d.com/showthread.php?p=3812261#post3812261
http://forums.guru3d.com/showthread.php?p=3770113#post3770113
http://forums.electronicarts.co.uk/battlefield-bad-company-2-pc/1273328-performance-tweaks-6.html#post18878023
http://forums.electronicarts.co.uk/battlefield-bad-company-2-pc/1273328-performance-tweaks.html
http://forums.steampowered.com/forums/showthread.php?p=19491040#post19491040




'Programming' 카테고리의 다른 글

[펌] [C++]STL  (0) 2012.01.15
[펌] BugTrap 상세 설명  (2) 2011.11.30
[펌] BugTrap 설정시 문제점들...  (0) 2011.11.30
Posted by 세모아
,