-
Notifications
You must be signed in to change notification settings - Fork 18k
time: NewTimer & NewTicker should use SetWaitableTimer on Windows #29714
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
Comments
@networkimprov how much better using SetWaitableTimer than 2ms? Alex |
2ms is a reasonable result. The smallest timer resolution you would see is about 1ms. Here is a doc with more info. |
@jordanrh1 that doc doesn't discuss the 10MHz interrupt timer hardware described in the article I linked -- it only covers the older "clock interrupt". From the article:
@alexbrainman this hardware enables at least 100ns resolution; many common HPET chips are 14MHz. |
|
The web is full of user reports on multimedia game performance differences after en/disabling the HPET in BIOS, tho that's not evidence of altered WaitableTimer resolution per se. I haven't seen anything explicit on how Windows surfaces HPET functionality, besides ACPI. It seems the HPET must be manually enabled in BIOS and/or the OS on some systems. |
I do not think SetWaitableTimer will get us better resolution that we have now. But I am only guessing. I need to write little program to find out for sure. My TODO list is very long at this moment, so I suspect others will beat me to it. Alex |
So far I haven't seen anything indicating that If someone (maybe someone less busy than Alex :) wants to do the experiment to show whether |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
This should be reopened... |
I built this program https://play.golang.org/p/Vj39giJIRJX and it prints
on one of my computers. @networkimprov I will let you play with my program and decide what to do here. Alex |
As far as I can tell |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Haven't tried 1.12beta
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Tested time.After with:
https://play.golang.org/p/TVDunzS8YU3
What did you expect to see?
100ns (repeating)
100ns is the result on Linux.
What did you see instead?
2.0014ms
1.9888ms
1.9951ms
1.9934ms
1.9945ms
1.9945ms
1.9951ms
1.9951ms
1.9945ms
1.9946ms
Discussion
SetWaitableTimer(), available since Win7, offers 100ns resolution. Go already calls it in the profiler.
https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-setwaitabletimerex
Windows hardware has shipped with a 10+MHz (100ns per click) interrupt timer for many years.
https://en.wikipedia.org/wiki/High_Precision_Event_Timer
Also applies to time.After, time.AfterFunc, and time.Tick.
Originally raised by @destinysync in #29485
CC: @jordanrh1 @alexbrainman @aclements
Thanks for your consideration!
The text was updated successfully, but these errors were encountered: