aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Time
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-05-31 16:29:35 -0300
committerGitHub <noreply@github.com>2022-05-31 16:29:35 -0300
commit0c87bf9ea4b0655fc6b90b4ab20e93f237e7549b (patch)
tree0fe100d5cd958bfb8f5974f1b614b94c09e89a26 /Ryujinx.HLE/HOS/Services/Time
parent9827dc35e14cb704cb4adcb894e0efbac893080c (diff)
Refactor CPU interface to allow the implementation of other CPU emulators (#3362)
* Refactor CPU interface * Use IExecutionContext interface on SVC handler, change how CPU interrupts invokes the handlers * Make CpuEngine take a ITickSource rather than returning one The previous implementation had the scenario where the CPU engine had to implement the tick source in mind, like for example, when we have a hypervisor and the game can read CNTPCT on the host directly. However given that we need to do conversion due to different frequencies anyway, it's not worth it. It's better to just let the user pass the tick source and redirect any reads to CNTPCT to the user tick source * XML docs for the public interfaces * PPTC invalidation due to NativeInterface function name changes * Fix build of the CPU tests * PR feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time')
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs8
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs20
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs19
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs12
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs20
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs16
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs33
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs18
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs5
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs13
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs3
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/TimeManager.cs28
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs27
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs5
14 files changed, 112 insertions, 115 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs
index b86f703d..aec03485 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs
@@ -1,4 +1,4 @@
-using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.Cpu;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
@@ -11,14 +11,14 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_standardNetworkClockSufficientAccuracy = new TimeSpanType(0);
}
- public bool IsStandardNetworkSystemClockAccuracySufficient(KThread thread)
+ public bool IsStandardNetworkSystemClockAccuracySufficient(ITickSource tickSource)
{
SteadyClockCore steadyClockCore = GetSteadyClockCore();
- SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
+ SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource);
bool isStandardNetworkClockSufficientAccuracy = false;
- ResultCode result = GetClockContext(thread, out SystemClockContext context);
+ ResultCode result = GetClockContext(tickSource, out SystemClockContext context);
if (result == ResultCode.Success && context.SteadyTimePoint.GetSpanBetween(currentTimePoint, out long outSpan) == ResultCode.Success)
{
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
index 370e7d73..8392c4b5 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardSteadyClockCore.cs
@@ -1,4 +1,4 @@
-using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.Cpu;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
@@ -17,11 +17,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_cachedRawTimePoint = TimeSpanType.Zero;
}
- public override SteadyClockTimePoint GetTimePoint(KThread thread)
+ public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
{
SteadyClockTimePoint result = new SteadyClockTimePoint
{
- TimePoint = GetCurrentRawTimePoint(thread).ToSeconds(),
+ TimePoint = GetCurrentRawTimePoint(tickSource).ToSeconds(),
ClockSourceId = GetClockSourceId()
};
@@ -48,19 +48,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_internalOffset = internalOffset;
}
- public override TimeSpanType GetCurrentRawTimePoint(KThread thread)
+ public override TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
{
- TimeSpanType ticksTimeSpan;
-
- // As this may be called before the guest code, we support passing a null thread to make this api usable.
- if (thread == null)
- {
- ticksTimeSpan = TimeSpanType.FromSeconds(0);
- }
- else
- {
- ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
- }
+ TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
TimeSpanType rawTimePoint = new TimeSpanType(_setupValue.NanoSeconds + ticksTimeSpan.NanoSeconds);
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs
index 2499b549..fa485437 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/StandardUserSystemClockCore.cs
@@ -1,4 +1,5 @@
-using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.Cpu;
+using Ryujinx.HLE.HOS.Kernel.Threading;
using System;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
@@ -26,15 +27,15 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
throw new NotImplementedException();
}
- public override ResultCode GetClockContext(KThread thread, out SystemClockContext context)
+ public override ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
{
- ResultCode result = ApplyAutomaticCorrection(thread, false);
+ ResultCode result = ApplyAutomaticCorrection(tickSource, false);
context = new SystemClockContext();
if (result == ResultCode.Success)
{
- return _localSystemClockCore.GetClockContext(thread, out context);
+ return _localSystemClockCore.GetClockContext(tickSource, out context);
}
return result;
@@ -45,13 +46,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
return ResultCode.NotImplemented;
}
- private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
+ private ResultCode ApplyAutomaticCorrection(ITickSource tickSource, bool autoCorrectionEnabled)
{
ResultCode result = ResultCode.Success;
- if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
+ if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(tickSource))
{
- result = _networkSystemClockCore.GetClockContext(thread, out SystemClockContext context);
+ result = _networkSystemClockCore.GetClockContext(tickSource, out SystemClockContext context);
if (result == ResultCode.Success)
{
@@ -67,9 +68,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_autoCorrectionEvent = new KEvent(system.KernelContext);
}
- public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
+ public ResultCode SetAutomaticCorrectionEnabled(ITickSource tickSource, bool autoCorrectionEnabled)
{
- ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
+ ResultCode result = ApplyAutomaticCorrection(tickSource, autoCorrectionEnabled);
if (result == ResultCode.Success)
{
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs
index 83ace981..4bb19e75 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/SteadyClockCore.cs
@@ -1,4 +1,4 @@
-using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.Cpu;
using Ryujinx.HLE.Utilities;
using System;
@@ -63,21 +63,21 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
public virtual void SetInternalOffset(TimeSpanType internalOffset) {}
- public virtual SteadyClockTimePoint GetTimePoint(KThread thread)
+ public virtual SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
{
throw new NotImplementedException();
}
- public virtual TimeSpanType GetCurrentRawTimePoint(KThread thread)
+ public virtual TimeSpanType GetCurrentRawTimePoint(ITickSource tickSource)
{
- SteadyClockTimePoint timePoint = GetTimePoint(thread);
+ SteadyClockTimePoint timePoint = GetTimePoint(tickSource);
return TimeSpanType.FromSeconds(timePoint.TimePoint);
}
- public SteadyClockTimePoint GetCurrentTimePoint(KThread thread)
+ public SteadyClockTimePoint GetCurrentTimePoint(ITickSource tickSource)
{
- SteadyClockTimePoint result = GetTimePoint(thread);
+ SteadyClockTimePoint result = GetTimePoint(tickSource);
result.TimePoint += GetTestOffset().ToSeconds();
result.TimePoint += GetInternalOffset().ToSeconds();
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs
index 865b1c09..f4bbaa60 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/SystemClockCore.cs
@@ -1,4 +1,4 @@
-using System;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Threading;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
@@ -25,13 +25,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
return _steadyClockCore;
}
- public ResultCode GetCurrentTime(KThread thread, out long posixTime)
+ public ResultCode GetCurrentTime(ITickSource tickSource, out long posixTime)
{
posixTime = 0;
- SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
+ SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
- ResultCode result = GetClockContext(thread, out SystemClockContext clockContext);
+ ResultCode result = GetClockContext(tickSource, out SystemClockContext clockContext);
if (result == ResultCode.Success)
{
@@ -48,9 +48,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
return result;
}
- public ResultCode SetCurrentTime(KThread thread, long posixTime)
+ public ResultCode SetCurrentTime(ITickSource tickSource, long posixTime)
{
- SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
+ SteadyClockTimePoint currentTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
SystemClockContext clockContext = new SystemClockContext()
{
@@ -68,7 +68,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
return result;
}
- public virtual ResultCode GetClockContext(KThread thread, out SystemClockContext context)
+ public virtual ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
{
context = _context;
@@ -127,13 +127,13 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
_isInitialized = true;
}
- public bool IsClockSetup(KThread thread)
+ public bool IsClockSetup(ITickSource tickSource)
{
- ResultCode result = GetClockContext(thread, out SystemClockContext context);
+ ResultCode result = GetClockContext(tickSource, out SystemClockContext context);
if (result == ResultCode.Success)
{
- SteadyClockTimePoint steadyClockTimePoint = _steadyClockCore.GetCurrentTimePoint(thread);
+ SteadyClockTimePoint steadyClockTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);
return steadyClockTimePoint.ClockSourceId == context.SteadyTimePoint.ClockSourceId;
}
diff --git a/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs b/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs
index 06502082..fe74da7e 100644
--- a/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/Clock/TickBasedSteadyClockCore.cs
@@ -1,4 +1,4 @@
-using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.Cpu;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
public TickBasedSteadyClockCore() {}
- public override SteadyClockTimePoint GetTimePoint(KThread thread)
+ public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
{
SteadyClockTimePoint result = new SteadyClockTimePoint
{
@@ -14,17 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
ClockSourceId = GetClockSourceId()
};
- TimeSpanType ticksTimeSpan;
-
- // As this may be called before the guest code, we support passing a null thread to make this api usable.
- if (thread == null)
- {
- ticksTimeSpan = TimeSpanType.FromSeconds(0);
- }
- else
- {
- ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
- }
+ TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
result.TimePoint = ticksTimeSpan.ToSeconds();
diff --git a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
index 534af457..441e4267 100644
--- a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
@@ -2,7 +2,6 @@ using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
-using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.HOS.Services.Time.StaticService;
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
@@ -163,13 +162,15 @@ namespace Ryujinx.HLE.HOS.Services.Time
bool autoCorrectionEnabled = context.RequestData.ReadBoolean();
- ResultCode result = userClock.SetAutomaticCorrectionEnabled(context.Thread, autoCorrectionEnabled);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ ResultCode result = userClock.SetAutomaticCorrectionEnabled(tickSource, autoCorrectionEnabled);
if (result == ResultCode.Success)
{
_timeManager.SharedMemory.SetAutomaticCorrectionEnabled(autoCorrectionEnabled);
- SteadyClockTimePoint currentTimePoint = userClock.GetSteadyClockCore().GetCurrentTimePoint(context.Thread);
+ SteadyClockTimePoint currentTimePoint = userClock.GetSteadyClockCore().GetCurrentTimePoint(tickSource);
userClock.SetAutomaticCorrectionUpdatedTime(currentTimePoint);
userClock.SignalAutomaticCorrectionEvent();
@@ -190,7 +191,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
// IsStandardNetworkSystemClockAccuracySufficient() -> bool
public ResultCode IsStandardNetworkSystemClockAccuracySufficient(ServiceCtx context)
{
- context.ResponseData.Write(_timeManager.StandardNetworkSystemClock.IsStandardNetworkSystemClockAccuracySufficient(context.Thread));
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ context.ResponseData.Write(_timeManager.StandardNetworkSystemClock.IsStandardNetworkSystemClockAccuracySufficient(tickSource));
return ResultCode.Success;
}
@@ -222,14 +225,16 @@ namespace Ryujinx.HLE.HOS.Services.Time
return ResultCode.UninitializedClock;
}
+ ITickSource tickSource = context.Device.System.TickSource;
+
SystemClockContext otherContext = context.RequestData.ReadStruct<SystemClockContext>();
- SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(context.Thread);
+ SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(tickSource);
ResultCode result = ResultCode.TimeMismatch;
if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
{
- TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(context.Thread.Context.CntpctEl0, context.Thread.Context.CntfrqEl0);
+ TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();
context.ResponseData.Write(baseTimePoint);
@@ -248,15 +253,17 @@ namespace Ryujinx.HLE.HOS.Services.Time
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf<ClockSnapshot>());
- ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(context.Thread, out SystemClockContext userContext);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(tickSource, out SystemClockContext userContext);
if (result == ResultCode.Success)
{
- result = _timeManager.StandardNetworkSystemClock.GetClockContext(context.Thread, out SystemClockContext networkContext);
+ result = _timeManager.StandardNetworkSystemClock.GetClockContext(tickSource, out SystemClockContext networkContext);
if (result == ResultCode.Success)
{
- result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
+ result = GetClockSnapshotFromSystemClockContextInternal(tickSource, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
if (result == ResultCode.Success)
{
@@ -281,7 +288,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
SystemClockContext userContext = context.RequestData.ReadStruct<SystemClockContext>();
SystemClockContext networkContext = context.RequestData.ReadStruct<SystemClockContext>();
- ResultCode result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ ResultCode result = GetClockSnapshotFromSystemClockContextInternal(tickSource, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
if (result == ResultCode.Success)
{
@@ -344,12 +353,12 @@ namespace Ryujinx.HLE.HOS.Services.Time
return resultCode;
}
- private ResultCode GetClockSnapshotFromSystemClockContextInternal(KThread thread, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot)
+ private ResultCode GetClockSnapshotFromSystemClockContextInternal(ITickSource tickSource, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot)
{
clockSnapshot = new ClockSnapshot();
SteadyClockCore steadyClockCore = _timeManager.StandardSteadyClock;
- SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
+ SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource);
clockSnapshot.IsAutomaticCorrectionEnabled = _timeManager.StandardUserSystemClock.IsAutomaticCorrectionEnabled();
clockSnapshot.UserContext = userContext;
diff --git a/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs b/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs
index be71bb4f..1ff5b2d6 100644
--- a/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/ITimeServiceManager.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
@@ -6,7 +7,6 @@ using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.Utilities;
using System;
using System.IO;
-using System.Text;
namespace Ryujinx.HLE.HOS.Services.Time
{
@@ -68,7 +68,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
TimeSpanType testOffset = context.RequestData.ReadStruct<TimeSpanType>();
bool isRtcResetDetected = context.RequestData.ReadBoolean();
- _timeManager.SetupStandardSteadyClock(context.Thread, clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ _timeManager.SetupStandardSteadyClock(tickSource, clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
return ResultCode.Success;
}
@@ -80,7 +82,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>();
long posixTime = context.RequestData.ReadInt64();
- _timeManager.SetupStandardLocalSystemClock(context.Thread, clockContext, posixTime);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ _timeManager.SetupStandardLocalSystemClock(tickSource, clockContext, posixTime);
return ResultCode.Success;
}
@@ -107,7 +111,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
SteadyClockTimePoint steadyClockTimePoint = context.RequestData.ReadStruct<SteadyClockTimePoint>();
- _timeManager.SetupStandardUserSystemClock(context.Thread, isAutomaticCorrectionEnabled, steadyClockTimePoint);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ _timeManager.SetupStandardUserSystemClock(tickSource, isAutomaticCorrectionEnabled, steadyClockTimePoint);
return ResultCode.Success;
}
@@ -191,7 +197,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
{
TimeSpanType rtcOffset = context.RequestData.ReadStruct<TimeSpanType>();
- _timeManager.SetStandardSteadyClockRtcOffset(context.Thread, rtcOffset);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ _timeManager.SetStandardSteadyClockRtcOffset(tickSource, rtcOffset);
return ResultCode.Success;
}
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs
index a5ce8d6a..1e517713 100644
--- a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISteadyClock.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Services.Time.Clock;
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
@@ -25,7 +26,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
return ResultCode.UninitializedClock;
}
- SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(context.Thread);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(tickSource);
context.ResponseData.WriteStruct(currentTimePoint);
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs
index 1d9f7873..085cc71d 100644
--- a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
@@ -31,7 +32,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
return ResultCode.UninitializedClock;
}
- ResultCode result = _clockCore.GetCurrentTime(context.Thread, out long posixTime);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ ResultCode result = _clockCore.GetCurrentTime(tickSource, out long posixTime);
if (result == ResultCode.Success)
{
@@ -57,7 +60,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
long posixTime = context.RequestData.ReadInt64();
- return _clockCore.SetCurrentTime(context.Thread, posixTime);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ return _clockCore.SetCurrentTime(tickSource, posixTime);
}
[CommandHipc(2)]
@@ -69,7 +74,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
return ResultCode.UninitializedClock;
}
- ResultCode result = _clockCore.GetClockContext(context.Thread, out SystemClockContext clockContext);
+ ITickSource tickSource = context.Device.System.TickSource;
+
+ ResultCode result = _clockCore.GetClockContext(tickSource, out SystemClockContext clockContext);
if (result == ResultCode.Success)
{
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs
index 83d745e3..202099b0 100644
--- a/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForPsc.cs
@@ -7,7 +7,6 @@ using Ryujinx.HLE.Utilities;
using System;
using System.Diagnostics;
using System.IO;
-using System.Text;
namespace Ryujinx.HLE.HOS.Services.Time.StaticService
{
@@ -44,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
{
return ResultCode.PermissionDenied;
}
-
+
return ResultCode.NotImplemented;
}
diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs
index e2217890..ac9f0880 100644
--- a/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/TimeManager.cs
@@ -1,11 +1,10 @@
-using System;
-using System.IO;
+using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Kernel.Memory;
-using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
using Ryujinx.HLE.Utilities;
+using System.IO;
namespace Ryujinx.HLE.HOS.Services.Time
{
@@ -68,14 +67,13 @@ namespace Ryujinx.HLE.HOS.Services.Time
TimeZone.Initialize(this, device);
}
-
- public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
+ public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
{
SetupInternalStandardSteadyClock(clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);
- TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);
+ TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);
- SharedMemory.SetupStandardSteadyClock(thread, clockSourceId, currentTimePoint);
+ SharedMemory.SetupStandardSteadyClock(tickSource, clockSourceId, currentTimePoint);
// TODO: propagate IPC late binding of "time:s" and "time:p"
}
@@ -97,18 +95,18 @@ namespace Ryujinx.HLE.HOS.Services.Time
// TODO: propagate IPC late binding of "time:s" and "time:p"
}
- public void SetupStandardLocalSystemClock(KThread thread, SystemClockContext clockContext, long posixTime)
+ public void SetupStandardLocalSystemClock(ITickSource tickSource, SystemClockContext clockContext, long posixTime)
{
StandardLocalSystemClock.SetUpdateCallbackInstance(LocalClockContextWriter);
- SteadyClockTimePoint currentTimePoint = StandardLocalSystemClock.GetSteadyClockCore().GetCurrentTimePoint(thread);
+ SteadyClockTimePoint currentTimePoint = StandardLocalSystemClock.GetSteadyClockCore().GetCurrentTimePoint(tickSource);
if (currentTimePoint.ClockSourceId == clockContext.SteadyTimePoint.ClockSourceId)
{
StandardLocalSystemClock.SetSystemClockContext(clockContext);
}
else
{
- if (StandardLocalSystemClock.SetCurrentTime(thread, posixTime) != ResultCode.Success)
+ if (StandardLocalSystemClock.SetCurrentTime(tickSource, posixTime) != ResultCode.Success)
{
throw new InternalServiceException("Cannot set current local time");
}
@@ -157,9 +155,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
// TODO: propagate IPC late binding of "time:s" and "time:p"
}
- public void SetupStandardUserSystemClock(KThread thread, bool isAutomaticCorrectionEnabled, SteadyClockTimePoint steadyClockTimePoint)
+ public void SetupStandardUserSystemClock(ITickSource tickSource, bool isAutomaticCorrectionEnabled, SteadyClockTimePoint steadyClockTimePoint)
{
- if (StandardUserSystemClock.SetAutomaticCorrectionEnabled(thread, isAutomaticCorrectionEnabled) != ResultCode.Success)
+ if (StandardUserSystemClock.SetAutomaticCorrectionEnabled(tickSource, isAutomaticCorrectionEnabled) != ResultCode.Success)
{
throw new InternalServiceException("Cannot set automatic user time correction state");
}
@@ -172,13 +170,13 @@ namespace Ryujinx.HLE.HOS.Services.Time
// TODO: propagate IPC late binding of "time:s" and "time:p"
}
- public void SetStandardSteadyClockRtcOffset(KThread thread, TimeSpanType rtcOffset)
+ public void SetStandardSteadyClockRtcOffset(ITickSource tickSource, TimeSpanType rtcOffset)
{
StandardSteadyClock.SetSetupValue(rtcOffset);
- TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);
+ TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);
- SharedMemory.SetSteadyClockRawTimePoint(thread, currentTimePoint);
+ SharedMemory.SetSteadyClockRawTimePoint(tickSource, currentTimePoint);
}
}
}
diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs
index 8b08b040..7063290b 100644
--- a/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/TimeSharedMemory.cs
@@ -1,12 +1,11 @@
-using System;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Memory;
-using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.HOS.Services.Time.Types;
using Ryujinx.HLE.Utilities;
+using System;
+using System.Runtime.CompilerServices;
+using System.Threading;
namespace Ryujinx.HLE.HOS.Services.Time
{
@@ -38,19 +37,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
return _sharedMemory;
}
- public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType currentTimePoint)
+ public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType currentTimePoint)
{
- TimeSpanType ticksTimeSpan;
-
- // As this may be called before the guest code, we support passing a null thread to make this api usable.
- if (thread == null)
- {
- ticksTimeSpan = TimeSpanType.FromSeconds(0);
- }
- else
- {
- ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
- }
+ TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
SteadyClockContext context = new SteadyClockContext
{
@@ -67,10 +56,10 @@ namespace Ryujinx.HLE.HOS.Services.Time
WriteObjectToSharedMemory(AutomaticCorrectionEnabledOffset, 0, Convert.ToByte(isAutomaticCorrectionEnabled));
}
- public void SetSteadyClockRawTimePoint(KThread thread, TimeSpanType currentTimePoint)
+ public void SetSteadyClockRawTimePoint(ITickSource tickSource, TimeSpanType currentTimePoint)
{
SteadyClockContext context = ReadObjectFromSharedMemory<SteadyClockContext>(SteadyClockContextOffset, 4);
- TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);
+ TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds);
diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs
index 8ff09026..141c2b4a 100644
--- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZoneContentManager.cs
@@ -7,6 +7,7 @@ using LibHac.Ncm;
using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Common.Logging;
+using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Services.Time.Clock;
@@ -63,7 +64,9 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
{
InitializeInstance(device.FileSystem, device.System.ContentManager, device.System.FsIntegrityCheckLevel);
- SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(null);
+ ITickSource tickSource = device.System.TickSource;
+
+ SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(tickSource);
string deviceLocationName = SanityCheckDeviceLocationName(device.Configuration.TimeZone);