summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.h
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-09 16:53:22 -0400
committerGravatar Fernando Sahmkow2020-06-18 16:29:17 -0400
commit234b5ff6a999d7d69cdcdf214e0c3984cdab11cf (patch)
tree4f0ef41d7738b53d1b81ac2f7072bec1ba5fe8f1 /src/common/wall_clock.h
parentTests: Add base tests to host timing (diff)
downloadyuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.gz
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.tar.xz
yuzu-234b5ff6a999d7d69cdcdf214e0c3984cdab11cf.zip
Common: Implement WallClock Interface and implement a native clock for x64
Diffstat (limited to 'src/common/wall_clock.h')
-rw-r--r--src/common/wall_clock.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
new file mode 100644
index 000000000..6f763d74b
--- /dev/null
+++ b/src/common/wall_clock.h
@@ -0,0 +1,40 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <chrono>
8
9#include "common/common_types.h"
10
11namespace Common {
12
13class WallClock {
14public:
15 virtual std::chrono::nanoseconds GetTimeNS() = 0;
16 virtual std::chrono::microseconds GetTimeUS() = 0;
17 virtual std::chrono::milliseconds GetTimeMS() = 0;
18 virtual u64 GetClockCycles() = 0;
19 virtual u64 GetCPUCycles() = 0;
20
21 /// Tells if the wall clock, uses the host CPU's hardware clock
22 bool IsNative() const {
23 return is_native;
24 }
25
26protected:
27 WallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, bool is_native)
28 : emulated_cpu_frequency{emulated_cpu_frequency},
29 emulated_clock_frequency{emulated_clock_frequency}, is_native{is_native} {}
30
31 u64 emulated_cpu_frequency;
32 u64 emulated_clock_frequency;
33
34private:
35 bool is_native;
36};
37
38WallClock* CreateBestMatchingClock(u32 emulated_cpu_frequency, u32 emulated_clock_frequency);
39
40} // namespace Common