Kernel: replace usage of Core::System::GetInstance()::Timing()
This commit is contained in:
parent
276ca88c9e
commit
eb050b8403
|
@ -174,7 +174,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) {
|
|||
|
||||
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) {
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
namespace 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);
|
||||
|
||||
resource_limits = std::make_unique<ResourceLimitList>(*this);
|
||||
thread_manager = std::make_unique<ThreadManager>(*this);
|
||||
timer_manager = std::make_unique<TimerManager>();
|
||||
timer_manager = std::make_unique<TimerManager>(timing);
|
||||
}
|
||||
|
||||
/// Shutdown the kernel
|
||||
|
|
|
@ -27,6 +27,10 @@ namespace Memory {
|
|||
class MemorySystem;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
class Timing;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class AddressArbiter;
|
||||
|
@ -78,7 +82,7 @@ using SharedPtr = boost::intrusive_ptr<T>;
|
|||
|
||||
class KernelSystem {
|
||||
public:
|
||||
explicit KernelSystem(Memory::MemorySystem& memory, u32 system_mode);
|
||||
explicit KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 system_mode);
|
||||
~KernelSystem();
|
||||
|
||||
/**
|
||||
|
@ -229,6 +233,8 @@ public:
|
|||
|
||||
Memory::MemorySystem& memory;
|
||||
|
||||
Core::Timing& timing;
|
||||
|
||||
private:
|
||||
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.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) {
|
||||
|
|
|
@ -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));
|
||||
|
||||
shared_page.running_hw = 0x1; // product
|
||||
|
@ -54,9 +54,9 @@ Handler::Handler() {
|
|||
init_time = GetInitTime();
|
||||
|
||||
using namespace std::placeholders;
|
||||
update_time_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
||||
"SharedPage::UpdateTimeCallback", std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
|
||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(0, update_time_event);
|
||||
update_time_event = timing.RegisterEvent("SharedPage::UpdateTimeCallback",
|
||||
std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
|
||||
timing.ScheduleEvent(0, update_time_event);
|
||||
|
||||
float slidestate =
|
||||
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.
|
||||
u64 Handler::GetSystemTime() const {
|
||||
std::chrono::milliseconds now =
|
||||
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
Core::System::GetInstance().CoreTiming().GetGlobalTimeUs());
|
||||
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(timing.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.
|
||||
|
@ -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;
|
||||
|
||||
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_offset = 0;
|
||||
|
||||
++shared_page.date_time_counter;
|
||||
|
||||
// system time is updated hourly
|
||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late,
|
||||
update_time_event);
|
||||
timing.ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late, update_time_event);
|
||||
}
|
||||
|
||||
void Handler::SetMacAddress(const MacAddress& addr) {
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
namespace Core {
|
||||
struct TimingEventType;
|
||||
}
|
||||
class Timing;
|
||||
} // namespace Core
|
||||
|
||||
namespace SharedPage {
|
||||
|
||||
|
@ -83,7 +84,7 @@ static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE,
|
|||
|
||||
class Handler {
|
||||
public:
|
||||
Handler();
|
||||
Handler(Core::Timing& timing);
|
||||
|
||||
void SetMacAddress(const MacAddress&);
|
||||
|
||||
|
@ -98,6 +99,7 @@ public:
|
|||
private:
|
||||
u64 GetSystemTime() const;
|
||||
void UpdateTimeCallback(u64 userdata, int cycles_late);
|
||||
Core::Timing& timing;
|
||||
Core::TimingEventType* update_time_event;
|
||||
std::chrono::seconds init_time;
|
||||
|
||||
|
|
|
@ -48,8 +48,7 @@ Thread* ThreadManager::GetCurrentThread() const {
|
|||
|
||||
void Thread::Stop() {
|
||||
// Cancel any outstanding wakeup events for this thread
|
||||
Core::System::GetInstance().CoreTiming().UnscheduleEvent(thread_manager.ThreadWakeupEventType,
|
||||
thread_id);
|
||||
thread_manager.kernel.timing.UnscheduleEvent(thread_manager.ThreadWakeupEventType, thread_id);
|
||||
thread_manager.wakeup_callback_table.erase(thread_id);
|
||||
|
||||
// Clean up thread from ready queue
|
||||
|
@ -81,7 +80,7 @@ void Thread::Stop() {
|
|||
void ThreadManager::SwitchContext(Thread* new_thread) {
|
||||
Thread* previous_thread = GetCurrentThread();
|
||||
|
||||
Core::Timing& timing = Core::System::GetInstance().CoreTiming();
|
||||
Core::Timing& timing = kernel.timing;
|
||||
|
||||
// Save context for previous thread
|
||||
if (previous_thread) {
|
||||
|
@ -186,8 +185,8 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
|
|||
if (nanoseconds == -1)
|
||||
return;
|
||||
|
||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
||||
nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType, thread_id);
|
||||
thread_manager.kernel.timing.ScheduleEvent(nsToCycles(nanoseconds),
|
||||
thread_manager.ThreadWakeupEventType, thread_id);
|
||||
}
|
||||
|
||||
void Thread::ResumeFromWait() {
|
||||
|
@ -320,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 = Core::System::GetInstance().CoreTiming().GetTicks();
|
||||
thread->last_running_ticks = timing.GetTicks();
|
||||
thread->processor_id = processor_id;
|
||||
thread->wait_objects.clear();
|
||||
thread->wait_address = 0;
|
||||
|
@ -462,9 +461,10 @@ VAddr Thread::GetCommandBufferAddress() const {
|
|||
}
|
||||
|
||||
ThreadManager::ThreadManager(Kernel::KernelSystem& kernel) : kernel(kernel) {
|
||||
ThreadWakeupEventType = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
||||
"ThreadWakeupCallback",
|
||||
[this](u64 thread_id, s64 cycle_late) { ThreadWakeupCallback(thread_id, cycle_late); });
|
||||
ThreadWakeupEventType =
|
||||
kernel.timing.RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) {
|
||||
ThreadWakeupCallback(thread_id, cycle_late);
|
||||
});
|
||||
}
|
||||
|
||||
ThreadManager::~ThreadManager() {
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
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() {
|
||||
Cancel();
|
||||
timer_manager.timer_callback_table.erase(callback_id);
|
||||
|
@ -56,14 +57,13 @@ void Timer::Set(s64 initial, s64 interval) {
|
|||
// Immediately invoke the callback
|
||||
Signal(0);
|
||||
} else {
|
||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
||||
nsToCycles(initial), timer_manager.timer_callback_event_type, callback_id);
|
||||
kernel.timing.ScheduleEvent(nsToCycles(initial), timer_manager.timer_callback_event_type,
|
||||
callback_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::Cancel() {
|
||||
Core::System::GetInstance().CoreTiming().UnscheduleEvent(
|
||||
timer_manager.timer_callback_event_type, callback_id);
|
||||
kernel.timing.UnscheduleEvent(timer_manager.timer_callback_event_type, callback_id);
|
||||
}
|
||||
|
||||
void Timer::Clear() {
|
||||
|
@ -87,9 +87,8 @@ void Timer::Signal(s64 cycles_late) {
|
|||
|
||||
if (interval_delay != 0) {
|
||||
// Reschedule the timer with the interval delay
|
||||
Core::System::GetInstance().CoreTiming().ScheduleEvent(
|
||||
nsToCycles(interval_delay) - cycles_late, timer_manager.timer_callback_event_type,
|
||||
callback_id);
|
||||
kernel.timing.ScheduleEvent(nsToCycles(interval_delay) - cycles_late,
|
||||
timer_manager.timer_callback_event_type, callback_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,10 +104,11 @@ void TimerManager::TimerCallback(u64 callback_id, s64 cycles_late) {
|
|||
timer->Signal(cycles_late);
|
||||
}
|
||||
|
||||
TimerManager::TimerManager() {
|
||||
timer_callback_event_type = Core::System::GetInstance().CoreTiming().RegisterEvent(
|
||||
"TimerCallback",
|
||||
[this](u64 thread_id, s64 cycle_late) { TimerCallback(thread_id, cycle_late); });
|
||||
TimerManager::TimerManager(Core::Timing& timing) : timing(timing) {
|
||||
timer_callback_event_type =
|
||||
timing.RegisterEvent("TimerCallback", [this](u64 thread_id, s64 cycle_late) {
|
||||
TimerCallback(thread_id, cycle_late);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -9,16 +9,22 @@
|
|||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/wait_object.h"
|
||||
|
||||
namespace Core {
|
||||
class Timing;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class TimerManager {
|
||||
public:
|
||||
TimerManager();
|
||||
TimerManager(Core::Timing& timing);
|
||||
|
||||
private:
|
||||
/// The timer callback event, called when a timer is fired
|
||||
void TimerCallback(u64 callback_id, s64 cycles_late);
|
||||
|
||||
Core::Timing& timing;
|
||||
|
||||
/// The event type of the generic timer callback event
|
||||
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.
|
||||
u64 callback_id;
|
||||
|
||||
KernelSystem& kernel;
|
||||
TimerManager& timer_manager;
|
||||
|
||||
friend class KernelSystem;
|
||||
|
|
|
@ -21,7 +21,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
|||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||
Core::System::GetInstance().memory = std::make_unique<Memory::MemorySystem>();
|
||||
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->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0)));
|
||||
|
|
|
@ -24,7 +24,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
// HACK: see comments of member timing
|
||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||
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());
|
||||
HLERequestContext context(std::move(session));
|
||||
|
||||
|
@ -237,7 +237,7 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
|||
// HACK: see comments of member timing
|
||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||
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());
|
||||
HLERequestContext context(std::move(session));
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
|||
// HACK: see comments of member timing
|
||||
Core::System::GetInstance().timing = std::make_unique<Core::Timing>();
|
||||
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") {
|
||||
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||
|
|
Loading…
Reference in New Issue