2014-12-17 08:38:14 +03:00
|
|
|
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-09 03:11:21 +04:00
|
|
|
// Refer to the license.txt file included.
|
2013-10-02 03:10:47 +04:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
2014-09-03 09:40:02 +04:00
|
|
|
#include <atomic>
|
2014-09-03 09:05:45 +04:00
|
|
|
#include <mutex>
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 04:15:08 +04:00
|
|
|
#include "common/chunk_file.h"
|
2014-09-13 05:18:46 +04:00
|
|
|
#include "common/msg_handler.h"
|
|
|
|
#include "common/string_util.h"
|
2014-04-09 04:15:08 +04:00
|
|
|
|
|
|
|
#include "core/core.h"
|
2014-09-13 05:18:46 +04:00
|
|
|
#include "core/core_timing.h"
|
2013-10-02 03:10:47 +04:00
|
|
|
|
|
|
|
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 03:11:21 +04:00
|
|
|
EventType() {}
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
EventType(TimedCallback cb, const char *n)
|
|
|
|
: callback(cb), name(n) {}
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
TimedCallback callback;
|
|
|
|
const char *name;
|
2013-10-02 03:10:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<EventType> event_types;
|
|
|
|
|
|
|
|
struct BaseEvent
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
s64 time;
|
|
|
|
u64 userdata;
|
|
|
|
int type;
|
2014-11-19 12:02:05 +03:00
|
|
|
// Event *next;
|
2013-10-02 03:10:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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 09:40:02 +04:00
|
|
|
std::atomic<u32> hasTsEvents;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
|
|
|
// 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-12-03 21:57:57 +03:00
|
|
|
void(*advanceCallback)(int cyclesExecuted) = nullptr;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
|
|
|
void SetClockFrequencyMHz(int cpuMhz)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
g_clock_rate_arm11 = cpuMhz * 1000000;
|
|
|
|
// TODO: Rescale times of scheduled events?
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int GetClockFrequencyMHz()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
return g_clock_rate_arm11 / 1000000;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Event* GetNewEvent()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
if (!eventPool)
|
|
|
|
return new Event;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
Event* ev = eventPool;
|
|
|
|
eventPool = ev->next;
|
|
|
|
return ev;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Event* GetNewTsEvent()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
allocatedTsEvents++;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
if (!eventTsPool)
|
|
|
|
return new Event;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
Event* ev = eventTsPool;
|
|
|
|
eventTsPool = ev->next;
|
|
|
|
return ev;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FreeEvent(Event* ev)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
ev->next = eventPool;
|
|
|
|
eventPool = ev;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FreeTsEvent(Event* ev)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
ev->next = eventTsPool;
|
|
|
|
eventTsPool = ev;
|
|
|
|
allocatedTsEvents--;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int RegisterEvent(const char *name, TimedCallback callback)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
event_types.push_back(EventType(callback, name));
|
|
|
|
return (int)event_types.size() - 1;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AntiCrashCallback(u64 userdata, int cyclesLate)
|
|
|
|
{
|
2014-12-06 04:53:49 +03:00
|
|
|
LOG_CRITICAL(Core, "Savestate broken: an unregistered event was called.");
|
2014-04-09 03:11:21 +04:00
|
|
|
Core::Halt("invalid timing events");
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
if (event_type >= (int)event_types.size())
|
|
|
|
event_types.resize(event_type + 1, EventType(AntiCrashCallback, "INVALID EVENT"));
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
event_types[event_type] = EventType(callback, name);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterAllEvents()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
if (first)
|
|
|
|
PanicAlert("Cannot unregister events with events pending");
|
|
|
|
event_types.clear();
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
//currentMIPS->downcount = INITIAL_SLICE_LENGTH;
|
|
|
|
//slicelength = INITIAL_SLICE_LENGTH;
|
|
|
|
globalTimer = 0;
|
|
|
|
idledCycles = 0;
|
|
|
|
hasTsEvents = 0;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
MoveEvents();
|
|
|
|
ClearPendingEvents();
|
|
|
|
UnregisterAllEvents();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
while (eventPool)
|
|
|
|
{
|
|
|
|
Event *ev = eventPool;
|
|
|
|
eventPool = ev->next;
|
|
|
|
delete ev;
|
|
|
|
}
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
|
|
|
while (eventTsPool)
|
|
|
|
{
|
|
|
|
Event *ev = eventTsPool;
|
|
|
|
eventTsPool = ev->next;
|
|
|
|
delete ev;
|
|
|
|
}
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetTicks()
|
|
|
|
{
|
2014-12-06 04:53:49 +03:00
|
|
|
LOG_ERROR(Core, "Unimplemented function!");
|
2014-04-09 03:11:21 +04:00
|
|
|
return 0;
|
|
|
|
//return (u64)globalTimer + slicelength - currentMIPS->downcount;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetIdleTicks()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
return (u64)idledCycles;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
|
2014-09-03 09:40:02 +04:00
|
|
|
hasTsEvents.store(1, std::memory_order_release);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearPendingEvents()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
Event *e = first->next;
|
|
|
|
FreeEvent(first);
|
|
|
|
first = e;
|
|
|
|
}
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddEventToQueue(Event* ne)
|
|
|
|
{
|
2014-12-03 21:57:57 +03:00
|
|
|
Event* prev = nullptr;
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This must be run ONLY from within the cpu thread
|
|
|
|
// cyclesIntoFuture may be VERY inaccurate if called from anything else
|
2014-11-19 11:49:13 +03:00
|
|
|
// than Advance
|
2013-10-02 03:10:47 +04:00
|
|
|
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
Event *ne = GetNewEvent();
|
|
|
|
ne->userdata = userdata;
|
|
|
|
ne->type = event_type;
|
|
|
|
ne->time = GetTicks() + cyclesIntoFuture;
|
|
|
|
AddEventToQueue(ne);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns cycles left in timer.
|
|
|
|
s64 UnscheduleEvent(int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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)
|
|
|
|
{
|
2014-12-03 21:57:57 +03:00
|
|
|
tsLast = nullptr;
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warning: not included in save state.
|
2014-04-09 03:11:21 +04:00
|
|
|
void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted))
|
2013-10-02 03:10:47 +04:00
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
advanceCallback = callback;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
bool IsScheduled(int event_type)
|
2013-10-02 03:10:47 +04:00
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
if (!first)
|
|
|
|
return false;
|
|
|
|
Event *e = first;
|
|
|
|
while (e) {
|
|
|
|
if (e->type == event_type)
|
|
|
|
return true;
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
return false;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveEvent(int event_type)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveThreadsafeEvent(int event_type)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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)
|
|
|
|
{
|
2014-12-03 21:57:57 +03:00
|
|
|
tsLast = nullptr;
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAllEvents(int event_type)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
RemoveThreadsafeEvent(event_type);
|
|
|
|
RemoveEvent(event_type);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//This raise only the events required while the fifo is processing data
|
|
|
|
void ProcessFifoWaitEvents()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
while (first)
|
|
|
|
{
|
|
|
|
if (first->time <= globalTimer)
|
|
|
|
{
|
2014-11-19 12:02:05 +03:00
|
|
|
//LOG(TIMER, "[Scheduler] %s (%lld, %lld) ",
|
|
|
|
// first->name ? first->name : "?", (u64)globalTimer, (u64)first->time);
|
2014-04-09 03:11:21 +04:00
|
|
|
Event* evt = first;
|
|
|
|
first = first->next;
|
|
|
|
event_types[evt->type].callback(evt->userdata, (int)(globalTimer - evt->time));
|
|
|
|
FreeEvent(evt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveEvents()
|
|
|
|
{
|
2014-09-03 09:40:02 +04:00
|
|
|
hasTsEvents.store(0, std::memory_order_release);
|
2014-04-09 03:11:21 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2014-12-03 21:57:57 +03:00
|
|
|
tsLast = nullptr;
|
2014-04-09 03:11:21 +04:00
|
|
|
|
|
|
|
// 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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Advance()
|
|
|
|
{
|
2014-12-06 04:53:49 +03:00
|
|
|
LOG_ERROR(Core, "Unimplemented function!");
|
2014-04-09 03:11:21 +04:00
|
|
|
//int cyclesExecuted = slicelength - currentMIPS->downcount;
|
|
|
|
//globalTimer += cyclesExecuted;
|
|
|
|
//currentMIPS->downcount = slicelength;
|
|
|
|
|
|
|
|
//if (Common::AtomicLoadAcquire(hasTsEvents))
|
2014-11-19 12:02:05 +03:00
|
|
|
// MoveEvents();
|
2014-04-09 03:11:21 +04:00
|
|
|
//ProcessFifoWaitEvents();
|
|
|
|
|
|
|
|
//if (!first)
|
|
|
|
//{
|
2014-11-19 12:02:05 +03:00
|
|
|
// // WARN_LOG(TIMER, "WARNING - no events in queue. Setting currentMIPS->downcount to 10000");
|
|
|
|
// currentMIPS->downcount += 10000;
|
2014-04-09 03:11:21 +04:00
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
2014-11-19 12:02:05 +03:00
|
|
|
// slicelength = (int)(first->time - globalTimer);
|
|
|
|
// if (slicelength > MAX_SLICE_LENGTH)
|
|
|
|
// slicelength = MAX_SLICE_LENGTH;
|
|
|
|
// currentMIPS->downcount = slicelength;
|
2014-04-09 03:11:21 +04:00
|
|
|
//}
|
|
|
|
//if (advanceCallback)
|
2014-11-19 12:02:05 +03:00
|
|
|
// advanceCallback(cyclesExecuted);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogPendingEvents()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Idle(int maxIdle)
|
|
|
|
{
|
2014-12-06 04:53:49 +03:00
|
|
|
LOG_ERROR(Core, "Unimplemented function!");
|
2014-04-09 03:11:21 +04:00
|
|
|
//int cyclesDown = currentMIPS->downcount;
|
|
|
|
//if (maxIdle != 0 && cyclesDown > maxIdle)
|
2014-11-19 12:02:05 +03:00
|
|
|
// cyclesDown = maxIdle;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
//if (first && cyclesDown > 0)
|
|
|
|
//{
|
2014-11-19 12:02:05 +03:00
|
|
|
// int cyclesExecuted = slicelength - currentMIPS->downcount;
|
|
|
|
// int cyclesNextEvent = (int) (first->time - globalTimer);
|
|
|
|
|
|
|
|
// if (cyclesNextEvent < cyclesExecuted + cyclesDown)
|
|
|
|
// {
|
|
|
|
// cyclesDown = cyclesNextEvent - cyclesExecuted;
|
|
|
|
// // Now, now... no time machines, please.
|
|
|
|
// if (cyclesDown < 0)
|
|
|
|
// cyclesDown = 0;
|
|
|
|
// }
|
2014-04-09 03:11:21 +04:00
|
|
|
//}
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
//INFO_LOG(TIME, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(g_clock_rate_arm11 * 0.001f));
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
//idledCycles += cyclesDown;
|
|
|
|
//currentMIPS->downcount -= cyclesDown;
|
|
|
|
//if (currentMIPS->downcount == 0)
|
2014-11-19 12:02:05 +03:00
|
|
|
// currentMIPS->downcount = -1;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetScheduledEventsSummary()
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
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 05:18:46 +04:00
|
|
|
|
|
|
|
text += Common::StringFromFormat("%s : %i %08x%08x\n", name, (int)ptr->time,
|
|
|
|
(u32)(ptr->userdata >> 32), (u32)(ptr->userdata));
|
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
return text;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Event_DoState(PointerWrap &p, BaseEvent *ev)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
p.Do(*ev);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
2014-04-09 03:11:21 +04:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
auto s = p.Section("CoreTiming", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
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 03:10:47 +04:00
|
|
|
|
2014-12-03 21:57:57 +03:00
|
|
|
p.DoLinkedList<BaseEvent, GetNewEvent, FreeEvent, Event_DoState>(first, (Event **)nullptr);
|
2014-04-09 03:11:21 +04:00
|
|
|
p.DoLinkedList<BaseEvent, GetNewTsEvent, FreeTsEvent, Event_DoState>(tsFirst, &tsLast);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
p.Do(g_clock_rate_arm11);
|
|
|
|
p.Do(slicelength);
|
|
|
|
p.Do(globalTimer);
|
|
|
|
p.Do(idledCycles);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
2014-11-19 12:02:05 +03:00
|
|
|
} // namespace
|