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

Tracking: Thread scheduler scheduling #124

Open
wheremyfoodat opened this issue Jul 18, 2023 · 3 comments
Open

Tracking: Thread scheduler scheduling #124

wheremyfoodat opened this issue Jul 18, 2023 · 3 comments

Comments

@wheremyfoodat
Copy link
Owner

wheremyfoodat commented Jul 18, 2023

It is important to remember the thread scheduler only pretends to be cooperative and loves to preempt.
Particularly any sort of ARM11 timer interrupt can preempt the running process, which is important to emulate since a lot of games seem to get stuck due to multithreading issues (eg #88).

Unimplemented examples of this pre-emption can be seen in

  • ArbitrateAddress (timing out will preempt, which we don't emulate)
  • WaitSync1/WaitSyncN (timing out again)
  • SleepThread (Waking up will preempt)
  • OS timers firing
  • TBD

We do have some cases implemented (eg events firing), but it's probably not good enough and still causes bugs/games hanging.
Below I attach some relevant resources from our Discord server.

@wheremyfoodat
Copy link
Owner Author

Additionally

  • File and archive operations will make the running thread go to nap and cause a reschedule (need to wait for syscore and then for Process9)
  • SendSyncRequest behaves similarly.

Both are quite important and very likely break games. Especially SendSyncRequest.

Thanks to these 2 yielding the running thread, it means that a program can completely ignore threads other than the main thread, and the kernel will still occasionally put the thread to sleep and give other threads time to shine.

@wheremyfoodat
Copy link
Owner Author

Also as a side note the address arbiter code only works if the game only ever creates a single arbiter (because it straight up ignores which arbiter a thread is sleeping on)

In my defense I wrote the relevant code around the same day I started the emulator and had no idea what I was doing

@wheremyfoodat
Copy link
Owner Author

wheremyfoodat commented Aug 9, 2023

Some games like Sonic Boom seem to ask for threads to run on the syscore. These threads typically have low priority so they may never actually get to run in the emulator, while real hardware would run them in parallel to the appcore using the limited syscore time applications can take up.

Old Citra fixed this by boosting the priority of starved threads, while newer Citra uses separate per core thread-managers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant