From 7daaab96d5a7097b2a3fda2ab981edce75f68fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 5 Jul 2023 11:43:37 +0200 Subject: [PATCH] Fix performance issue in MLB 2k games with profiler funcs 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 --- Core/HLE/sceKernel.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index f83efc63c1..c41df68594 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -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; @@ -678,24 +679,22 @@ struct DebugProfilerRegs { u32 local_bus; }; -static u32 sceKernelReferThreadProfiler(u32 statusPtr) { - ERROR_LOG(SCEKERNEL, "FAKE sceKernelReferThreadProfiler()"); +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). - // Can we confirm that the struct above is the right struct? - // If so, re-enable this code. - //auto regs = PSPPointer::Create(statusPtr); - // TODO: fill the struct. - //if (regs.IsValid()) { - // memset((DebugProfilerRegs *)regs, 0, sizeof(DebugProfilerRegs)); - // regs.NotifyWrite("ThreadProfiler"); - //} - return 0; + // 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[] =