Only use higher priority on yield, change reschedule to be per-thread instead of using SchedulerThread to store the reschedule flag

This commit is contained in:
gdkchan 2018-05-15 23:49:57 -03:00
parent 73a3233d57
commit 9b9ead94cd
4 changed files with 13 additions and 17 deletions

View File

@ -13,6 +13,8 @@ namespace Ryujinx.Core.OsHle.Handles
private KThread[] CoreThreads; private KThread[] CoreThreads;
private bool[] CoreReschedule;
private object SchedLock; private object SchedLock;
private Logger Log; private Logger Log;
@ -27,6 +29,8 @@ namespace Ryujinx.Core.OsHle.Handles
CoreThreads = new KThread[4]; CoreThreads = new KThread[4];
CoreReschedule = new bool[4];
SchedLock = new object(); SchedLock = new object();
} }
@ -147,10 +151,10 @@ namespace Ryujinx.Core.OsHle.Handles
{ {
PrintDbgThreadInfo(Thread, "suspended."); PrintDbgThreadInfo(Thread, "suspended.");
AllThreads[Thread].NeedsReschedule = false;
int ActualCore = Thread.ActualCore; int ActualCore = Thread.ActualCore;
CoreReschedule[ActualCore] = false;
SchedulerThread SchedThread = WaitingToRun.Pop(ActualCore); SchedulerThread SchedThread = WaitingToRun.Pop(ActualCore);
if (SchedThread != null) if (SchedThread != null)
@ -174,26 +178,21 @@ namespace Ryujinx.Core.OsHle.Handles
{ {
lock (SchedLock) lock (SchedLock)
{ {
KThread Thread = CoreThreads[Core]; CoreReschedule[Core] = true;
if (Thread != null && AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread))
{
SchedThread.NeedsReschedule = true;
}
} }
} }
public void Reschedule(KThread Thread) public void Reschedule(KThread Thread)
{ {
SchedulerThread SchedThread = AllThreads[Thread];
bool NeedsReschedule; bool NeedsReschedule;
lock (SchedLock) lock (SchedLock)
{ {
NeedsReschedule = SchedThread.NeedsReschedule; int ActualCore = Thread.ActualCore;
SchedThread.NeedsReschedule = false; NeedsReschedule = CoreReschedule[ActualCore];
CoreReschedule[ActualCore] = false;
} }
if (NeedsReschedule) if (NeedsReschedule)
@ -220,7 +219,7 @@ namespace Ryujinx.Core.OsHle.Handles
RunThread(NewThread); RunThread(NewThread);
} }
TryResumingExecution(SchedThread); Resume(Thread);
} }
} }

View File

@ -11,8 +11,6 @@ namespace Ryujinx.Core.OsHle.Handles
public bool IsActive { get; set; } public bool IsActive { get; set; }
public bool NeedsReschedule { get; set; }
public AutoResetEvent WaitSync { get; private set; } public AutoResetEvent WaitSync { get; private set; }
public ManualResetEvent WaitActivity { get; private set; } public ManualResetEvent WaitActivity { get; private set; }
public AutoResetEvent WaitSched { get; private set; } public AutoResetEvent WaitSched { get; private set; }

View File

@ -63,7 +63,7 @@ namespace Ryujinx.Core.OsHle.Handles
{ {
KThread Thread = Curr.Thread; KThread Thread = Curr.Thread;
if (Thread.ActualPriority <= MinPriority && (Thread.CoreMask & CoreMask) != 0) if (Thread.ActualPriority < MinPriority && (Thread.CoreMask & CoreMask) != 0)
{ {
if (Prev != null) if (Prev != null)
{ {

View File

@ -217,7 +217,6 @@ namespace Ryujinx.Core.OsHle.Kernel
UpdateMutexOwner(CurrThread, OwnerThread, MutexAddress); UpdateMutexOwner(CurrThread, OwnerThread, MutexAddress);
CurrThread.UpdatePriority(); CurrThread.UpdatePriority();
OwnerThread.UpdatePriority();
int HasListeners = OwnerThread.MutexWaiters.Count > 0 ? MutexHasListenersMask : 0; int HasListeners = OwnerThread.MutexWaiters.Count > 0 ? MutexHasListenersMask : 0;