summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-25 11:09:31 -0700
committerGravatar GitHub2018-07-25 11:09:31 -0700
commit657bd113e35edc9e36037c8529a1c1027c15c5fd (patch)
treea8b6bd2227ba84cb4dd3d5a54d0c6d18a3d631d9 /src/core/core_timing.cpp
parentMerge pull request #802 from lioncash/unreach (diff)
parentcore_timing: Split off utility functions into core_timing_util (diff)
downloadyuzu-657bd113e35edc9e36037c8529a1c1027c15c5fd.tar.gz
yuzu-657bd113e35edc9e36037c8529a1c1027c15c5fd.tar.xz
yuzu-657bd113e35edc9e36037c8529a1c1027c15c5fd.zip
Merge pull request #803 from MerryMage/core_timing_util
core_timing: Split off utility functions into core_timing_util
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp53
1 files changed, 1 insertions, 52 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 50d1e3fc9..a1b6f96f1 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -5,17 +5,15 @@
5#include "core/core_timing.h" 5#include "core/core_timing.h"
6 6
7#include <algorithm> 7#include <algorithm>
8#include <cinttypes>
9#include <limits>
10#include <mutex> 8#include <mutex>
11#include <string> 9#include <string>
12#include <tuple> 10#include <tuple>
13#include <unordered_map> 11#include <unordered_map>
14#include <vector> 12#include <vector>
15#include "common/assert.h" 13#include "common/assert.h"
16#include "common/logging/log.h"
17#include "common/thread.h" 14#include "common/thread.h"
18#include "common/threadsafe_queue.h" 15#include "common/threadsafe_queue.h"
16#include "core/core_timing_util.h"
19 17
20namespace CoreTiming { 18namespace CoreTiming {
21 19
@@ -59,7 +57,6 @@ static u64 event_fifo_id;
59static Common::MPSCQueue<Event, false> ts_queue; 57static Common::MPSCQueue<Event, false> ts_queue;
60 58
61constexpr int MAX_SLICE_LENGTH = 20000; 59constexpr int MAX_SLICE_LENGTH = 20000;
62constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
63 60
64static s64 idled_cycles; 61static s64 idled_cycles;
65 62
@@ -72,54 +69,6 @@ static EventType* ev_lost = nullptr;
72 69
73static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {} 70static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
74 71
75s64 usToCycles(s64 us) {
76 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
77 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
78 return std::numeric_limits<s64>::max();
79 }
80 if (us > MAX_VALUE_TO_MULTIPLY) {
81 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
82 return BASE_CLOCK_RATE * (us / 1000000);
83 }
84 return (BASE_CLOCK_RATE * us) / 1000000;
85}
86
87s64 usToCycles(u64 us) {
88 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
89 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
90 return std::numeric_limits<s64>::max();
91 }
92 if (us > MAX_VALUE_TO_MULTIPLY) {
93 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
94 return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
95 }
96 return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
97}
98
99s64 nsToCycles(s64 ns) {
100 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
101 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
102 return std::numeric_limits<s64>::max();
103 }
104 if (ns > MAX_VALUE_TO_MULTIPLY) {
105 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
106 return BASE_CLOCK_RATE * (ns / 1000000000);
107 }
108 return (BASE_CLOCK_RATE * ns) / 1000000000;
109}
110
111s64 nsToCycles(u64 ns) {
112 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
113 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
114 return std::numeric_limits<s64>::max();
115 }
116 if (ns > MAX_VALUE_TO_MULTIPLY) {
117 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
118 return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
119 }
120 return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
121}
122
123EventType* RegisterEvent(const std::string& name, TimedCallback callback) { 72EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
124 // check for existing type with same name. 73 // check for existing type with same name.
125 // we want event type names to remain unique so that we can use them for serialization. 74 // we want event type names to remain unique so that we can use them for serialization.