ryujinx/src/Ryujinx.HLE
riperiperi c1ed150949
Kernel: Wake cores from idle directly rather than through a host thread (#6837)
* Kernel: Wake cores from idle directly rather than through a host thread

Right now when a core enters an idle state, leaving that idle state requires us to first signal the core's idle thread, which then signals the correct thread that we want to run on the core. This means that in a lot of cases, we're paying double for a thread to be woken from an idle state.

This PR moves this process to happen on the thread that is waking others out of idle, instead of an idle thread that needs to be woken first.

For compatibility the process has been kept as similar as possible - the process for IdleThreadLoop has been migrated to TryLeaveIdle, and is gated by a condition variable that lets it run only once at a time for each core. A core is only considered for wake from idle if idle is both active and has been signalled - the signal is consumed and the active state is cleared when the core leaves idle.

Dummy threads (just the idle thread at the moment) have been changed to have no host thread, as the work is now done by threads entering idle and signalling out of it.

This could put a bit of extra work on threads that would have triggered `_idleInterruptEvent` before, but I'd expect less work than signalling all those reset events and the OS overhead that follows. Worst case is that other threads performing these signals at the same time will have to wait for each other, but it's still going to be a very short amount of time.

Improvements are best seen in games with heavy (or very misguided) multithreading, such as Pokemon: Legends Arceus. Improvements are expected in Scarlet/Violet and TOTK, but are harder to measure.

Testing on Linux/MacOS still to be done, definitely need to test more games as this affects all of them (obviously) and any issues might be rare to encounter.

* Remove _idleThread entirely

* Use spinwait so we don't completely blast the CPU with cmpxchg

* Didn't I already do this

* Cleanup
2024-05-22 17:47:27 -03:00
..
Exceptions editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
FileSystem Enhance Error Handling with Try-Pattern Refactoring (#6610) 2024-04-07 17:55:34 -03:00
HOS Kernel: Wake cores from idle directly rather than through a host thread (#6837) 2024-05-22 17:47:27 -03:00
Loaders Ava UI: Mod Manager (#4390) 2024-01-26 02:02:28 +01:00
UI Infra: Capitalisation Consistency (#6296) 2024-02-11 03:09:18 +01:00
Utilities editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
AssemblyInfo.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
HLEConfiguration.cs Infra: Capitalisation Consistency (#6296) 2024-02-11 03:09:18 +01:00
Homebrew.npdm Move solution and projects to src 2023-04-27 23:51:14 +02:00
MemoryConfiguration.cs [Ryujinx.HLE] Address dotnet-format issues (#5380) 2023-07-16 19:31:14 +02:00
PerformanceStatistics.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
Ryujinx.HLE.csproj Migrate Audio service to new IPC (#6285) 2024-02-22 16:58:33 -03:00
Switch.cs Migrate Audio service to new IPC (#6285) 2024-02-22 16:58:33 -03:00