-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Remove busy loops #1367
base: master
Are you sure you want to change the base?
Remove busy loops #1367
Conversation
replaced with either this_thread::sleep_* condition_variable for audio read/write loop this reduces usage from "around 16%" (on a 16t CPU, thus a 2.5 threads load) to a nicer "around 0.7%"
Some missing include for Movie.cpp is killing linux/macos builds. I will fix that. I probably also need to replicate AO's Movie.cpp fixes in AE. Still interested in any feedback meanwhile. |
@@ -1346,19 +1347,51 @@ EXPORT void CC SsSetTickMode_4FDC20(s32) | |||
// Stub | |||
} | |||
|
|||
// TODO: Removed 4FDC30 | |||
EXPORT bool CC SsSeqCalledTbyT_4FDC80_sleep_until_due_time_if_before_max_time(SYS_time_point_t current_time, SYS_time_point_t max_time) |
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.
_4FDC80 needs to be at the end of the function as exported function names are parsed at runtime for installing hooks into the game when running as a DLL. This name is super verbose too, I would have just left it as SsSeqCalledTbyT_4FDC80 tbh since the waiting/sleeping is an implementation detail.
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.
I meant to avoid breaking existing SsSeqCalledTbyT_4FDC80 ABI with "max_time" new argument.
(because I understood that number-suffixed functions are meant to be interchangeable with original binaries)
Unless I miss something, I thus can simplify the name but not use the original one.
{ | ||
const auto nextDueTime = lastTime + 30; | ||
|
||
if ((s32) (SYS_AsU32Ms(max_time) - nextDueTime) < 0) |
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.
use static_cast instead of a C cast
|
||
const auto timeToWait = (s32) (nextDueTime - SYS_AsU32Ms(current_time)); |
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.
use static_cast instead of a C cast
@@ -100,6 +100,11 @@ HRESULT SDLSoundSystem::Release() | |||
|
|||
// Stop audio rendering thread | |||
mRenderAudioThreadQuit = true; | |||
{ | |||
std::lock_guard g{mAudioRingBufferMutex}; |
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.
instead of 'g' can we at least called it 'lock' or something
@@ -139,6 +144,11 @@ void SDLSoundSystem::AudioCallBack(Uint8* stream, s32 len) | |||
{ | |||
LOG_ERROR("Ring buffer read failure!"); | |||
} | |||
|
|||
{ | |||
std::lock_guard g{mAudioRingBufferMutex}; |
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.
ditto for naming
|
||
u32 SYS_AsU32Ms(SYS_time_point_t t) | ||
{ | ||
return (u32) std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch()).count(); |
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.
static_cast instead of C cast
We could probably do with someone with a slower machine testing this to check it doesn't impact performance. Maybe @mouzedrift can try one the build is fixed. |
CPU usage went down to +-7% but the game looks very laggy |
I suspected that might be an issue. @ilelann it might be better to try to get https://github.com/AliveTeam/sound_rev working instead as this can work without another thread which would remove the busy waits. It needs progressing so that the emulator integration can run the psx SPU code (instead of emulated mips code). Once this works it can be refactored/reduced down and integrated into relive. |
Thanks a lot for your comments, I'll dig that. |
windows 10 pro, 8 gb ram, intel core i5-4440 with intel hd graphics 4600 |
A temp hack fix was merged that removes the busy loops, already confirmed that this causes stuttering on some machines but it can be turned off via the ini. Hack fix is temp till audio is rewritten. |
replaced with either
this_thread::sleep_*
condition_variable for audio read/write loop
this reduces usage from "around 16%" (on a recent 16t CPU, thus a 2.5 threads load)
to a nicer "around 0.7%"