mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-08-03 11:23:49 +00:00
kernel: preserve microsecond wall-clock resolution
Extracted from 3db2b3c5c5e1a26a861df7ebcacd9ccb8c484420 in KytyPS5/KytyPS5#147.
This commit is contained in:
@@ -3886,8 +3886,12 @@ int KYTY_SYSV_ABI KernelGettimeofday(KernelTimeval* tp) {
|
||||
tp->tv_sec = static_cast<int64_t>(ticks / 1000000);
|
||||
tp->tv_usec = static_cast<int64_t>(ticks % 1000000);
|
||||
#else
|
||||
auto dt = Common::DateTime::FromSystemUTC();
|
||||
sec_to_timeval(tp, dt.ToUnix());
|
||||
struct timespec ts {};
|
||||
result = ::clock_gettime(CLOCK_REALTIME, &ts);
|
||||
if (result == 0) {
|
||||
tp->tv_sec = static_cast<int64_t>(ts.tv_sec);
|
||||
tp->tv_usec = static_cast<int64_t>(ts.tv_nsec / 1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (result == 0) {
|
||||
|
||||
+7
-14
@@ -4,6 +4,7 @@
|
||||
#include "libs/libs.h"
|
||||
#include "loader/symbolDatabase.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
@@ -247,20 +248,12 @@ static int KYTY_SYSV_ABI RtcGetCurrentTick(RtcTick* tick) {
|
||||
return RTC_ERROR_DATETIME_UNINITIALIZED;
|
||||
}
|
||||
|
||||
const auto now = Common::DateTime::FromSystemUTC();
|
||||
const auto date = now.GetDate();
|
||||
const auto tod = now.GetTime();
|
||||
|
||||
RtcDateTime time {};
|
||||
time.year = static_cast<uint16_t>(date.Year());
|
||||
time.month = static_cast<uint16_t>(date.Month());
|
||||
time.day = static_cast<uint16_t>(date.Day());
|
||||
time.hour = static_cast<uint16_t>(tod.Hour24());
|
||||
time.minute = static_cast<uint16_t>(tod.Minute());
|
||||
time.second = static_cast<uint16_t>(tod.Second());
|
||||
time.microsecond = static_cast<uint32_t>(tod.Msec() * 1000);
|
||||
|
||||
return RtcGetTick(&time, tick);
|
||||
const auto now_us =
|
||||
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
tick->tick = RTC_UNIX_EPOCH_TICKS + now_us;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int KYTY_SYSV_ABI RtcGetCurrentNetworkTick(RtcTick* tick) {
|
||||
|
||||
Reference in New Issue
Block a user