From 9b9ead94cd2f25a85468ecf91b7898bf34e10825 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 15 May 2018 23:49:57 -0300 Subject: [PATCH] Only use higher priority on yield, change reschedule to be per-thread instead of using SchedulerThread to store the reschedule flag --- .../OsHle/Handles/KProcessScheduler.cs | 25 +++++++++---------- Ryujinx.Core/OsHle/Handles/SchedulerThread.cs | 2 -- Ryujinx.Core/OsHle/Handles/ThreadQueue.cs | 2 +- Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs | 1 - 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs index f27455b9..c1c10314 100644 --- a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs +++ b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs @@ -13,6 +13,8 @@ namespace Ryujinx.Core.OsHle.Handles private KThread[] CoreThreads; + private bool[] CoreReschedule; + private object SchedLock; private Logger Log; @@ -27,6 +29,8 @@ namespace Ryujinx.Core.OsHle.Handles CoreThreads = new KThread[4]; + CoreReschedule = new bool[4]; + SchedLock = new object(); } @@ -147,10 +151,10 @@ namespace Ryujinx.Core.OsHle.Handles { PrintDbgThreadInfo(Thread, "suspended."); - AllThreads[Thread].NeedsReschedule = false; - int ActualCore = Thread.ActualCore; + CoreReschedule[ActualCore] = false; + SchedulerThread SchedThread = WaitingToRun.Pop(ActualCore); if (SchedThread != null) @@ -174,26 +178,21 @@ namespace Ryujinx.Core.OsHle.Handles { lock (SchedLock) { - KThread Thread = CoreThreads[Core]; - - if (Thread != null && AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) - { - SchedThread.NeedsReschedule = true; - } + CoreReschedule[Core] = true; } } public void Reschedule(KThread Thread) { - SchedulerThread SchedThread = AllThreads[Thread]; - bool NeedsReschedule; lock (SchedLock) { - NeedsReschedule = SchedThread.NeedsReschedule; + int ActualCore = Thread.ActualCore; - SchedThread.NeedsReschedule = false; + NeedsReschedule = CoreReschedule[ActualCore]; + + CoreReschedule[ActualCore] = false; } if (NeedsReschedule) @@ -220,7 +219,7 @@ namespace Ryujinx.Core.OsHle.Handles RunThread(NewThread); } - TryResumingExecution(SchedThread); + Resume(Thread); } } diff --git a/Ryujinx.Core/OsHle/Handles/SchedulerThread.cs b/Ryujinx.Core/OsHle/Handles/SchedulerThread.cs index dd79b0f7..4a8b4c09 100644 --- a/Ryujinx.Core/OsHle/Handles/SchedulerThread.cs +++ b/Ryujinx.Core/OsHle/Handles/SchedulerThread.cs @@ -11,8 +11,6 @@ namespace Ryujinx.Core.OsHle.Handles public bool IsActive { get; set; } - public bool NeedsReschedule { get; set; } - public AutoResetEvent WaitSync { get; private set; } public ManualResetEvent WaitActivity { get; private set; } public AutoResetEvent WaitSched { get; private set; } diff --git a/Ryujinx.Core/OsHle/Handles/ThreadQueue.cs b/Ryujinx.Core/OsHle/Handles/ThreadQueue.cs index 41fbd81e..491b77c8 100644 --- a/Ryujinx.Core/OsHle/Handles/ThreadQueue.cs +++ b/Ryujinx.Core/OsHle/Handles/ThreadQueue.cs @@ -63,7 +63,7 @@ namespace Ryujinx.Core.OsHle.Handles { KThread Thread = Curr.Thread; - if (Thread.ActualPriority <= MinPriority && (Thread.CoreMask & CoreMask) != 0) + if (Thread.ActualPriority < MinPriority && (Thread.CoreMask & CoreMask) != 0) { if (Prev != null) { diff --git a/Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs b/Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs index 1d28a24b..e762c396 100644 --- a/Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs +++ b/Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs @@ -217,7 +217,6 @@ namespace Ryujinx.Core.OsHle.Kernel UpdateMutexOwner(CurrThread, OwnerThread, MutexAddress); CurrThread.UpdatePriority(); - OwnerThread.UpdatePriority(); int HasListeners = OwnerThread.MutexWaiters.Count > 0 ? MutexHasListenersMask : 0;