2024-02-14 22:52:57 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "common/native_clock.h"
|
|
|
|
#include "common/rdtsc.h"
|
2024-02-23 20:57:57 +00:00
|
|
|
#include "common/uint128.h"
|
2024-02-14 22:52:57 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
#include <pthread_time.h>
|
|
|
|
#else
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
NativeClock::NativeClock()
|
2024-02-23 20:57:57 +00:00
|
|
|
: rdtsc_frequency{EstimateRDTSCFrequency()}, ns_rdtsc_factor{GetFixedPoint64Factor(
|
|
|
|
std::nano::den, rdtsc_frequency)},
|
2024-02-14 22:52:57 +00:00
|
|
|
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::GetTimeUS() const {
|
|
|
|
return MultiplyHigh(GetUptime(), us_rdtsc_factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 NativeClock::GetTimeMS() const {
|
|
|
|
return MultiplyHigh(GetUptime(), ms_rdtsc_factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 NativeClock::GetUptime() const {
|
|
|
|
return FencedRDTSC();
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 NativeClock::GetProcessTimeUS() const {
|
|
|
|
timespec ret;
|
|
|
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ret);
|
|
|
|
return ret.tv_nsec / 1000 + ret.tv_sec * 1000000;
|
|
|
|
}
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
} // namespace Common
|