libraries: kernel: fix for inaccurate `sceKernelGetProcessTime`

This commit is contained in:
psucien 2024-08-25 23:29:22 +02:00
parent 6fd4264b5d
commit 78e24852f8
3 changed files with 12 additions and 10 deletions

View File

@ -18,16 +18,16 @@ NativeClock::NativeClock()
us_rdtsc_factor{GetFixedPoint64Factor(std::micro::den, rdtsc_frequency)},
ms_rdtsc_factor{GetFixedPoint64Factor(std::milli::den, rdtsc_frequency)} {}
u64 NativeClock::GetTimeNS() const {
return MultiplyHigh(GetUptime(), ns_rdtsc_factor);
u64 NativeClock::GetTimeNS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, ns_rdtsc_factor);
}
u64 NativeClock::GetTimeUS() const {
return MultiplyHigh(GetUptime(), us_rdtsc_factor);
u64 NativeClock::GetTimeUS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, us_rdtsc_factor);
}
u64 NativeClock::GetTimeMS() const {
return MultiplyHigh(GetUptime(), ms_rdtsc_factor);
u64 NativeClock::GetTimeMS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, ms_rdtsc_factor);
}
u64 NativeClock::GetUptime() const {

View File

@ -16,9 +16,9 @@ public:
return rdtsc_frequency;
}
u64 GetTimeNS() const;
u64 GetTimeUS() const;
u64 GetTimeMS() const;
u64 GetTimeNS(u64 base_ptc = 0) const;
u64 GetTimeUS(u64 base_ptc = 0) const;
u64 GetTimeMS(u64 base_ptc = 0) const;
u64 GetUptime() const;
u64 GetProcessTimeUS() const;

View File

@ -3,6 +3,7 @@
#include <thread>
#include "common/assert.h"
#include "common/debug.h"
#include "common/native_clock.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/time_management.h"
@ -30,7 +31,8 @@ u64 PS4_SYSV_ABI sceKernelGetTscFrequency() {
}
u64 PS4_SYSV_ABI sceKernelGetProcessTime() {
return clock->GetProcessTimeUS();
// TODO: this timer should support suspends, so initial ptc needs to be updated on wake up
return clock->GetTimeUS(initial_ptc);
}
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() {