diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2018-04-25 23:11:26 -0300 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2018-04-25 23:12:26 -0300 |
| commit | a38a72b0622f89897bdcd01b6d00ea6bc142c34f (patch) | |
| tree | 2025cdddaa7ef6769ac69c51eeede0924ffcba5f /Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs | |
| parent | 211f7f69db4d84b82caa3ee62d4ecdfbbd95604d (diff) | |
Some small sync primitive fixes, logging fixes, started to implement the 2D engine on the GPU, fixed DrawArrays, implemented a few more shader instructions, made a start on nvdrv refactor, etc...
Diffstat (limited to 'Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs')
| -rw-r--r-- | Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs | 154 |
1 files changed, 69 insertions, 85 deletions
diff --git a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs index c601d522..1c35b23c 100644 --- a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs +++ b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs @@ -14,23 +14,23 @@ namespace Ryujinx.Core.OsHle.Handles { public KThread Thread { get; private set; } - public ManualResetEvent SyncWaitEvent { get; private set; } - public AutoResetEvent SchedWaitEvent { get; private set; } + public bool IsActive { get; set; } - public bool Active { get; set; } - - public int SyncTimeout { get; set; } + public AutoResetEvent WaitSync { get; private set; } + public ManualResetEvent WaitActivity { get; private set; } + public AutoResetEvent WaitSched { get; private set; } public SchedulerThread(KThread Thread) { this.Thread = Thread; - SyncWaitEvent = new ManualResetEvent(true); - SchedWaitEvent = new AutoResetEvent(false); + IsActive = true; + + WaitSync = new AutoResetEvent(false); - Active = true; + WaitActivity = new ManualResetEvent(true); - SyncTimeout = 0; + WaitSched = new AutoResetEvent(false); } public void Dispose() @@ -42,8 +42,11 @@ namespace Ryujinx.Core.OsHle.Handles { if (Disposing) { - SyncWaitEvent.Dispose(); - SchedWaitEvent.Dispose(); + WaitSync.Dispose(); + + WaitActivity.Dispose(); + + WaitSched.Dispose(); } } } @@ -206,67 +209,56 @@ namespace Ryujinx.Core.OsHle.Handles throw new InvalidOperationException(); } - SchedThread.Active = Active; + SchedThread.IsActive = Active; - UpdateSyncWaitEvent(SchedThread); - - WaitIfNeeded(SchedThread); + if (Active) + { + SchedThread.WaitActivity.Set(); + } + else + { + SchedThread.WaitActivity.Reset(); + } } - public bool EnterWait(KThread Thread, int Timeout = -1) + public void EnterWait(KThread Thread) { if (!AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) { throw new InvalidOperationException(); } - SchedThread.SyncTimeout = Timeout; + Suspend(Thread.ProcessorId); - UpdateSyncWaitEvent(SchedThread); + SchedThread.WaitSync.WaitOne(); - return WaitIfNeeded(SchedThread); + TryResumingExecution(SchedThread); } - public void WakeUp(KThread Thread) + public bool EnterWait(KThread Thread, int Timeout) { if (!AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) { throw new InvalidOperationException(); } - SchedThread.SyncTimeout = 0; + Suspend(Thread.ProcessorId); - UpdateSyncWaitEvent(SchedThread); + bool Result = SchedThread.WaitSync.WaitOne(Timeout); - WaitIfNeeded(SchedThread); - } + TryResumingExecution(SchedThread); - private void UpdateSyncWaitEvent(SchedulerThread SchedThread) - { - if (SchedThread.Active && SchedThread.SyncTimeout == 0) - { - SchedThread.SyncWaitEvent.Set(); - } - else - { - SchedThread.SyncWaitEvent.Reset(); - } + return Result; } - private bool WaitIfNeeded(SchedulerThread SchedThread) + public void WakeUp(KThread Thread) { - KThread Thread = SchedThread.Thread; - - if (!IsActive(SchedThread) && Thread.Thread.IsCurrentThread()) - { - Suspend(Thread.ProcessorId); - - return Resume(Thread); - } - else + if (!AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) { - return false; + throw new InvalidOperationException(); } + + SchedThread.WaitSync.Set(); } public void Suspend(int ProcessorId) @@ -292,53 +284,52 @@ namespace Ryujinx.Core.OsHle.Handles { PrintDbgThreadInfo(Thread, "yielded execution."); - lock (SchedLock) + if (IsActive(Thread)) { - SchedulerThread SchedThread = WaitingToRun[Thread.ProcessorId].Pop(Thread.ActualPriority); - - if (IsActive(Thread) && SchedThread == null) + lock (SchedLock) { - PrintDbgThreadInfo(Thread, "resumed because theres nothing better to run."); + SchedulerThread SchedThread = WaitingToRun[Thread.ProcessorId].Pop(Thread.ActualPriority); - return; - } + if (SchedThread == null) + { + PrintDbgThreadInfo(Thread, "resumed because theres nothing better to run."); - if (SchedThread != null) - { - RunThread(SchedThread); + return; + } + + if (SchedThread != null) + { + RunThread(SchedThread); + } } } + else + { + //Just stop running the thread if it's not active, + //and run whatever is waiting to run with the higuest priority. + Suspend(Thread.ProcessorId); + } Resume(Thread); } - public bool Resume(KThread Thread) + public void Resume(KThread Thread) { if (!AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) { throw new InvalidOperationException(); } - return TryResumingExecution(SchedThread); + TryResumingExecution(SchedThread); } - private bool TryResumingExecution(SchedulerThread SchedThread) + private void TryResumingExecution(SchedulerThread SchedThread) { KThread Thread = SchedThread.Thread; - if (!SchedThread.Active || SchedThread.SyncTimeout != 0) - { - PrintDbgThreadInfo(Thread, "entering inactive wait state..."); - } - - bool Result = false; - - if (SchedThread.SyncTimeout != 0) - { - Result = SchedThread.SyncWaitEvent.WaitOne(SchedThread.SyncTimeout); + PrintDbgThreadInfo(Thread, "trying to resume..."); - SchedThread.SyncTimeout = 0; - } + SchedThread.WaitActivity.WaitOne(); lock (SchedLock) { @@ -346,7 +337,7 @@ namespace Ryujinx.Core.OsHle.Handles { PrintDbgThreadInfo(Thread, "resuming execution..."); - return Result; + return; } WaitingToRun[Thread.ProcessorId].Push(SchedThread); @@ -354,18 +345,16 @@ namespace Ryujinx.Core.OsHle.Handles PrintDbgThreadInfo(Thread, "entering wait state..."); } - SchedThread.SchedWaitEvent.WaitOne(); + SchedThread.WaitSched.WaitOne(); PrintDbgThreadInfo(Thread, "resuming execution..."); - - return Result; } private void RunThread(SchedulerThread SchedThread) { if (!SchedThread.Thread.Thread.Execute()) { - SchedThread.SchedWaitEvent.Set(); + SchedThread.WaitSched.Set(); } else { @@ -380,21 +369,16 @@ namespace Ryujinx.Core.OsHle.Handles throw new InvalidOperationException(); } - return IsActive(SchedThread); - } - - private bool IsActive(SchedulerThread SchedThread) - { - return SchedThread.Active && SchedThread.SyncTimeout == 0; + return SchedThread.IsActive; } private void PrintDbgThreadInfo(KThread Thread, string Message) { Log.PrintDebug(LogClass.KernelScheduler, "(" + - "ThreadId: " + Thread.ThreadId + ", " + - "ProcessorId: " + Thread.ProcessorId + ", " + - "ActualPriority: " + Thread.ActualPriority + ", " + - "WantedPriority: " + Thread.WantedPriority + ") " + Message); + "ThreadId = " + Thread.ThreadId + ", " + + "ProcessorId = " + Thread.ProcessorId + ", " + + "ActualPriority = " + Thread.ActualPriority + ", " + + "WantedPriority = " + Thread.WantedPriority + ") " + Message); } public void Dispose() |
