Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance issue in MLB 2k games with profiler funcs #17666

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Jul 5, 2023

The function sceKernelReferGlobalProfiler are spammed by this game between matches. So let's reduce logging to DEBUG and delay the response by a tested number of ms. And do the same for its sibling function, sceKernelReferThreadProfiler.

Fixes #17623

Here's the pspautotest I wrote, though not a good idea to check in the timing checks:

#include "shared.h"
#include "string.h"

int main(int argc, char *argv[]) {
	checkpointNext("sceKernelReferThreadProfiler");
	u64 before = sceKernelGetSystemTimeWide();
	PspDebugProfilerRegs *regs = sceKernelReferThreadProfiler();
	checkpoint("regs: %08x", regs);
	u64 timeTaken = sceKernelGetSystemTimeWide() - before;
	checkpoint("timeTaken: %llu", (unsigned long long)timeTaken);
	if (regs) {
		// TODO: Inspect the data here, but we don't seem to get any.
	}

	checkpointNext("sceKernelReferGlobalProfiler");
	before = sceKernelGetSystemTimeWide();
	regs = sceKernelReferGlobalProfiler();
	checkpoint("regs: %08x", regs);
	timeTaken = sceKernelGetSystemTimeWide() - before;
	checkpoint("timeTaken: %llu", (unsigned long long)timeTaken);
	if (regs) {
		// TODO: Inspect the data here, but we don't seem to get any.
	}
	return 0;
}

and the output:

[x] sceKernelReferThreadProfiler
[x] regs: 00000000
[x] timeTaken: 55

[x] sceKernelReferGlobalProfiler
[x] regs: 00000000
[x] timeTaken: 54

It should be noted though that this doesn't really confirm that the functions don't take a parameter, only that they return 0. But I've chosen to just follow https://pspdev.github.io/pspsdk/group__ThreadMan.html#ga8fd30da51b9dc0507ac4dae04a7e4a17 . It does seem assymetrical with sceKernelReferSystemStatus though...

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
@hrydgard hrydgard added HLE/Kernel Kernel, memory manager, other HLE issues Performance Unexpected slow performance issues labels Jul 5, 2023
@hrydgard hrydgard added this to the v1.16.0 milestone Jul 5, 2023
@hrydgard
Copy link
Owner Author

hrydgard commented Jul 6, 2023

I'm just gonna go for this one. Seems safe enough.

@hrydgard hrydgard merged commit 3c17239 into master Jul 6, 2023
@hrydgard hrydgard deleted the mlb-perf-issue-with-profiler-funcs branch July 6, 2023 09:22
@unknownbrackets
Copy link
Collaborator

There's an option for the tests CHECKPOINT_ENABLE_TIME = 1;, which will show the time since last checkpoint automatically on each. Also, I've usually run the func 8 times in a row to avoid overheads.

That said, I doubt exactness is that important here, as long as we're in the right area.

-[Unknown]

DEBUG_LOG(SCEKERNEL, "0=sceKernelReferThreadProfiler()");

// The delay has been measured, 53-56 us.
hleEatMicro(55);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not important, but I usually use hleEatCycles for things that get faster when you set the PSP clock speed faster. This is probably (but not certainly) one of those cases.

-[Unknown]

@hrydgard
Copy link
Owner Author

hrydgard commented Jul 8, 2023

It has turned out that implementing the function like this makes MLB 2K11 run incredibly slowly. So I think there's more to this function. Maybe the function signature in the pspsdk is simply wrong, and it does write a structure to the first parameter. I'll investigate soon.

And yeah, you're right that hleEatCycles should be more appropriate here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLE/Kernel Kernel, memory manager, other HLE issues Performance Unexpected slow performance issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unusual slowdown in the MLB 2k games
2 participants