2018-10-28 22:31:13 +00:00
|
|
|
using Ryujinx.Common;
|
2018-09-19 00:36:43 +01:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
class KCoreContext
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
private KScheduler Scheduler;
|
2018-09-19 00:36:43 +01:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private HleCoreManager CoreManager;
|
2018-09-19 00:36:43 +01:00
|
|
|
|
|
|
|
public bool ContextSwitchNeeded { get; private set; }
|
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
public long LastContextSwitchTime { get; private set; }
|
|
|
|
|
|
|
|
public long TotalIdleTimeTicks { get; private set; } //TODO
|
|
|
|
|
2018-09-19 00:36:43 +01:00
|
|
|
public KThread CurrentThread { get; private set; }
|
|
|
|
public KThread SelectedThread { get; private set; }
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public KCoreContext(KScheduler Scheduler, HleCoreManager CoreManager)
|
2018-09-19 00:36:43 +01:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
this.Scheduler = Scheduler;
|
|
|
|
this.CoreManager = CoreManager;
|
2018-09-19 00:36:43 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void SelectThread(KThread Thread)
|
2018-09-19 00:36:43 +01:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
SelectedThread = Thread;
|
2018-09-19 00:36:43 +01:00
|
|
|
|
2018-09-19 16:16:20 +01:00
|
|
|
if (SelectedThread != CurrentThread)
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = true;
|
|
|
|
}
|
2018-09-19 00:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateCurrentThread()
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = false;
|
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
|
|
|
|
|
2018-09-19 00:36:43 +01:00
|
|
|
CurrentThread = SelectedThread;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
long CurrentTime = PerformanceCounter.ElapsedMilliseconds;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
CurrentThread.TotalTimeRunning += CurrentTime - CurrentThread.LastScheduledTime;
|
|
|
|
CurrentThread.LastScheduledTime = CurrentTime;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
2018-09-19 00:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ContextSwitch()
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = false;
|
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
|
|
|
|
|
2018-09-19 00:36:43 +01:00
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
CoreManager.Reset(CurrentThread.Context.Work);
|
2018-09-19 00:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CurrentThread = SelectedThread;
|
|
|
|
|
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
long CurrentTime = PerformanceCounter.ElapsedMilliseconds;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
CurrentThread.TotalTimeRunning += CurrentTime - CurrentThread.LastScheduledTime;
|
|
|
|
CurrentThread.LastScheduledTime = CurrentTime;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-09-19 00:36:43 +01:00
|
|
|
CurrentThread.ClearExclusive();
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
CoreManager.Set(CurrentThread.Context.Work);
|
2018-09-19 00:36:43 +01:00
|
|
|
|
|
|
|
CurrentThread.Context.Execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|