diff options
| author | 2015-01-05 20:17:49 -0500 | |
|---|---|---|
| committer | 2015-01-07 15:08:35 -0500 | |
| commit | 9bf82beb4cbb0b75448a071179c3497187963248 (patch) | |
| tree | c7a99156a6aefb78436c625f1d3170ee4becccd0 /src/core/core_timing.h | |
| parent | Merge pull request #422 from lioncash/bxj (diff) | |
| download | yuzu-9bf82beb4cbb0b75448a071179c3497187963248.tar.gz yuzu-9bf82beb4cbb0b75448a071179c3497187963248.tar.xz yuzu-9bf82beb4cbb0b75448a071179c3497187963248.zip | |
CoreTiming: Ported the CoreTiming namespace from PPSSPP
Implemented the required calls to make it work.
CoreTiming: Added a new logging class Core_Timing.
Diffstat (limited to 'src/core/core_timing.h')
| -rw-r--r-- | src/core/core_timing.h | 77 |
1 files changed, 54 insertions, 23 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 496234538..d62ff3604 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project | 1 | // Copyright (c) 2012- PPSSPP Project / Dolphin Project. |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | |||
| 7 | // This is a system to schedule events into the emulated machine's future. Time is measured | 9 | // This is a system to schedule events into the emulated machine's future. Time is measured |
| 8 | // in main CPU clock cycles. | 10 | // in main CPU clock cycles. |
| 9 | 11 | ||
| @@ -12,14 +14,14 @@ | |||
| 12 | 14 | ||
| 13 | // See HW/SystemTimers.cpp for the main part of Dolphin's usage of this scheduler. | 15 | // See HW/SystemTimers.cpp for the main part of Dolphin's usage of this scheduler. |
| 14 | 16 | ||
| 15 | // The int cyclesLate that the callbacks get is how many cycles late it was. | 17 | // The int cycles_late that the callbacks get is how many cycles late it was. |
| 16 | // So to schedule a new event on a regular basis: | 18 | // So to schedule a new event on a regular basis: |
| 17 | // inside callback: | 19 | // inside callback: |
| 18 | // ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") | 20 | // ScheduleEvent(periodInCycles - cycles_late, callback, "whatever") |
| 19 | 21 | ||
| 20 | #include "common/common.h" | 22 | #include <functional> |
| 21 | 23 | ||
| 22 | class PointerWrap; | 24 | #include "common/common.h" |
| 23 | 25 | ||
| 24 | extern int g_clock_rate_arm11; | 26 | extern int g_clock_rate_arm11; |
| 25 | 27 | ||
| @@ -55,55 +57,84 @@ inline s64 cyclesToUs(s64 cycles) { | |||
| 55 | return cycles / (g_clock_rate_arm11 / 1000000); | 57 | return cycles / (g_clock_rate_arm11 / 1000000); |
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | namespace CoreTiming { | 60 | inline u64 cyclesToMs(s64 cycles) { |
| 61 | return cycles / (g_clock_rate_arm11 / 1000); | ||
| 62 | } | ||
| 59 | 63 | ||
| 64 | namespace CoreTiming | ||
| 65 | { | ||
| 60 | void Init(); | 66 | void Init(); |
| 61 | void Shutdown(); | 67 | void Shutdown(); |
| 62 | 68 | ||
| 63 | typedef void(*TimedCallback)(u64 userdata, int cyclesLate); | 69 | typedef void(*MHzChangeCallback)(); |
| 70 | typedef std::function<void(u64 userdata, int cycles_late)> TimedCallback; | ||
| 64 | 71 | ||
| 65 | u64 GetTicks(); | 72 | u64 GetTicks(); |
| 66 | u64 GetIdleTicks(); | 73 | u64 GetIdleTicks(); |
| 67 | 74 | u64 GetGlobalTimeUs(); | |
| 68 | // Returns the event_type identifier. | 75 | |
| 69 | int RegisterEvent(const char *name, TimedCallback callback); | 76 | /** |
| 70 | // For save states. | 77 | * Registers an event type with the specified name and callback |
| 78 | * @param name Name of the event type | ||
| 79 | * @param callback Function that will execute when this event fires | ||
| 80 | * @returns An identifier for the event type that was registered | ||
| 81 | */ | ||
| 82 | int RegisterEvent(const char* name, TimedCallback callback); | ||
| 83 | /// For save states. | ||
| 71 | void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback); | 84 | void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback); |
| 72 | void UnregisterAllEvents(); | 85 | void UnregisterAllEvents(); |
| 73 | 86 | ||
| 74 | // userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk, | 87 | /// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk, |
| 75 | // when we implement state saves. | 88 | /// when we implement state saves. |
| 76 | void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0); | 89 | /** |
| 77 | void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata = 0); | 90 | * Schedules an event to run after the specified number of cycles, |
| 91 | * with an optional parameter to be passed to the callback handler. | ||
| 92 | * This must be run ONLY from within the cpu thread. | ||
| 93 | * @param cycles_into_future The number of cycles after which this event will be fired | ||
| 94 | * @param event_type The event type to fire, as returned from RegisterEvent | ||
| 95 | * @param userdata Optional parameter to pass to the callback when fired | ||
| 96 | */ | ||
| 97 | void ScheduleEvent(s64 cycles_into_future, int event_type, u64 userdata = 0); | ||
| 98 | |||
| 99 | void ScheduleEvent_Threadsafe(s64 cycles_into_future, int event_type, u64 userdata = 0); | ||
| 78 | void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0); | 100 | void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0); |
| 101 | |||
| 102 | /** | ||
| 103 | * Unschedules an event with the specified type and userdata | ||
| 104 | * @param event_type The type of event to unschedule, as returned from RegisterEvent | ||
| 105 | * @param userdata The userdata that identifies this event, as passed to ScheduleEvent | ||
| 106 | * @returns The remaining ticks until the next invocation of the event callback | ||
| 107 | */ | ||
| 79 | s64 UnscheduleEvent(int event_type, u64 userdata); | 108 | s64 UnscheduleEvent(int event_type, u64 userdata); |
| 109 | |||
| 80 | s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata); | 110 | s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata); |
| 81 | 111 | ||
| 82 | void RemoveEvent(int event_type); | 112 | void RemoveEvent(int event_type); |
| 83 | void RemoveThreadsafeEvent(int event_type); | 113 | void RemoveThreadsafeEvent(int event_type); |
| 84 | void RemoveAllEvents(int event_type); | 114 | void RemoveAllEvents(int event_type); |
| 85 | bool IsScheduled(int event_type); | 115 | bool IsScheduled(int event_type); |
| 116 | /// Runs any pending events and updates downcount for the next slice of cycles | ||
| 86 | void Advance(); | 117 | void Advance(); |
| 87 | void MoveEvents(); | 118 | void MoveEvents(); |
| 88 | void ProcessFifoWaitEvents(); | 119 | void ProcessFifoWaitEvents(); |
| 120 | void ForceCheck(); | ||
| 89 | 121 | ||
| 90 | // Pretend that the main CPU has executed enough cycles to reach the next event. | 122 | /// Pretend that the main CPU has executed enough cycles to reach the next event. |
| 91 | void Idle(int maxIdle = 0); | 123 | void Idle(int maxIdle = 0); |
| 92 | 124 | ||
| 93 | // Clear all pending events. This should ONLY be done on exit or state load. | 125 | /// Clear all pending events. This should ONLY be done on exit or state load. |
| 94 | void ClearPendingEvents(); | 126 | void ClearPendingEvents(); |
| 95 | 127 | ||
| 96 | void LogPendingEvents(); | 128 | void LogPendingEvents(); |
| 97 | 129 | ||
| 98 | // Warning: not included in save states. | 130 | /// Warning: not included in save states. |
| 99 | void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted)); | 131 | void RegisterAdvanceCallback(void(*callback)(int cycles_executed)); |
| 132 | void RegisterMHzChangeCallback(MHzChangeCallback callback); | ||
| 100 | 133 | ||
| 101 | std::string GetScheduledEventsSummary(); | 134 | std::string GetScheduledEventsSummary(); |
| 102 | 135 | ||
| 103 | void DoState(PointerWrap &p); | 136 | void SetClockFrequencyMHz(int cpu_mhz); |
| 104 | |||
| 105 | void SetClockFrequencyMHz(int cpuMhz); | ||
| 106 | int GetClockFrequencyMHz(); | 137 | int GetClockFrequencyMHz(); |
| 107 | extern int slicelength; | 138 | extern int g_slice_length; |
| 108 | 139 | ||
| 109 | } // namespace | 140 | } // namespace |