2014-04-09 04:41:21 +05:30
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2013-10-02 04:40:47 +05:30
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
2014-09-03 11:10:02 +05:30
|
|
|
#include <atomic>
|
2014-09-03 10:35:45 +05:30
|
|
|
#include <mutex>
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 05:45:08 +05:30
|
|
|
#include "common/chunk_file.h"
|
2014-09-13 06:48:46 +05:30
|
|
|
#include "common/msg_handler.h"
|
|
|
|
#include "common/string_util.h"
|
2014-04-09 05:45:08 +05:30
|
|
|
|
|
|
|
#include "core/core.h"
|
2014-09-13 06:48:46 +05:30
|
|
|
#include "core/core_timing.h"
|
2013-10-02 04:40:47 +05:30
|
|
|
|
|
|
|
int g_clock_rate_arm11 = 268123480;
|
|
|
|
|
|
|
|
// is this really necessary?
|
|
|
|
#define INITIAL_SLICE_LENGTH 20000
|
|
|
|
#define MAX_SLICE_LENGTH 100000000
|
|
|
|
|
|
|
|
namespace CoreTiming
|
|
|
|
{
|
|
|
|
|
|
|
|
struct EventType
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
EventType() {}
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
EventType(TimedCallback cb, const char *n)
|
|
|
|
: callback(cb), name(n) {}
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
TimedCallback callback;
|
|
|
|
const char *name;
|
2013-10-02 04:40:47 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<EventType> event_types;
|
|
|
|
|
|
|
|
struct BaseEvent
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
s64 time;
|
|
|
|
u64 userdata;
|
|
|
|
int type;
|
|
|
|
// Event *next;
|
2013-10-02 04:40:47 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
typedef LinkedListItem<BaseEvent> Event;
|
|
|
|
|
|
|
|
Event *first;
|
|
|
|
Event *tsFirst;
|
|
|
|
Event *tsLast;
|
|
|
|
|
|
|
|
// event pools
|
|
|
|
Event *eventPool = 0;
|
|
|
|
Event *eventTsPool = 0;
|
|
|
|
int allocatedTsEvents = 0;
|
|
|
|
// Optimization to skip MoveEvents when possible.
|
2014-09-03 11:10:02 +05:30
|
|
|
std::atomic<u32> hasTsEvents;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
|
|
|
// Downcount has been moved to currentMIPS, to save a couple of clocks in every ARM JIT block
|
|
|
|
// as we can already reach that structure through a register.
|
|
|
|
int slicelength;
|
|
|
|
|
|
|
|
MEMORY_ALIGNED16(s64) globalTimer;
|
|
|
|
s64 idledCycles;
|
|
|
|
|
|
|
|
static std::recursive_mutex externalEventSection;
|
|
|
|
|
|
|
|
// Warning: not included in save state.
|
2014-04-09 04:41:21 +05:30
|
|
|
void(*advanceCallback)(int cyclesExecuted) = NULL;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
|
|
|
void SetClockFrequencyMHz(int cpuMhz)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
g_clock_rate_arm11 = cpuMhz * 1000000;
|
|
|
|
// TODO: Rescale times of scheduled events?
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int GetClockFrequencyMHz()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
return g_clock_rate_arm11 / 1000000;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Event* GetNewEvent()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (!eventPool)
|
|
|
|
return new Event;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
Event* ev = eventPool;
|
|
|
|
eventPool = ev->next;
|
|
|
|
return ev;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Event* GetNewTsEvent()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
allocatedTsEvents++;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
if (!eventTsPool)
|
|
|
|
return new Event;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
Event* ev = eventTsPool;
|
|
|
|
eventTsPool = ev->next;
|
|
|
|
return ev;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FreeEvent(Event* ev)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ev->next = eventPool;
|
|
|
|
eventPool = ev;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FreeTsEvent(Event* ev)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ev->next = eventTsPool;
|
|
|
|
eventTsPool = ev;
|
|
|
|
allocatedTsEvents--;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int RegisterEvent(const char *name, TimedCallback callback)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
event_types.push_back(EventType(callback, name));
|
|
|
|
return (int)event_types.size() - 1;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void AntiCrashCallback(u64 userdata, int cyclesLate)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ERROR_LOG(TIME, "Savestate broken: an unregistered event was called.");
|
|
|
|
Core::Halt("invalid timing events");
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (event_type >= (int)event_types.size())
|
|
|
|
event_types.resize(event_type + 1, EventType(AntiCrashCallback, "INVALID EVENT"));
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
event_types[event_type] = EventType(callback, name);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterAllEvents()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (first)
|
|
|
|
PanicAlert("Cannot unregister events with events pending");
|
|
|
|
event_types.clear();
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
//currentMIPS->downcount = INITIAL_SLICE_LENGTH;
|
|
|
|
//slicelength = INITIAL_SLICE_LENGTH;
|
|
|
|
globalTimer = 0;
|
|
|
|
idledCycles = 0;
|
|
|
|
hasTsEvents = 0;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
MoveEvents();
|
|
|
|
ClearPendingEvents();
|
|
|
|
UnregisterAllEvents();
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
while (eventPool)
|
|
|
|
{
|
|
|
|
Event *ev = eventPool;
|
|
|
|
eventPool = ev->next;
|
|
|
|
delete ev;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
while (eventTsPool)
|
|
|
|
{
|
|
|
|
Event *ev = eventTsPool;
|
|
|
|
eventTsPool = ev->next;
|
|
|
|
delete ev;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetTicks()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ERROR_LOG(TIME, "Unimplemented function!");
|
|
|
|
return 0;
|
|
|
|
//return (u64)globalTimer + slicelength - currentMIPS->downcount;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetIdleTicks()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
return (u64)idledCycles;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is to be called when outside threads, such as the graphics thread, wants to
|
|
|
|
// schedule things to be executed on the main thread.
|
|
|
|
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
Event *ne = GetNewTsEvent();
|
|
|
|
ne->time = GetTicks() + cyclesIntoFuture;
|
|
|
|
ne->type = event_type;
|
|
|
|
ne->next = 0;
|
|
|
|
ne->userdata = userdata;
|
|
|
|
if (!tsFirst)
|
|
|
|
tsFirst = ne;
|
|
|
|
if (tsLast)
|
|
|
|
tsLast->next = ne;
|
|
|
|
tsLast = ne;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-09-03 11:10:02 +05:30
|
|
|
hasTsEvents.store(1, std::memory_order_release);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Same as ScheduleEvent_Threadsafe(0, ...) EXCEPT if we are already on the CPU thread
|
|
|
|
// in which case the event will get handled immediately, before returning.
|
|
|
|
void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (false) //Core::IsCPUThread())
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
event_types[event_type].callback(userdata, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ScheduleEvent_Threadsafe(0, event_type, userdata);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPendingEvents()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
Event *e = first->next;
|
|
|
|
FreeEvent(first);
|
|
|
|
first = e;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void AddEventToQueue(Event* ne)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
Event* prev = NULL;
|
|
|
|
Event** pNext = &first;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
Event*& next = *pNext;
|
|
|
|
if (!next || ne->time < next->time)
|
|
|
|
{
|
|
|
|
ne->next = next;
|
|
|
|
next = ne;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = next;
|
|
|
|
pNext = &prev->next;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// This must be run ONLY from within the cpu thread
|
|
|
|
// cyclesIntoFuture may be VERY inaccurate if called from anything else
|
|
|
|
// than Advance
|
|
|
|
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
Event *ne = GetNewEvent();
|
|
|
|
ne->userdata = userdata;
|
|
|
|
ne->type = event_type;
|
|
|
|
ne->time = GetTicks() + cyclesIntoFuture;
|
|
|
|
AddEventToQueue(ne);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Returns cycles left in timer.
|
|
|
|
s64 UnscheduleEvent(int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
s64 result = 0;
|
|
|
|
if (!first)
|
|
|
|
return result;
|
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
if (first->type == event_type && first->userdata == userdata)
|
|
|
|
{
|
|
|
|
result = first->time - globalTimer;
|
|
|
|
|
|
|
|
Event *next = first->next;
|
|
|
|
FreeEvent(first);
|
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!first)
|
|
|
|
return result;
|
|
|
|
Event *prev = first;
|
|
|
|
Event *ptr = prev->next;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (ptr->type == event_type && ptr->userdata == userdata)
|
|
|
|
{
|
|
|
|
result = ptr->time - globalTimer;
|
|
|
|
|
|
|
|
prev->next = ptr->next;
|
|
|
|
FreeEvent(ptr);
|
|
|
|
ptr = prev->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = ptr;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
s64 result = 0;
|
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
if (!tsFirst)
|
|
|
|
return result;
|
|
|
|
while (tsFirst)
|
|
|
|
{
|
|
|
|
if (tsFirst->type == event_type && tsFirst->userdata == userdata)
|
|
|
|
{
|
|
|
|
result = tsFirst->time - globalTimer;
|
|
|
|
|
|
|
|
Event *next = tsFirst->next;
|
|
|
|
FreeTsEvent(tsFirst);
|
|
|
|
tsFirst = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tsFirst)
|
|
|
|
{
|
|
|
|
tsLast = NULL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Event *prev = tsFirst;
|
|
|
|
Event *ptr = prev->next;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (ptr->type == event_type && ptr->userdata == userdata)
|
|
|
|
{
|
|
|
|
result = ptr->time - globalTimer;
|
|
|
|
|
|
|
|
prev->next = ptr->next;
|
|
|
|
if (ptr == tsLast)
|
|
|
|
tsLast = prev;
|
|
|
|
FreeTsEvent(ptr);
|
|
|
|
ptr = prev->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = ptr;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Warning: not included in save state.
|
2014-04-09 04:41:21 +05:30
|
|
|
void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted))
|
2013-10-02 04:40:47 +05:30
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
advanceCallback = callback;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
bool IsScheduled(int event_type)
|
2013-10-02 04:40:47 +05:30
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (!first)
|
|
|
|
return false;
|
|
|
|
Event *e = first;
|
|
|
|
while (e) {
|
|
|
|
if (e->type == event_type)
|
|
|
|
return true;
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
return false;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveEvent(int event_type)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
if (!first)
|
|
|
|
return;
|
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
if (first->type == event_type)
|
|
|
|
{
|
|
|
|
Event *next = first->next;
|
|
|
|
FreeEvent(first);
|
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!first)
|
|
|
|
return;
|
|
|
|
Event *prev = first;
|
|
|
|
Event *ptr = prev->next;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (ptr->type == event_type)
|
|
|
|
{
|
|
|
|
prev->next = ptr->next;
|
|
|
|
FreeEvent(ptr);
|
|
|
|
ptr = prev->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = ptr;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveThreadsafeEvent(int event_type)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
if (!tsFirst)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tsFirst)
|
|
|
|
{
|
|
|
|
if (tsFirst->type == event_type)
|
|
|
|
{
|
|
|
|
Event *next = tsFirst->next;
|
|
|
|
FreeTsEvent(tsFirst);
|
|
|
|
tsFirst = next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tsFirst)
|
|
|
|
{
|
|
|
|
tsLast = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Event *prev = tsFirst;
|
|
|
|
Event *ptr = prev->next;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (ptr->type == event_type)
|
|
|
|
{
|
|
|
|
prev->next = ptr->next;
|
|
|
|
if (ptr == tsLast)
|
|
|
|
tsLast = prev;
|
|
|
|
FreeTsEvent(ptr);
|
|
|
|
ptr = prev->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = ptr;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAllEvents(int event_type)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
RemoveThreadsafeEvent(event_type);
|
|
|
|
RemoveEvent(event_type);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//This raise only the events required while the fifo is processing data
|
|
|
|
void ProcessFifoWaitEvents()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
if (first->time <= globalTimer)
|
|
|
|
{
|
|
|
|
// LOG(TIMER, "[Scheduler] %s (%lld, %lld) ",
|
|
|
|
// first->name ? first->name : "?", (u64)globalTimer, (u64)first->time);
|
|
|
|
Event* evt = first;
|
|
|
|
first = first->next;
|
|
|
|
event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
|
|
|
|
FreeEvent(evt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void MoveEvents()
|
|
|
|
{
|
2014-09-03 11:10:02 +05:30
|
|
|
hasTsEvents.store(0, std::memory_order_release);
|
2014-04-09 04:41:21 +05:30
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
// Move events from async queue into main queue
|
|
|
|
while (tsFirst)
|
|
|
|
{
|
|
|
|
Event *next = tsFirst->next;
|
|
|
|
AddEventToQueue(tsFirst);
|
|
|
|
tsFirst = next;
|
|
|
|
}
|
|
|
|
tsLast = NULL;
|
|
|
|
|
|
|
|
// Move free events to threadsafe pool
|
|
|
|
while (allocatedTsEvents > 0 && eventPool)
|
|
|
|
{
|
|
|
|
Event *ev = eventPool;
|
|
|
|
eventPool = ev->next;
|
|
|
|
ev->next = eventTsPool;
|
|
|
|
eventTsPool = ev;
|
|
|
|
allocatedTsEvents--;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Advance()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ERROR_LOG(TIME, "Unimplemented function!");
|
|
|
|
//int cyclesExecuted = slicelength - currentMIPS->downcount;
|
|
|
|
//globalTimer += cyclesExecuted;
|
|
|
|
//currentMIPS->downcount = slicelength;
|
|
|
|
|
|
|
|
//if (Common::AtomicLoadAcquire(hasTsEvents))
|
|
|
|
// MoveEvents();
|
|
|
|
//ProcessFifoWaitEvents();
|
|
|
|
|
|
|
|
//if (!first)
|
|
|
|
//{
|
|
|
|
// // WARN_LOG(TIMER, "WARNING - no events in queue. Setting currentMIPS->downcount to 10000");
|
|
|
|
// currentMIPS->downcount += 10000;
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// slicelength = (int)(first->time - globalTimer);
|
|
|
|
// if (slicelength > MAX_SLICE_LENGTH)
|
|
|
|
// slicelength = MAX_SLICE_LENGTH;
|
|
|
|
// currentMIPS->downcount = slicelength;
|
|
|
|
//}
|
|
|
|
//if (advanceCallback)
|
|
|
|
// advanceCallback(cyclesExecuted);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogPendingEvents()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
Event *ptr = first;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
//INFO_LOG(TIMER, "PENDING: Now: %lld Pending: %lld Type: %d", globalTimer, ptr->time, ptr->type);
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Idle(int maxIdle)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
ERROR_LOG(TIME, "Unimplemented function!");
|
|
|
|
//int cyclesDown = currentMIPS->downcount;
|
|
|
|
//if (maxIdle != 0 && cyclesDown > maxIdle)
|
|
|
|
// cyclesDown = maxIdle;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
//if (first && cyclesDown > 0)
|
|
|
|
//{
|
|
|
|
// int cyclesExecuted = slicelength - currentMIPS->downcount;
|
|
|
|
// int cyclesNextEvent = (int) (first->time - globalTimer);
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
// if (cyclesNextEvent < cyclesExecuted + cyclesDown)
|
|
|
|
// {
|
|
|
|
// cyclesDown = cyclesNextEvent - cyclesExecuted;
|
|
|
|
// // Now, now... no time machines, please.
|
|
|
|
// if (cyclesDown < 0)
|
|
|
|
// cyclesDown = 0;
|
|
|
|
// }
|
|
|
|
//}
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
//INFO_LOG(TIME, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(g_clock_rate_arm11 * 0.001f));
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
//idledCycles += cyclesDown;
|
|
|
|
//currentMIPS->downcount -= cyclesDown;
|
|
|
|
//if (currentMIPS->downcount == 0)
|
|
|
|
// currentMIPS->downcount = -1;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetScheduledEventsSummary()
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
Event *ptr = first;
|
|
|
|
std::string text = "Scheduled events\n";
|
|
|
|
text.reserve(1000);
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
unsigned int t = ptr->type;
|
|
|
|
if (t >= event_types.size())
|
|
|
|
PanicAlert("Invalid event type"); // %i", t);
|
|
|
|
const char *name = event_types[ptr->type].name;
|
|
|
|
if (!name)
|
|
|
|
name = "[unknown]";
|
2014-09-13 06:48:46 +05:30
|
|
|
|
|
|
|
text += Common::StringFromFormat("%s : %i %08x%08x\n", name, (int)ptr->time,
|
|
|
|
(u32)(ptr->userdata >> 32), (u32)(ptr->userdata));
|
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
return text;
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Event_DoState(PointerWrap &p, BaseEvent *ev)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
p.Do(*ev);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
2014-04-09 04:41:21 +05:30
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
auto s = p.Section("CoreTiming", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
int n = (int)event_types.size();
|
|
|
|
p.Do(n);
|
|
|
|
// These (should) be filled in later by the modules.
|
|
|
|
event_types.resize(n, EventType(AntiCrashCallback, "INVALID EVENT"));
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
p.DoLinkedList<BaseEvent, GetNewEvent, FreeEvent, Event_DoState>(first, (Event **)NULL);
|
|
|
|
p.DoLinkedList<BaseEvent, GetNewTsEvent, FreeTsEvent, Event_DoState>(tsFirst, &tsLast);
|
2013-10-02 04:40:47 +05:30
|
|
|
|
2014-04-09 04:41:21 +05:30
|
|
|
p.Do(g_clock_rate_arm11);
|
|
|
|
p.Do(slicelength);
|
|
|
|
p.Do(globalTimer);
|
|
|
|
p.Do(idledCycles);
|
2013-10-02 04:40:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|