Kernel: replace usage of Core::System::GetInstance()::Timing()
This commit is contained in:
parent
276ca88c9e
commit
eb050b8403
12 changed files with 58 additions and 42 deletions
|
@ -174,7 +174,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) {
|
||||||
|
|
||||||
timing = std::make_unique<Timing>();
|
timing = std::make_unique<Timing>();
|
||||||
|
|
||||||
kernel = std::make_unique<Kernel::KernelSystem>(*memory, system_mode);
|
kernel = std::make_unique<Kernel::KernelSystem>(*memory, *timing, system_mode);
|
||||||
|
|
||||||
if (Settings::values.use_cpu_jit) {
|
if (Settings::values.use_cpu_jit) {
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
/// Initialize the kernel
|
/// Initialize the kernel
|
||||||
KernelSystem::KernelSystem(Memory::MemorySystem& memory, u32 system_mode) : memory(memory) {
|
KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 system_mode)
|
||||||
|
: memory(memory), timing(timing) {
|
||||||
MemoryInit(system_mode);
|
MemoryInit(system_mode);
|
||||||
|
|
||||||
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
||||||
thread_manager = std::make_unique<ThreadManager>(*this);
|
thread_manager = std::make_unique<ThreadManager>(*this);
|
||||||
timer_manager = std::make_unique<TimerManager>();
|
timer_manager = std::make_unique<TimerManager>(timing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shutdown the kernel
|
/// Shutdown the kernel
|
||||||
|
|
|
@ -27,6 +27,10 @@ namespace Memory {
|
||||||
class MemorySystem;
|
class MemorySystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class Timing;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class AddressArbiter;
|
class AddressArbiter;
|
||||||
|
@ -78,7 +82,7 @@ using SharedPtr = boost::intrusive_ptr<T>;
|
||||||
|
|
||||||
class KernelSystem {
|
class KernelSystem {
|
||||||
public:
|
public:
|
||||||
explicit KernelSystem(Memory::MemorySystem& memory, u32 system_mode);
|
explicit KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 system_mode);
|
||||||
~KernelSystem();
|
~KernelSystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,6 +233,8 @@ public:
|
||||||
|
|
||||||
Memory::MemorySystem& memory;
|
Memory::MemorySystem& memory;
|
||||||
|
|
||||||
|
Core::Timing& timing;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MemoryInit(u32 mem_type);
|
void MemoryInit(u32 mem_type);
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ void KernelSystem::MemoryInit(u32 mem_type) {
|
||||||
config_mem.sys_mem_alloc = memory_regions[1].size;
|
config_mem.sys_mem_alloc = memory_regions[1].size;
|
||||||
config_mem.base_mem_alloc = memory_regions[2].size;
|
config_mem.base_mem_alloc = memory_regions[2].size;
|
||||||
|
|
||||||
shared_page_handler = std::make_unique<SharedPage::Handler>();
|
shared_page_handler = std::make_unique<SharedPage::Handler>(timing);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) {
|
MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ static std::chrono::seconds GetInitTime() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handler::Handler() {
|
Handler::Handler(Core::Timing& timing) : timing(timing) {
|
||||||
std::memset(&shared_page, 0, sizeof(shared_page));
|
std::memset(&shared_page, 0, sizeof(shared_page));
|
||||||
|
|
||||||
shared_page.running_hw = 0x1; // product
|
shared_page.running_hw = 0x1; // product
|
||||||
|
@ -54,9 +54,9 @@ Handler::Handler() {
|
||||||
init_time = GetInitTime();
|
init_time = GetInitTime();
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
update_time_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
update_time_event = timing.RegisterEvent("SharedPage::UpdateTimeCallback",
|
||||||
"SharedPage::UpdateTimeCallback", std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
|
std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(0, update_time_event);
|
timing.ScheduleEvent(0, update_time_event);
|
||||||
|
|
||||||
float slidestate =
|
float slidestate =
|
||||||
Settings::values.toggle_3d ? (float_le)Settings::values.factor_3d / 100 : 0.0f;
|
Settings::values.toggle_3d ? (float_le)Settings::values.factor_3d / 100 : 0.0f;
|
||||||
|
@ -66,8 +66,7 @@ Handler::Handler() {
|
||||||
/// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond.
|
/// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond.
|
||||||
u64 Handler::GetSystemTime() const {
|
u64 Handler::GetSystemTime() const {
|
||||||
std::chrono::milliseconds now =
|
std::chrono::milliseconds now =
|
||||||
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(
|
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(timing.GetGlobalTimeUs());
|
||||||
Core::System::GetInstance().CoreTiming().GetGlobalTimeUs());
|
|
||||||
|
|
||||||
// 3DS system does't allow user to set a time before Jan 1 2000,
|
// 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.
|
// so we use it as an auxiliary epoch to calculate the console time.
|
||||||
|
@ -98,15 +97,14 @@ void Handler::UpdateTimeCallback(u64 userdata, int cycles_late) {
|
||||||
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;
|
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;
|
||||||
|
|
||||||
date_time.date_time = GetSystemTime();
|
date_time.date_time = GetSystemTime();
|
||||||
date_time.update_tick = Core::System::GetInstance().CoreTiming().GetTicks();
|
date_time.update_tick = timing.GetTicks();
|
||||||
date_time.tick_to_second_coefficient = BASE_CLOCK_RATE_ARM11;
|
date_time.tick_to_second_coefficient = BASE_CLOCK_RATE_ARM11;
|
||||||
date_time.tick_offset = 0;
|
date_time.tick_offset = 0;
|
||||||
|
|
||||||
++shared_page.date_time_counter;
|
++shared_page.date_time_counter;
|
||||||
|
|
||||||
// system time is updated hourly
|
// system time is updated hourly
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late,
|
timing.ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late, update_time_event);
|
||||||
update_time_event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Handler::SetMacAddress(const MacAddress& addr) {
|
void Handler::SetMacAddress(const MacAddress& addr) {
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
struct TimingEventType;
|
struct TimingEventType;
|
||||||
}
|
class Timing;
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
namespace SharedPage {
|
namespace SharedPage {
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE,
|
||||||
|
|
||||||
class Handler {
|
class Handler {
|
||||||
public:
|
public:
|
||||||
Handler();
|
Handler(Core::Timing& timing);
|
||||||
|
|
||||||
void SetMacAddress(const MacAddress&);
|
void SetMacAddress(const MacAddress&);
|
||||||
|
|
||||||
|
@ -98,6 +99,7 @@ public:
|
||||||
private:
|
private:
|
||||||
u64 GetSystemTime() const;
|
u64 GetSystemTime() const;
|
||||||
void UpdateTimeCallback(u64 userdata, int cycles_late);
|
void UpdateTimeCallback(u64 userdata, int cycles_late);
|
||||||
|
Core::Timing& timing;
|
||||||
Core::TimingEventType* update_time_event;
|
Core::TimingEventType* update_time_event;
|
||||||
std::chrono::seconds init_time;
|
std::chrono::seconds init_time;
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,7 @@ Thread* ThreadManager::GetCurrentThread() const {
|
||||||
|
|
||||||
void Thread::Stop() {
|
void Thread::Stop() {
|
||||||
// Cancel any outstanding wakeup events for this thread
|
// Cancel any outstanding wakeup events for this thread
|
||||||
Core::System::GetInstance().CoreTiming().UnscheduleEvent(thread_manager.ThreadWakeupEventType,
|
thread_manager.kernel.timing.UnscheduleEvent(thread_manager.ThreadWakeupEventType, thread_id);
|
||||||
thread_id);
|
|
||||||
thread_manager.wakeup_callback_table.erase(thread_id);
|
thread_manager.wakeup_callback_table.erase(thread_id);
|
||||||
|
|
||||||
// Clean up thread from ready queue
|
// Clean up thread from ready queue
|
||||||
|
@ -81,7 +80,7 @@ void Thread::Stop() {
|
||||||
void ThreadManager::SwitchContext(Thread* new_thread) {
|
void ThreadManager::SwitchContext(Thread* new_thread) {
|
||||||
Thread* previous_thread = GetCurrentThread();
|
Thread* previous_thread = GetCurrentThread();
|
||||||
|
|
||||||
Core::Timing& timing = Core::System::GetInstance().CoreTiming();
|
Core::Timing& timing = kernel.timing;
|
||||||
|
|
||||||
// Save context for previous thread
|
// Save context for previous thread
|
||||||
if (previous_thread) {
|
if (previous_thread) {
|
||||||
|
@ -186,8 +185,8 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
|
||||||
if (nanoseconds == -1)
|
if (nanoseconds == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
thread_manager.kernel.timing.ScheduleEvent(nsToCycles(nanoseconds),
|
||||||
nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType, thread_id);
|
thread_manager.ThreadWakeupEventType, thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::ResumeFromWait() {
|
void Thread::ResumeFromWait() {
|
||||||
|
@ -320,7 +319,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
|
||||||
thread->entry_point = entry_point;
|
thread->entry_point = entry_point;
|
||||||
thread->stack_top = stack_top;
|
thread->stack_top = stack_top;
|
||||||
thread->nominal_priority = thread->current_priority = priority;
|
thread->nominal_priority = thread->current_priority = priority;
|
||||||
thread->last_running_ticks = Core::System::GetInstance().CoreTiming().GetTicks();
|
thread->last_running_ticks = timing.GetTicks();
|
||||||
thread->processor_id = processor_id;
|
thread->processor_id = processor_id;
|
||||||
thread->wait_objects.clear();
|
thread->wait_objects.clear();
|
||||||
thread->wait_address = 0;
|
thread->wait_address = 0;
|
||||||
|
@ -462,9 +461,10 @@ VAddr Thread::GetCommandBufferAddress() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadManager::ThreadManager(Kernel::KernelSystem& kernel) : kernel(kernel) {
|
ThreadManager::ThreadManager(Kernel::KernelSystem& kernel) : kernel(kernel) {
|
||||||
ThreadWakeupEventType = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
ThreadWakeupEventType =
|
||||||
"ThreadWakeupCallback",
|
kernel.timing.RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) {
|
||||||
[this](u64 thread_id, s64 cycle_late) { ThreadWakeupCallback(thread_id, cycle_late); });
|
ThreadWakeupCallback(thread_id, cycle_late);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadManager::~ThreadManager() {
|
ThreadManager::~ThreadManager() {
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
Timer::Timer(KernelSystem& kernel) : WaitObject(kernel), timer_manager(kernel.GetTimerManager()) {}
|
Timer::Timer(KernelSystem& kernel)
|
||||||
|
: WaitObject(kernel), kernel(kernel), timer_manager(kernel.GetTimerManager()) {}
|
||||||
Timer::~Timer() {
|
Timer::~Timer() {
|
||||||
Cancel();
|
Cancel();
|
||||||
timer_manager.timer_callback_table.erase(callback_id);
|
timer_manager.timer_callback_table.erase(callback_id);
|
||||||
|
@ -56,14 +57,13 @@ void Timer::Set(s64 initial, s64 interval) {
|
||||||
// Immediately invoke the callback
|
// Immediately invoke the callback
|
||||||
Signal(0);
|
Signal(0);
|
||||||
} else {
|
} else {
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
kernel.timing.ScheduleEvent(nsToCycles(initial), timer_manager.timer_callback_event_type,
|
||||||
nsToCycles(initial), timer_manager.timer_callback_event_type, callback_id);
|
callback_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::Cancel() {
|
void Timer::Cancel() {
|
||||||
Core::System::GetInstance().CoreTiming().UnscheduleEvent(
|
kernel.timing.UnscheduleEvent(timer_manager.timer_callback_event_type, callback_id);
|
||||||
timer_manager.timer_callback_event_type, callback_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::Clear() {
|
void Timer::Clear() {
|
||||||
|
@ -87,9 +87,8 @@ void Timer::Signal(s64 cycles_late) {
|
||||||
|
|
||||||
if (interval_delay != 0) {
|
if (interval_delay != 0) {
|
||||||
// Reschedule the timer with the interval delay
|
// Reschedule the timer with the interval delay
|
||||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
kernel.timing.ScheduleEvent(nsToCycles(interval_delay) - cycles_late,
|
||||||
nsToCycles(interval_delay) - cycles_late, timer_manager.timer_callback_event_type,
|
timer_manager.timer_callback_event_type, callback_id);
|
||||||
callback_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +104,11 @@ void TimerManager::TimerCallback(u64 callback_id, s64 cycles_late) {
|
||||||
timer->Signal(cycles_late);
|
timer->Signal(cycles_late);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimerManager::TimerManager() {
|
TimerManager::TimerManager(Core::Timing& timing) : timing(timing) {
|
||||||
timer_callback_event_type = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
timer_callback_event_type =
|
||||||
"TimerCallback",
|
timing.RegisterEvent("TimerCallback", [this](u64 thread_id, s64 cycle_late) {
|
||||||
[this](u64 thread_id, s64 cycle_late) { TimerCallback(thread_id, cycle_late); });
|
TimerCallback(thread_id, cycle_late);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -9,16 +9,22 @@
|
||||||
#include "core/hle/kernel/object.h"
|
#include "core/hle/kernel/object.h"
|
||||||
#include "core/hle/kernel/wait_object.h"
|
#include "core/hle/kernel/wait_object.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class Timing;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class TimerManager {
|
class TimerManager {
|
||||||
public:
|
public:
|
||||||
TimerManager();
|
TimerManager(Core::Timing& timing);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// The timer callback event, called when a timer is fired
|
/// The timer callback event, called when a timer is fired
|
||||||
void TimerCallback(u64 callback_id, s64 cycles_late);
|
void TimerCallback(u64 callback_id, s64 cycles_late);
|
||||||
|
|
||||||
|
Core::Timing& timing;
|
||||||
|
|
||||||
/// The event type of the generic timer callback event
|
/// The event type of the generic timer callback event
|
||||||
Core::TimingEventType* timer_callback_event_type = nullptr;
|
Core::TimingEventType* timer_callback_event_type = nullptr;
|
||||||
|
|
||||||
|
@ -93,6 +99,7 @@ private:
|
||||||
/// ID used as userdata to reference this object when inserting into the CoreTiming queue.
|
/// ID used as userdata to reference this object when inserting into the CoreTiming queue.
|
||||||
u64 callback_id;
|
u64 callback_id;
|
||||||
|
|
||||||
|
KernelSystem& kernel;
|
||||||
TimerManager& timer_manager;
|
TimerManager& timer_manager;
|
||||||
|
|
||||||
friend class KernelSystem;
|
friend class KernelSystem;
|
||||||
|
|
|
@ -21,7 +21,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||||
Core::System::GetInstance().memory = std::make_unique<Memory::MemorySystem>();
|
Core::System::GetInstance().memory = std::make_unique<Memory::MemorySystem>();
|
||||||
Memory::MemorySystem& memory = *Core::System::GetInstance().memory;
|
Memory::MemorySystem& memory = *Core::System::GetInstance().memory;
|
||||||
Core::System::GetInstance().kernel = std::make_unique<Kernel::KernelSystem>(memory, 0);
|
Core::System::GetInstance().kernel =
|
||||||
|
std::make_unique<Kernel::KernelSystem>(memory, *Core::System::GetInstance().timing, 0);
|
||||||
kernel = Core::System::GetInstance().kernel.get();
|
kernel = Core::System::GetInstance().kernel.get();
|
||||||
|
|
||||||
kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0)));
|
kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0)));
|
||||||
|
|
|
@ -24,7 +24,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
||||||
// HACK: see comments of member timing
|
// HACK: see comments of member timing
|
||||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||||
auto memory = std::make_unique<Memory::MemorySystem>();
|
auto memory = std::make_unique<Memory::MemorySystem>();
|
||||||
Kernel::KernelSystem kernel(*memory, 0);
|
Kernel::KernelSystem kernel(*memory, *Core::System::GetInstance().timing, 0);
|
||||||
auto session = std::get<SharedPtr<ServerSession>>(kernel.CreateSessionPair());
|
auto session = std::get<SharedPtr<ServerSession>>(kernel.CreateSessionPair());
|
||||||
HLERequestContext context(std::move(session));
|
HLERequestContext context(std::move(session));
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
||||||
// HACK: see comments of member timing
|
// HACK: see comments of member timing
|
||||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||||
auto memory = std::make_unique<Memory::MemorySystem>();
|
auto memory = std::make_unique<Memory::MemorySystem>();
|
||||||
Kernel::KernelSystem kernel(*memory, 0);
|
Kernel::KernelSystem kernel(*memory, *Core::System::GetInstance().timing, 0);
|
||||||
auto session = std::get<SharedPtr<ServerSession>>(kernel.CreateSessionPair());
|
auto session = std::get<SharedPtr<ServerSession>>(kernel.CreateSessionPair());
|
||||||
HLERequestContext context(std::move(session));
|
HLERequestContext context(std::move(session));
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||||
// HACK: see comments of member timing
|
// HACK: see comments of member timing
|
||||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||||
Core::System::GetInstance().memory = std::make_unique<Memory::MemorySystem>();
|
Core::System::GetInstance().memory = std::make_unique<Memory::MemorySystem>();
|
||||||
Kernel::KernelSystem kernel(*Core::System::GetInstance().memory, 0);
|
Kernel::KernelSystem kernel(*Core::System::GetInstance().memory,
|
||||||
|
*Core::System::GetInstance().timing, 0);
|
||||||
SECTION("these regions should not be mapped on an empty process") {
|
SECTION("these regions should not be mapped on an empty process") {
|
||||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||||
|
|
Loading…
Reference in a new issue