Kernel: replace usage of Core::System::GetInstance().PrepareReschedule() with callback

This commit is contained in:
Weiyi Wang 2019-02-01 12:19:20 -05:00
parent eb050b8403
commit 20f47583f6
9 changed files with 25 additions and 13 deletions

View File

@ -174,7 +174,8 @@ 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, *timing, system_mode); kernel = std::make_unique<Kernel::KernelSystem>(*memory, *timing,
[this] { PrepareReschedule(); }, system_mode);
if (Settings::values.use_cpu_jit) { if (Settings::values.use_cpu_jit) {
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64

View File

@ -16,8 +16,10 @@
namespace Kernel { namespace Kernel {
/// Initialize the kernel /// Initialize the kernel
KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 system_mode) KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing,
: memory(memory), timing(timing) { std::function<void()> prepare_reschedule_callback, u32 system_mode)
: memory(memory), timing(timing),
prepare_reschedule_callback(std::move(prepare_reschedule_callback)) {
MemoryInit(system_mode); MemoryInit(system_mode);
resource_limits = std::make_unique<ResourceLimitList>(*this); resource_limits = std::make_unique<ResourceLimitList>(*this);

View File

@ -6,6 +6,7 @@
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -82,7 +83,8 @@ using SharedPtr = boost::intrusive_ptr<T>;
class KernelSystem { class KernelSystem {
public: public:
explicit KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 system_mode); explicit KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing,
std::function<void()> prepare_reschedule_callback, u32 system_mode);
~KernelSystem(); ~KernelSystem();
/** /**
@ -228,6 +230,10 @@ public:
/// Adds a port to the named port table /// Adds a port to the named port table
void AddNamedPort(std::string name, SharedPtr<ClientPort> port); void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
void PrepareReschedule() {
prepare_reschedule_callback();
}
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort /// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
std::unordered_map<std::string, SharedPtr<ClientPort>> named_ports; std::unordered_map<std::string, SharedPtr<ClientPort>> named_ports;
@ -238,6 +244,8 @@ public:
private: private:
void MemoryInit(u32 mem_type); void MemoryInit(u32 mem_type);
std::function<void()> prepare_reschedule_callback;
std::unique_ptr<ResourceLimitList> resource_limits; std::unique_ptr<ResourceLimitList> resource_limits;
std::atomic<u32> next_object_id{0}; std::atomic<u32> next_object_id{0};

View File

@ -24,7 +24,7 @@ void ReleaseThreadMutexes(Thread* thread) {
thread->held_mutexes.clear(); thread->held_mutexes.clear();
} }
Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel) {} Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel), kernel(kernel) {}
Mutex::~Mutex() {} Mutex::~Mutex() {}
SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) { SharedPtr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {
@ -54,7 +54,7 @@ void Mutex::Acquire(Thread* thread) {
thread->held_mutexes.insert(this); thread->held_mutexes.insert(this);
holding_thread = thread; holding_thread = thread;
thread->UpdatePriority(); thread->UpdatePriority();
Core::System::GetInstance().PrepareReschedule(); kernel.PrepareReschedule();
} }
lock_count++; lock_count++;
@ -87,7 +87,7 @@ ResultCode Mutex::Release(Thread* thread) {
holding_thread->UpdatePriority(); holding_thread->UpdatePriority();
holding_thread = nullptr; holding_thread = nullptr;
WakeupAllWaitingThreads(); WakeupAllWaitingThreads();
Core::System::GetInstance().PrepareReschedule(); kernel.PrepareReschedule();
} }
return RESULT_SUCCESS; return RESULT_SUCCESS;

View File

@ -57,6 +57,7 @@ private:
~Mutex() override; ~Mutex() override;
friend class KernelSystem; friend class KernelSystem;
KernelSystem& kernel;
}; };
/** /**

View File

@ -224,7 +224,7 @@ void Thread::ResumeFromWait() {
thread_manager.ready_queue.push_back(current_priority, this); thread_manager.ready_queue.push_back(current_priority, this);
status = ThreadStatus::Ready; status = ThreadStatus::Ready;
Core::System::GetInstance().PrepareReschedule(); thread_manager.kernel.PrepareReschedule();
} }
void ThreadManager::DebugThreadQueue() { void ThreadManager::DebugThreadQueue() {

View File

@ -21,8 +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 = Core::System::GetInstance().kernel = std::make_unique<Kernel::KernelSystem>(
std::make_unique<Kernel::KernelSystem>(memory, *Core::System::GetInstance().timing, 0); 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)));

View File

@ -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, *Core::System::GetInstance().timing, 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, *Core::System::GetInstance().timing, 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));

View File

@ -15,7 +15,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][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>();
Kernel::KernelSystem kernel(*Core::System::GetInstance().memory, Kernel::KernelSystem kernel(*Core::System::GetInstance().memory,
*Core::System::GetInstance().timing, 0); *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);