Ryujinx/src/Ryujinx.HLE/HOS
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
..
Applets chore: remove repetitive words (#6500) 2024-03-16 19:49:54 +01:00
Diagnostics/Demangler editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
Ipc [Ryujinx.HLE] Address dotnet-format issues (#5380) 2023-07-16 19:31:14 +02:00
Kernel Kernel: Wake cores from idle directly rather than through a host thread (#6837) 2024-05-22 17:47:27 -03:00
Services HID: Stub IHidServer: 134 (SetNpadAnalogStickUseCenterClamp) (#6664) 2024-05-14 16:26:49 +02:00
SystemState editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
Tamper Revert "Update StoreConstantToMemory to match StoreConstantToAddress on value…" (#6649) 2024-04-10 21:50:06 -03:00
ArmProcessContext.cs Implement a new JIT for Arm devices (#6057) 2024-01-20 11:11:28 -03:00
ArmProcessContextFactory.cs Delete old 16KB page workarounds (#6584) 2024-04-06 13:51:44 -03:00
HomebrewRomFsStream.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
Horizon.cs Migrate Audio service to new IPC (#6285) 2024-02-22 16:58:33 -03:00
HorizonFsClient.cs Implement NGC service (#5681) 2023-09-27 19:21:26 +02:00
IdDictionary.cs [Ryujinx.HLE] Address dotnet-format issues (#5380) 2023-07-16 19:31:14 +02:00
LibHacHorizonManager.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
ModLoader.cs Replacing the try-catch block with null-conditional and null-coalescing operators (#6612) 2024-04-07 16:49:14 -03:00
ResultCode.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00
ServiceCtx.cs [Ryujinx.HLE] Address dotnet-format issues (#5380) 2023-07-16 19:31:14 +02:00
TamperMachine.cs Update to new standard for volatility operations (#6682) 2024-04-19 09:03:52 -03:00
UserChannelPersistence.cs editorconfig: Set default encoding to UTF-8 (#5793) 2023-12-04 14:17:13 +01:00