News for hackers. Stuff that matters.
Re:Windows Timer Resolution: The Great Rule Change by vardump on Monday October 05, 2020 @06:00AM (#24686178)
You're just using timeSetEvent (which is an obsolete API, if I may add) instead of timeBeginPeriod. Which ultimately changes Windows timer interrupt frequency to the specified value.

So, sure, if you change Windows timer interrupt frequency, that's what you get. It'll of course also affect Sleep while active. Back to the square one.

Re:Windows Timer Resolution: The Great Rule Change by mehrdadn on Monday October 05, 2020 @06:05AM (#24686209)
Try adding timeBeginPeriod(1)/timeEndPeriod(1) around the waitable timer code and you'll see it still wakes up every 16ms.
Re:Windows Timer Resolution: The Great Rule Change by vardump on Monday October 05, 2020 @06:37AM (#24686369)
Pretty interesting.

And very alarming.

On Win10/1809 timeBeginPeriod does affect SetWaitableTimer resolution, as I'd have expected.

On Win10/2004 timeBeginPeriod doesn't seem to affect SetWaitableTimer resolution?! This could certainly break things!

SetWaitableTimer documentation lets you understand timeBeginPeriod is expected to affect the resolution. Of course, depending on hardware... but in this case both tests were running on same hardware.

"You can change the resolution of your API with a call to the timeBeginPeriod and timeEndPeriod functions. How precise you can change the resolution depends on which hardware clock the particular API uses. For more information, check your hardware documentation."

https://docs.microsoft.com/en-us/windows/win32/api/synchapi/...

Re:Windows Timer Resolution: The Great Rule Change by mehrdadn on Monday October 05, 2020 @06:42AM (#24686402)
Might be due to my use of APCs rather than waiting on the object. Not bothered enough to try it myself but I guess you can try WaitForSingleObject on the timer to see if it behaves similarly...
Re:Windows Timer Resolution: The Great Rule Change by vardump on Monday October 05, 2020 @06:48AM (#24686427)
On 2004, I tried timeBeginPeriod(1) and calling Sleep(1) 1000 times. Perplexingly it took a bit under 2 seconds.

On 1809 same took about 1.3 seconds.

I'm at loss... Windows timers have yet again managed to do really weird, unexpected things.

I really hope this mess doesn't affect device drivers, or there could be a world of hurt coming up.

Re:Windows Timer Resolution: The Great Rule Change by mehrdadn on Monday October 05, 2020 @06:54AM (#24686457)
I think it's due to my use of APCs like I said. Try replacing SleepEx(100, TRUE) with WaitForSingleObject(handle, INFINITE).

Edit: Never mind. Seems it might not be the APCs. Maybe some callee of Sleep(Ex) is just rounding up the wait interval to a time slice somewhere. Not sure... would need some digging.

Re:Windows Timer Resolution: The Great Rule Change by vardump on Monday October 05, 2020 @06:55AM (#24686467)
I didn't call SleepEx, but just plain old Sleep. I don't see how APCs would have anything to do with this.