Skip to content

Commit

Permalink
Fix performance issue in MLB 2k games with profiler funcs
Browse files Browse the repository at this point in the history
The two functions sceKernelReferThreadProfiler and
sceKernelReferGlobalProfiler are spammed by this game. So let's reduce
logging to DEBUG and delay the response by a tested number of ms.

Fixes #17623
  • Loading branch information
hrydgard committed Jul 5, 2023
1 parent 6512558 commit 7daaab9
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ static int sceKernelReferSystemStatus(u32 statusPtr) {
return 0;
}

// Unused - believed to be the returned struct from sceKernelReferThreadProfiler.
struct DebugProfilerRegs {
u32 enable;
u32 systemck;
Expand All @@ -678,24 +679,22 @@ struct DebugProfilerRegs {
u32 local_bus;
};

static u32 sceKernelReferThreadProfiler(u32 statusPtr) {
ERROR_LOG(SCEKERNEL, "FAKE sceKernelReferThreadProfiler()");

// Can we confirm that the struct above is the right struct?
// If so, re-enable this code.
//auto regs = PSPPointer<DebugProfilerRegs>::Create(statusPtr);
// TODO: fill the struct.
//if (regs.IsValid()) {
// memset((DebugProfilerRegs *)regs, 0, sizeof(DebugProfilerRegs));
// regs.NotifyWrite("ThreadProfiler");
//}
return 0;
static u32 sceKernelReferThreadProfiler(u32 unused) {
// This seems to simply has no parameter:
// https://pspdev.github.io/pspsdk/group__ThreadMan.html#ga8fd30da51b9dc0507ac4dae04a7e4a17 ,
// And in testing it just returns null in 55 usec (which is surprisingly long).

// So, we log only if debug logging is enabled, and sleep for a bit.
DEBUG_LOG(SCEKERNEL, "sceKernelReferThreadProfiler(%08x)", unused);

// The delay has been measured, 53-56.
return hleDelayResult(0, "refer_thread_profiler", 55);
}

static int sceKernelReferGlobalProfiler(u32 statusPtr) {
ERROR_LOG(SCEKERNEL, "UNIMPL sceKernelReferGlobalProfiler(%08x)", statusPtr);
// Ignore for now
return 0;
static int sceKernelReferGlobalProfiler(u32 unused) {
DEBUG_LOG(SCEKERNEL, "sceKernelReferGlobalProfiler(%08x)", unused);
// The delay has been measured, 53-56.
return hleDelayResult(0, "refer_thread_profiler", 55);
}

const HLEFunction ThreadManForUser[] =
Expand Down

0 comments on commit 7daaab9

Please sign in to comment.