-
Notifications
You must be signed in to change notification settings - Fork 39
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
improve SuperSleepUntil implementation #198
Conversation
1) as found in lots of experiments done for the VPX and PinMAME projects, Sleep() on windows can oversleep for over 1ms, especially when doing Sleep(>1) 2) thus loop Sleep(1) and end if its less than 2ms 3) in the spin to wait for the rest of the time, insert yield(=_mm_pause) or the determined by the Rust devs arm64 equivalent this actually gets rid of micro-stutter on my AMD based minipc e.g. in Daytona2 then also use same Sleep() implementation in the network code (to avoid potential sideeffects between the 2 implementations)
See our battle-tested implementation in PinMAME: https://github.com/vpinball/pinmame/blob/master/src/windows/ticker.c#L253 |
I'd much prefer a solution based upon SDL if possible, even if it's slightly sub optimal for different platforms. The original code does assume that windows sleep isn't that accurate, that's why it subtracts 1ms from the sleep time, then just spins for the rest of the time. But it's possible I guess that's not quite enough, and it goes over the time slightly. The network code really doesn't need any kind of spin lock at all, std::this_thread::sleep_for(16ms); really is enough. The code could be changed to sleep for 1 second and it would still be fine. |
It is still all SDL based, also the network code (CThread::Sleep maps to SDL_Delay, so no spin there). |
SDL3 will add one though apparently: https://wiki.libsdl.org/SDL3/SDL_CPUPauseInstruction |
Turns out that this was also added later-on for SDL2, just not documented. |
And as said, it fixes a real life issue on my mini PC, where with this changes some VERY noticable micro stutter vanishes. |
SDL_CPUPauseInstruction is a nice solution. I think I need to update my sdl though because it's missing my from my version. |
What SDL2 version does this function "un-documentedly" appear in? This will potentially break the the ability for some distributions to upgrade supermodel, particular in Linux. |
@sgpowers I tweaked it now, so that this part is optional. So this part will function like it did before, if SDL2 is too old. |
This actually gets rid of micro-stutter on my AMD based minipc e.g. in Daytona2 (see #178)
Then also use same Sleep() implementation in the network code (to avoid potential sideeffects between the 2 implementations)