2

It might be obvious, but I can't find/google the correct method to get the current system value of the timer resolution, which a program can set by timeBeginPeriod(n)/timeEndPeriod(n). I want to find out what's the current resolution... The Windows 7 default value seems to be 15.6 ms, but other applications or the machine vendor might have changed the setting.

There are some tools which report the value, but I need to read the value in an application.

Thanks for any quick hint or link. C# would be a plus, but I know my way around with P/Invoke.

EDIT: Thanks to the answer I've made a little tool in C# which uses the described method: github.com/tebjan/TimerTool

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
thalm
  • 2,738
  • 2
  • 35
  • 49
  • yes, i have seen this thread, but there is no answer to the actual problem... – thalm Jan 21 '14 at 16:18
  • That may be true, but the idea of flagging questions as duplicates is to try to keep all the answers (good and bad) together in one place. You can perhaps choose to offer a bounty on the original question rather than asking the same thing again. – Roger Rowland Jan 21 '14 at 16:20
  • that sounds good, i was not familiar with this concept. can i offer a bounty even if it wasn't my question? – thalm Jan 21 '14 at 16:24
  • See this: http://www.geisswerks.com/ryan/FAQS/timing.html ... it finds out the granularity of timeGetTime for you. Also see this for further explanation: http://forum.sysinternals.com/bug-in-waitable-timers_topic16229.html – Colin Smith Jan 21 '14 at 16:27
  • Yes you can offer a bounty on any question. There's even a special badge for doing so :-) – Roger Rowland Jan 21 '14 at 16:38
  • done! @colinsmith thanks, but this does not really help, the article uses brute force methods and shows no in depth winapi knowledge. – thalm Jan 21 '14 at 16:44
  • damn missed that bounty – Arno Jan 21 '14 at 17:04
  • @Arno no problem, i'll award you as soon as i can... :) – thalm Jan 21 '14 at 17:35
  • It shall be noted that the tool will only establish a new timer period (_Begin Timer Period_) when the new value is smaller than the actual value. The _Timer End Period_ will only show effect when no other process has established a timer period of _Current Period_. Side note: Current is not necessarily within the range of _Min_ and _Max_; e.g. systems running at 1024 interrups/s show Current: 0,9766 with Min: 15,625 and Max: 1. This is due to the lack of accuracy the parameters of ´NtQueryTimerResolution´ can hold. More details in [this](http://stackoverflow.com/a/11628374/1504523) answer. – Arno Jan 23 '14 at 12:36

1 Answers1

3

Windows timer resolution is provided by the hidden API call:

NTSTATUS NtQueryTimerResolution(OUT PULONG MinimumResolution, 
                                OUT PULONG MaximumResolution, 
                                OUT PULONG ActualResolution);

NtQueryTimerResolution is exported by the native Windows NT library NTDLL.DLL.

Common hardware platforms report 156,250 or 100,144 for ActualResolution; older platforms may report even larger numbers; newer systems, particulary when HPET (High Precision Event Timer) or constant/invariant TSC are supported, may return 156,001 for ActualResolution.

Calls to timeBeginPeriod(n) are reflected in ActualResolution.

More details in this answer.

Community
  • 1
  • 1
Arno
  • 4,994
  • 3
  • 39
  • 63