summaryrefslogtreecommitdiff
path: root/src/core/core_timing.h
diff options
context:
space:
mode:
authorGravatar Subv2015-01-05 20:17:49 -0500
committerGravatar Subv2015-01-07 15:08:35 -0500
commit9bf82beb4cbb0b75448a071179c3497187963248 (patch)
treec7a99156a6aefb78436c625f1d3170ee4becccd0 /src/core/core_timing.h
parentMerge pull request #422 from lioncash/bxj (diff)
downloadyuzu-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.h77
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
22class PointerWrap; 24#include "common/common.h"
23 25
24extern int g_clock_rate_arm11; 26extern 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
58namespace CoreTiming { 60inline u64 cyclesToMs(s64 cycles) {
61 return cycles / (g_clock_rate_arm11 / 1000);
62}
59 63
64namespace CoreTiming
65{
60void Init(); 66void Init();
61void Shutdown(); 67void Shutdown();
62 68
63typedef void(*TimedCallback)(u64 userdata, int cyclesLate); 69typedef void(*MHzChangeCallback)();
70typedef std::function<void(u64 userdata, int cycles_late)> TimedCallback;
64 71
65u64 GetTicks(); 72u64 GetTicks();
66u64 GetIdleTicks(); 73u64 GetIdleTicks();
67 74u64 GetGlobalTimeUs();
68// Returns the event_type identifier. 75
69int 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 */
82int RegisterEvent(const char* name, TimedCallback callback);
83/// For save states.
71void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback); 84void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback);
72void UnregisterAllEvents(); 85void 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.
76void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0); 89/**
77void 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 */
97void ScheduleEvent(s64 cycles_into_future, int event_type, u64 userdata = 0);
98
99void ScheduleEvent_Threadsafe(s64 cycles_into_future, int event_type, u64 userdata = 0);
78void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0); 100void 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 */
79s64 UnscheduleEvent(int event_type, u64 userdata); 108s64 UnscheduleEvent(int event_type, u64 userdata);
109
80s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata); 110s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata);
81 111
82void RemoveEvent(int event_type); 112void RemoveEvent(int event_type);
83void RemoveThreadsafeEvent(int event_type); 113void RemoveThreadsafeEvent(int event_type);
84void RemoveAllEvents(int event_type); 114void RemoveAllEvents(int event_type);
85bool IsScheduled(int event_type); 115bool IsScheduled(int event_type);
116/// Runs any pending events and updates downcount for the next slice of cycles
86void Advance(); 117void Advance();
87void MoveEvents(); 118void MoveEvents();
88void ProcessFifoWaitEvents(); 119void ProcessFifoWaitEvents();
120void 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.
91void Idle(int maxIdle = 0); 123void 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.
94void ClearPendingEvents(); 126void ClearPendingEvents();
95 127
96void LogPendingEvents(); 128void LogPendingEvents();
97 129
98// Warning: not included in save states. 130/// Warning: not included in save states.
99void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted)); 131void RegisterAdvanceCallback(void(*callback)(int cycles_executed));
132void RegisterMHzChangeCallback(MHzChangeCallback callback);
100 133
101std::string GetScheduledEventsSummary(); 134std::string GetScheduledEventsSummary();
102 135
103void DoState(PointerWrap &p); 136void SetClockFrequencyMHz(int cpu_mhz);
104
105void SetClockFrequencyMHz(int cpuMhz);
106int GetClockFrequencyMHz(); 137int GetClockFrequencyMHz();
107extern int slicelength; 138extern int g_slice_length;
108 139
109} // namespace 140} // namespace