Skip to content

Commit

Permalink
Merge pull request #14730 from unknownbrackets/savedata-shutdown
Browse files Browse the repository at this point in the history
Dialog: Prevent reschedule on shutdown start
  • Loading branch information
hrydgard committed Aug 15, 2021
2 parents 92e7534 + 5d17ec7 commit ed3201a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Core/Dialog/PSPDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void PSPDialog::ChangeStatusInit(int delayUs) {

void PSPDialog::ChangeStatusShutdown(int delayUs) {
// If we're doing shutdown right away and skipped start, we don't run the dialog thread.
bool skipDialogShutdown = status == SCE_UTILITY_STATUS_NONE;
bool skipDialogShutdown = status == SCE_UTILITY_STATUS_NONE && pendingStatus == SCE_UTILITY_STATUS_NONE;
ChangeStatus(SCE_UTILITY_STATUS_SHUTDOWN, 0);

auto params = GetCommonParam();
Expand Down
11 changes: 9 additions & 2 deletions Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,15 @@ void *GetQuickSyscallFunc(MIPSOpcode op) {
}

static double hleSteppingTime = 0.0;
void hleSetSteppingTime(double t)
{
void hleSetSteppingTime(double t) {
hleSteppingTime += t;
}

static double hleFlipTime = 0.0;
void hleSetFlipTime(double t) {
hleFlipTime = t;
}

void CallSyscall(MIPSOpcode op)
{
PROFILE_THIS_SCOPE("syscall");
Expand Down Expand Up @@ -734,8 +738,11 @@ void CallSyscall(MIPSOpcode op)
int funcnum = callno & 0xFFF;
int modulenum = (callno & 0xFF000) >> 12;
double total = time_now_d() - start - hleSteppingTime;
if (total >= hleFlipTime)
total -= hleFlipTime;
_dbg_assert_msg_(total >= 0.0, "Time spent in syscall became negative");
hleSteppingTime = 0.0;
hleFlipTime = 0.0;
updateSyscallStats(modulenum, funcnum, total);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/HLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void hleDebugBreak();
void hleSkipDeadbeef();
// Set time spent in debugger (for more useful debug stats while debugging.)
void hleSetSteppingTime(double t);
// Set time spent in realtime sync.
void hleSetFlipTime(double t);
// Check if the current syscall context is kernel.
bool hleIsKernelMode();
// Enqueue a MIPS function to be called after this HLE call finishes.
Expand Down
7 changes: 6 additions & 1 deletion Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,13 @@ void __DisplaySetFramebuf(u32 topaddr, int linesize, int pixelFormat, int sync)
// IMMEDIATE means that the buffer is fine. We can just flip immediately.
// Doing it in non-buffered though creates problems (black screen) on occasion though
// so let's not.
if (!flippedThisFrame && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE)
if (!flippedThisFrame && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) {
double before_flip = time_now_d();
__DisplayFlip(0);
double after_flip = time_now_d();
// Ignore for debug stats.
hleSetFlipTime(after_flip - before_flip);
}
} else {
// Delay the write until vblank
latchedFramebuf = fbstate;
Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/sceGe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ static u32 sceGeDrawSync(u32 mode) {
//wait/check entire drawing state
if (PSP_CoreParameter().compat.flags().DrawSyncEatCycles)
hleEatCycles(500000); //HACK(?) : Potential fix for Crash Tag Team Racing and a few Gundam games
else
hleEatCycles(1240);
DEBUG_LOG(SCEGE, "sceGeDrawSync(mode=%d) (0=wait for completion, 1=peek)", mode);
return gpu->DrawSync(mode);
}
Expand Down
4 changes: 0 additions & 4 deletions Core/HLE/sceKernelInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#include "GPU/GPUCommon.h"
#include "GPU/GPUState.h"

void __DisableInterrupts();
void __EnableInterrupts();
bool __InterruptsEnabled();

// Seems like some > 16 are taken but not available. Probably kernel only?
static const u32 PSP_NUMBER_SUBINTERRUPTS = 32;

Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/sceKernelInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class IntrHandler
std::map<int, SubIntrHandler> subIntrHandlers;
};

void __DisableInterrupts();
void __EnableInterrupts();
bool __InterruptsEnabled();
bool __IsInInterrupt();
void __InterruptsInit();
Expand Down
3 changes: 2 additions & 1 deletion Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,8 @@ int __KernelStartThread(SceUID threadToStartID, int argSize, u32 argBlockPtr, bo
Core_ExecException(startThread->context.pc, currentMIPS->pc, ExecExceptionType::THREAD);
}
__KernelChangeReadyState(cur, currentThread, true);
hleReSchedule("thread started");
if (__InterruptsEnabled())
hleReSchedule("thread started");
}

// Starting a thread automatically resumes the dispatch thread if the new thread has worse priority.
Expand Down
5 changes: 5 additions & 0 deletions Core/HLE/sceUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "Core/System.h"

#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelInterrupt.h"
#include "Core/HLE/sceKernelMemory.h"
#include "Core/HLE/sceKernelThread.h"
#include "Core/HLE/scePower.h"
Expand Down Expand Up @@ -326,8 +327,12 @@ void UtilityDialogShutdown(UtilityDialogType type, int delayUs, int priority) {

CleanupDialogThreads();
_assert_(accessThread == nullptr);
bool prevInterrupts = __InterruptsEnabled();
__DisableInterrupts();
accessThread = new HLEHelperThread("ScePafJob", insts, (uint32_t)ARRAY_SIZE(insts), priority, 0x200);
accessThread->Start(partDelay, 0);
if (prevInterrupts)
__EnableInterrupts();
}

static int UtilityWorkUs(int us) {
Expand Down

0 comments on commit ed3201a

Please sign in to comment.