Live data from Hacker News

The Story of Microsleep (2012)

scalibq.wordpress.com

11–13 of 13 posts

Re: The Story of Microsleep (2012)

#11
post #7

Earlier quoted context omitted.

You're right. But sometimes, you can't afford the cost of the context switch.

but the proposed solution is literally trying to context switch in a loop

Exactly. As I tried to explain, you NEED a context switch (which doesn't make it a spin-wait) in order to avoid the deadlock between your main loop and the processing of the Windows message queue (and as you see, I do check the quantum, via QueryPerformanceCounter()). The goal was to find a way that didn't deadlock the system, while also not wasting so much time that it impacts your framerate to the point where you can't even drive a high-refresh display at say 144 Hz.

Ofcourse I'm open to even better solutions, but so far this is the best solution I know of.

I doubt that events/semaphores would work better, as they'd be implemented as spinlocks for short periods of time, in which case they wouldn't actually trigger a context switch. Once you use a long enough time to get to a context switch, it's probably going to be worse than doing the context switch explicitly, the way I do here.

All in all, it's a bug in Windows Aero, as the followup blog expained (not sure if it was ever fixed in later versions of Windows, I haven't been working with multiple display adapters/screens in situations like these in recent years): https://scalibq.wordpress.com/2012/03/28/the-story-of-micros...

Re: The Story of Microsleep (2012)

#12

Spin-wait seem a wasteful solution. It seems to me that some sort of pseudo-cooperative scheduling implemented via some event or semaphore and keeping track of the current used 'quantum' would be better.

Please correct me if I am wrong , Linux has HRTs introduced just to solve this problem right ? Windows doesnt have anything like that ?

How is micro-sleep solving the problem that OP has underlined ? >The resulting behaviour appears to be that the message queues are filling up, and as a result, not only the windows themselves are becoming unresponsive, but the system as a whole is starting to respond poorly. This seems to happen even on a quadcore system with HyperThreading, which should be able to handle 8 threads simultaneously. So just having enough cores is not always the answer, apparently.

Re: The Story of Microsleep (2012)

#13

Spin-wait seem a wasteful solution. It seems to me that some sort of pseudo-cooperative scheduling implemented via some event or semaphore and keeping track of the current used 'quantum' would be better.

Please correct me if I am wrong , Linux has HRTs introduced just to solve this problem right ? Windows doesnt have anything like that ? How is micro-sleep solving the problem that OP has underlined ? >The resulting behaviour appears to be that the message queues are filling up, and as a result, not only the windows themselves are becoming unresponsive, but the system as a whole is starting to respond poorly. This see…

Yes, I posted a followup which investigates the issue somewhat further. It appears to be some bug with the message queue handling, specifically when the UI is in Aero mode. In classic mode, the problem is not there. In Windows XP, the problem is also not there. https://scalibq.wordpress.com/2012/03/28/the-story-of-micros...
Post reply on HN