diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index df8ab549d7..2acd71c90a 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include #include #include @@ -289,6 +290,15 @@ void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata) ne->type = event_type; ne->time = GetTicks(currentMIPS) + cyclesIntoFuture; AddEventToQueue(ne); + + // The slice was sized to end at the next event. If this one is due sooner, end it there, or it + // fires late: an alarm set by a thread that keeps running went off hundreds of us late + // (pspautotests threads/scheduling/alarmcosts). + if (cyclesIntoFuture < currentMIPS->downcount) { + const int diff = (int)std::max(cyclesIntoFuture, 0) - currentMIPS->downcount; + slicelength += diff; + currentMIPS->downcount += diff; + } } // Returns cycles left in timer.