-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timeval: use QueryPerformanceCounter on Windows #3318
Conversation
Thanks! We have a helper function for verifying the Windows version: Line 64 in 25d2a1b
This is because VerifyVersionInfo is only available starting from Windows 2000, the Windows 8 and later SDKs warn about GetVersionInfoEx and it doesn't work without a manifest, and UWP/WinRT supports neither.
|
34bd0a4
to
3394a1e
Compare
can you please restart "LGTM analysis: C/C++ — Analysis failed (could not build the merge commit)" step. |
When you force push it should restart |
Yes, I had to come up with some random change to force push something new :) |
How does How about |
AFAIK QueryPerformanceCounter is guaranteed to provide consistent results for quite some time. It does not use true CPU frequency. It used to have some of these issues long time ago, so in this change I set it to use QPC only starting from Vista (even though QPC is available starting from win95 probably) |
Strange, they mention that TSC is used for QPC timer, however, I haven't seen that. AFAIK QPC always uses something else, as I've never seen that QPF returns some huge values closely related to CPU frequency; instead I've always seen values around 1000 times smaller than CPU frequency. Also, keep in mind originally I simply matched implementation of |
No idea. You'd need to step into these functions to see what they use internally (what API). There aren't many choices. GetSystemTimeAsFileTime is very likely candidate here, but it returns calendar time (e.g. user can change system time and your clock will jump, same applies for auto time adjustments done by the system). |
@MarcelRaad @gvanem @jay I'll appreciate your input and guidance on where to go with this PR. Users will certainly appreciate higher resolution timers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I haven't encountered any issues with QPC/QPF on Windows Vista / Server 2008 and later myself yet.
The result of |
@MarcelRaad Okay, then this look all good to me. |
AFAICT from Acquiring high-resolution time stamps Windows Vista+ will automatically select a source for the QPC that is not subject to synchronization issues across cores. Specifically it says that "the performance counter results are consistent across all processors in multi-core and multi-processor systems, even when measured on different threads or processes" with the two noted exceptions, neither of which affect us here. If there is a bug in the user's TSC or some other source Windows Vista+ should detect and avoid it, and if it's not then QPC is not working as documented. Though that stackoverflow report sounds credible I don't think it's significant enough to block this. |
Thanks |
see #3309
There is confusing info floating around that QueryPerformanceCounter can leap etc, which might have been true long time ago, but no loner the case nowadays (perhaps starting from WinXP?). Also, boost and std::chrono::steady_clock use QueryPerformanceCounter in a similar way.