Merge pull request #4400 from wwylele/core-timing-global

CoreTiming: wrap into class
This commit is contained in:
Weiyi Wang 2018-11-06 20:04:56 -05:00 committed by GitHub
commit 1444d60109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 413 additions and 413 deletions

View file

@ -4,6 +4,7 @@
#include <chrono>
#include <cstring>
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/service/ptm/ptm.h"
@ -53,9 +54,9 @@ Handler::Handler() {
init_time = GetInitTime();
using namespace std::placeholders;
update_time_event = CoreTiming::RegisterEvent(
update_time_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
"SharedPage::UpdateTimeCallback", std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
CoreTiming::ScheduleEvent(0, update_time_event);
Core::System::GetInstance().CoreTiming().ScheduleEvent(0, update_time_event);
float slidestate =
Settings::values.toggle_3d ? (float_le)Settings::values.factor_3d / 100 : 0.0f;
@ -65,8 +66,8 @@ Handler::Handler() {
/// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond.
u64 Handler::GetSystemTime() const {
std::chrono::milliseconds now =
init_time +
std::chrono::duration_cast<std::chrono::milliseconds>(CoreTiming::GetGlobalTimeUs());
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(
Core::System::GetInstance().CoreTiming().GetGlobalTimeUs());
// 3DS system does't allow user to set a time before Jan 1 2000,
// so we use it as an auxiliary epoch to calculate the console time.
@ -97,14 +98,15 @@ void Handler::UpdateTimeCallback(u64 userdata, int cycles_late) {
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;
date_time.date_time = GetSystemTime();
date_time.update_tick = CoreTiming::GetTicks();
date_time.update_tick = Core::System::GetInstance().CoreTiming().GetTicks();
date_time.tick_to_second_coefficient = BASE_CLOCK_RATE_ARM11;
date_time.tick_offset = 0;
++shared_page.date_time_counter;
// system time is updated hourly
CoreTiming::ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late, update_time_event);
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late,
update_time_event);
}
void Handler::SetMacAddress(const MacAddress& addr) {

View file

@ -21,8 +21,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
}
namespace SharedPage {
@ -96,7 +96,7 @@ public:
private:
u64 GetSystemTime() const;
void UpdateTimeCallback(u64 userdata, int cycles_late);
CoreTiming::EventType* update_time_event;
Core::TimingEventType* update_time_event;
std::chrono::seconds init_time;
SharedPageDef shared_page;

View file

@ -1107,9 +1107,10 @@ static void SleepThread(s64 nanoseconds) {
/// This returns the total CPU ticks elapsed since the CPU was powered-on
static s64 GetSystemTick() {
s64 result = CoreTiming::GetTicks();
s64 result = Core::System::GetInstance().CoreTiming().GetTicks();
// Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end.
CoreTiming::AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
// Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
Core::System::GetInstance().CoreTiming().AddTicks(150);
return result;
}

View file

@ -48,7 +48,8 @@ Thread* ThreadManager::GetCurrentThread() const {
void Thread::Stop() {
// Cancel any outstanding wakeup events for this thread
CoreTiming::UnscheduleEvent(thread_manager.ThreadWakeupEventType, thread_id);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(thread_manager.ThreadWakeupEventType,
thread_id);
thread_manager.wakeup_callback_table.erase(thread_id);
// Clean up thread from ready queue
@ -80,9 +81,11 @@ void Thread::Stop() {
void ThreadManager::SwitchContext(Thread* new_thread) {
Thread* previous_thread = GetCurrentThread();
Core::Timing& timing = Core::System::GetInstance().CoreTiming();
// Save context for previous thread
if (previous_thread) {
previous_thread->last_running_ticks = CoreTiming::GetTicks();
previous_thread->last_running_ticks = timing.GetTicks();
Core::CPU().SaveContext(previous_thread->context);
if (previous_thread->status == ThreadStatus::Running) {
@ -99,7 +102,7 @@ void ThreadManager::SwitchContext(Thread* new_thread) {
"Thread must be ready to become running.");
// Cancel any outstanding wakeup events for this thread
CoreTiming::UnscheduleEvent(ThreadWakeupEventType, new_thread->thread_id);
timing.UnscheduleEvent(ThreadWakeupEventType, new_thread->thread_id);
auto previous_process = Core::System::GetInstance().Kernel().GetCurrentProcess();
@ -182,8 +185,8 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
if (nanoseconds == -1)
return;
CoreTiming::ScheduleEvent(nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType,
thread_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType, thread_id);
}
void Thread::ResumeFromWait() {
@ -316,7 +319,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
thread->entry_point = entry_point;
thread->stack_top = stack_top;
thread->nominal_priority = thread->current_priority = priority;
thread->last_running_ticks = CoreTiming::GetTicks();
thread->last_running_ticks = Core::System::GetInstance().CoreTiming().GetTicks();
thread->processor_id = processor_id;
thread->wait_objects.clear();
thread->wait_address = 0;
@ -459,10 +462,9 @@ VAddr Thread::GetCommandBufferAddress() const {
}
ThreadManager::ThreadManager() {
ThreadWakeupEventType =
CoreTiming::RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) {
ThreadWakeupCallback(thread_id, cycle_late);
});
ThreadWakeupEventType = Core::System::GetInstance().CoreTiming().RegisterEvent(
"ThreadWakeupCallback",
[this](u64 thread_id, s64 cycle_late) { ThreadWakeupCallback(thread_id, cycle_late); });
}
ThreadManager::~ThreadManager() {

View file

@ -127,7 +127,7 @@ private:
std::unordered_map<u64, Thread*> wakeup_callback_table;
/// Event type for the thread wake up event
CoreTiming::EventType* ThreadWakeupEventType = nullptr;
Core::TimingEventType* ThreadWakeupEventType = nullptr;
// Lists all threadsthat aren't deleted.
std::vector<SharedPtr<Thread>> thread_list;

View file

@ -6,6 +6,7 @@
#include <unordered_map>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/thread.h"
@ -55,13 +56,14 @@ void Timer::Set(s64 initial, s64 interval) {
// Immediately invoke the callback
Signal(0);
} else {
CoreTiming::ScheduleEvent(nsToCycles(initial), timer_manager.timer_callback_event_type,
callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(initial), timer_manager.timer_callback_event_type, callback_id);
}
}
void Timer::Cancel() {
CoreTiming::UnscheduleEvent(timer_manager.timer_callback_event_type, callback_id);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(
timer_manager.timer_callback_event_type, callback_id);
}
void Timer::Clear() {
@ -85,8 +87,9 @@ void Timer::Signal(s64 cycles_late) {
if (interval_delay != 0) {
// Reschedule the timer with the interval delay
CoreTiming::ScheduleEvent(nsToCycles(interval_delay) - cycles_late,
timer_manager.timer_callback_event_type, callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(interval_delay) - cycles_late, timer_manager.timer_callback_event_type,
callback_id);
}
}
@ -103,10 +106,9 @@ void TimerManager::TimerCallback(u64 callback_id, s64 cycles_late) {
}
TimerManager::TimerManager() {
timer_callback_event_type =
CoreTiming::RegisterEvent("TimerCallback", [this](u64 thread_id, s64 cycle_late) {
TimerCallback(thread_id, cycle_late);
});
timer_callback_event_type = Core::System::GetInstance().CoreTiming().RegisterEvent(
"TimerCallback",
[this](u64 thread_id, s64 cycle_late) { TimerCallback(thread_id, cycle_late); });
}
} // namespace Kernel

View file

@ -20,7 +20,7 @@ private:
void TimerCallback(u64 callback_id, s64 cycles_late);
/// The event type of the generic timer callback event
CoreTiming::EventType* timer_callback_event_type = nullptr;
Core::TimingEventType* timer_callback_event_type = nullptr;
u64 next_timer_callback_id = 0;
std::unordered_map<u64, Timer*> timer_callback_table;