mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 03:16:54 +02: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_sec = static_cast<int64_t>(ticks / 1000000);
|
||||||
tp->tv_usec = static_cast<int64_t>(ticks % 1000000);
|
tp->tv_usec = static_cast<int64_t>(ticks % 1000000);
|
||||||
#else
|
#else
|
||||||
auto dt = Common::DateTime::FromSystemUTC();
|
struct timespec ts {};
|
||||||
sec_to_timeval(tp, dt.ToUnix());
|
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
|
#endif
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
|||||||
+7
-14
@@ -4,6 +4,7 @@
|
|||||||
#include "libs/libs.h"
|
#include "libs/libs.h"
|
||||||
#include "loader/symbolDatabase.h"
|
#include "loader/symbolDatabase.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -247,20 +248,12 @@ static int KYTY_SYSV_ABI RtcGetCurrentTick(RtcTick* tick) {
|
|||||||
return RTC_ERROR_DATETIME_UNINITIALIZED;
|
return RTC_ERROR_DATETIME_UNINITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto now = Common::DateTime::FromSystemUTC();
|
const auto now_us =
|
||||||
const auto date = now.GetDate();
|
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(
|
||||||
const auto tod = now.GetTime();
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
|
.count());
|
||||||
RtcDateTime time {};
|
tick->tick = RTC_UNIX_EPOCH_TICKS + now_us;
|
||||||
time.year = static_cast<uint16_t>(date.Year());
|
return OK;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int KYTY_SYSV_ABI RtcGetCurrentNetworkTick(RtcTick* tick) {
|
static int KYTY_SYSV_ABI RtcGetCurrentNetworkTick(RtcTick* tick) {
|
||||||
|
|||||||
Reference in New Issue
Block a user