From b52c432f067f045205befe25a58f180ce33db0e1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 6 Feb 2021 18:35:55 -0800 Subject: [PATCH 1/2] CoreTiming: Ensure we never idle into the past. Better to keep away from quantum trickiness here. --- Core/CoreTiming.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index ca30771568..0ddb79d926 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -566,8 +566,7 @@ void ForceCheck() #endif } -void Advance() -{ +void Advance() { PROFILE_THIS_SCOPE("advance"); int cyclesExecuted = slicelength - currentMIPS->downcount; globalTimer += cyclesExecuted; @@ -577,17 +576,14 @@ void Advance() MoveEvents(); ProcessFifoWaitEvents(); - if (!first) - { + if (!first) { // This should never happen in PPSSPP. // WARN_LOG_REPORT(TIME, "WARNING - no events in queue. Setting currentMIPS->downcount to 10000"); if (slicelength < 10000) { slicelength += 10000; - currentMIPS->downcount += slicelength; + currentMIPS->downcount += 10000; } - } - else - { + } else { // Note that events can eat cycles as well. int target = (int)(first->time - globalTimer); if (target > MAX_SLICE_LENGTH) @@ -599,36 +595,31 @@ void Advance() } } -void LogPendingEvents() -{ +void LogPendingEvents() { Event *ptr = first; - while (ptr) - { + while (ptr) { //INFO_LOG(CPU, "PENDING: Now: %lld Pending: %lld Type: %d", globalTimer, ptr->time, ptr->type); ptr = ptr->next; } } -void Idle(int maxIdle) -{ +void Idle(int maxIdle) { int cyclesDown = currentMIPS->downcount; if (maxIdle != 0 && cyclesDown > maxIdle) cyclesDown = maxIdle; - if (first && cyclesDown > 0) - { + if (first && cyclesDown > 0) { int cyclesExecuted = slicelength - currentMIPS->downcount; int cyclesNextEvent = (int) (first->time - globalTimer); if (cyclesNextEvent < cyclesExecuted + cyclesDown) - { cyclesDown = cyclesNextEvent - cyclesExecuted; - // Now, now... no time machines, please. - if (cyclesDown < 0) - cyclesDown = 0; - } } + // Now, now... no time machines, please. + if (cyclesDown < 0) + cyclesDown = 0; + // VERBOSE_LOG(CPU, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(CPU_HZ * 0.001f)); idledCycles += cyclesDown; From c99de6409d26dae64f2c34b9b91ee985e7b08457 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 6 Feb 2021 18:37:05 -0800 Subject: [PATCH 2/2] Sas: Minor clenaup. --- Core/HLE/sceSas.cpp | 3 +-- Core/HW/SasAudio.cpp | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index 25cb02f392..c0bde1bd44 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -109,10 +109,9 @@ int __SasThread() { if (sasThreadState == SasThreadState::QUEUED) { sas->Mix(sasThreadParams.outAddr, sasThreadParams.inAddr, sasThreadParams.leftVol, sasThreadParams.rightVol); - sasDoneMutex.lock(); + std::lock_guard doneGuard(sasDoneMutex); sasThreadState = SasThreadState::READY; sasDone.notify_one(); - sasDoneMutex.unlock(); } } return 0; diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 15db6c4d50..52566ee0d7 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -565,13 +565,10 @@ void SasInstance::MixVoice(SasVoice &voice) { } void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) { - int voicesPlayingCount = 0; - for (int v = 0; v < PSP_SAS_VOICES_MAX; v++) { SasVoice &voice = voices[v]; if (!voice.playing || voice.paused) continue; - voicesPlayingCount++; MixVoice(voice); }