5 void os_clk_tck(long *clk_tck)
8 * The timer resolution is variable on Windows. Try to query it
9 * or use 64 Hz, the clock frequency lower bound. See also
10 * https://carpediemsystems.co.uk/2019/07/18/windows-system-timer-granularity/.
12 unsigned long minRes, maxRes, curRes;
14 NTSTATUS NTAPI (*queryTimer)
15 (OUT PULONG MinimumResolution,
16 OUT PULONG MaximumResolution,
17 OUT PULONG CurrentResolution);
18 NTSTATUS NTAPI (*setTimer)
19 (IN ULONG DesiredResolution,
20 IN BOOLEAN SetResolution,
21 OUT PULONG CurrentResolution);
23 if (!(lib = LoadLibrary(TEXT("ntdll.dll"))) ||
24 !(queryTimer = (void *)GetProcAddress(lib, "NtQueryTimerResolution")) ||
25 !(setTimer = (void *)GetProcAddress(lib, "NtSetTimerResolution"))) {
26 dprint(FD_HELPERTHREAD,
27 "Failed to load ntdll library, set to lower bound 64 Hz\n");
30 queryTimer(&minRes, &maxRes, &curRes);
31 dprint(FD_HELPERTHREAD,
32 "minRes = %lu, maxRes = %lu, curRes = %lu\n",
33 minRes, maxRes, curRes);
35 /* Use maximum resolution for most accurate timestamps */
36 setTimer(maxRes, 1, &curRes);
37 *clk_tck = (long) (10000000L / maxRes);