diff options
| author | 2018-05-03 15:08:43 -0400 | |
|---|---|---|
| committer | 2018-05-03 15:08:43 -0400 | |
| commit | 8c665d6752e8b8726e8e78560bb1ed6dc4253305 (patch) | |
| tree | 04d1f976cecc96768215422e285c9069cc263302 /src/core/core_timing.cpp | |
| parent | Merge pull request #431 from lioncash/fmt (diff) | |
| parent | core_timing: Don't include the log header in core timing's header (diff) | |
| download | yuzu-8c665d6752e8b8726e8e78560bb1ed6dc4253305.tar.gz yuzu-8c665d6752e8b8726e8e78560bb1ed6dc4253305.tar.xz yuzu-8c665d6752e8b8726e8e78560bb1ed6dc4253305.zip | |
Merge pull request #433 from lioncash/logging
core_timing: Don't include the log header in core timing's header
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 91c93e01f..dc1d8668f 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <algorithm> | 7 | #include <algorithm> |
| 8 | #include <cinttypes> | 8 | #include <cinttypes> |
| 9 | #include <limits> | ||
| 9 | #include <mutex> | 10 | #include <mutex> |
| 10 | #include <string> | 11 | #include <string> |
| 11 | #include <tuple> | 12 | #include <tuple> |
| @@ -57,7 +58,8 @@ static u64 event_fifo_id; | |||
| 57 | // to the event_queue by the emu thread | 58 | // to the event_queue by the emu thread |
| 58 | static Common::MPSCQueue<Event, false> ts_queue; | 59 | static Common::MPSCQueue<Event, false> ts_queue; |
| 59 | 60 | ||
| 60 | static constexpr int MAX_SLICE_LENGTH = 20000; | 61 | constexpr int MAX_SLICE_LENGTH = 20000; |
| 62 | constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE; | ||
| 61 | 63 | ||
| 62 | static s64 idled_cycles; | 64 | static s64 idled_cycles; |
| 63 | 65 | ||
| @@ -70,6 +72,54 @@ static EventType* ev_lost = nullptr; | |||
| 70 | 72 | ||
| 71 | static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {} | 73 | static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {} |
| 72 | 74 | ||
| 75 | s64 usToCycles(s64 us) { | ||
| 76 | if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) { | ||
| 77 | NGLOG_ERROR(Core_Timing, "Integer overflow, use max value"); | ||
| 78 | return std::numeric_limits<s64>::max(); | ||
| 79 | } | ||
| 80 | if (us > MAX_VALUE_TO_MULTIPLY) { | ||
| 81 | NGLOG_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 | |||
| 87 | s64 usToCycles(u64 us) { | ||
| 88 | if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) { | ||
| 89 | NGLOG_ERROR(Core_Timing, "Integer overflow, use max value"); | ||
| 90 | return std::numeric_limits<s64>::max(); | ||
| 91 | } | ||
| 92 | if (us > MAX_VALUE_TO_MULTIPLY) { | ||
| 93 | NGLOG_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 | |||
| 99 | s64 nsToCycles(s64 ns) { | ||
| 100 | if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) { | ||
| 101 | NGLOG_ERROR(Core_Timing, "Integer overflow, use max value"); | ||
| 102 | return std::numeric_limits<s64>::max(); | ||
| 103 | } | ||
| 104 | if (ns > MAX_VALUE_TO_MULTIPLY) { | ||
| 105 | NGLOG_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 | |||
| 111 | s64 nsToCycles(u64 ns) { | ||
| 112 | if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) { | ||
| 113 | NGLOG_ERROR(Core_Timing, "Integer overflow, use max value"); | ||
| 114 | return std::numeric_limits<s64>::max(); | ||
| 115 | } | ||
| 116 | if (ns > MAX_VALUE_TO_MULTIPLY) { | ||
| 117 | NGLOG_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 | |||
| 73 | EventType* RegisterEvent(const std::string& name, TimedCallback callback) { | 123 | EventType* RegisterEvent(const std::string& name, TimedCallback callback) { |
| 74 | // check for existing type with same name. | 124 | // check for existing type with same name. |
| 75 | // we want event type names to remain unique so that we can use them for serialization. | 125 | // we want event type names to remain unique so that we can use them for serialization. |