2018-05-02 05:21:38 +03:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-05-03 04:26:14 +03:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
|
2018-05-02 05:21:38 +03:00
|
|
|
#include "common/logging/log.h"
|
2018-09-18 01:15:09 +03:00
|
|
|
#include "core/arm/exclusive_monitor.h"
|
2018-05-02 05:21:38 +03:00
|
|
|
#include "core/arm/unicorn/arm_unicorn.h"
|
2019-03-05 00:02:59 +03:00
|
|
|
#include "core/core.h"
|
2020-01-26 21:07:22 +03:00
|
|
|
#include "core/core_manager.h"
|
2018-05-02 05:21:38 +03:00
|
|
|
#include "core/core_timing.h"
|
2020-01-26 01:55:32 +03:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/physical_core.h"
|
2018-05-02 05:21:38 +03:00
|
|
|
#include "core/hle/kernel/scheduler.h"
|
|
|
|
#include "core/hle/kernel/thread.h"
|
2018-08-13 01:50:44 +03:00
|
|
|
#include "core/hle/lock.h"
|
2018-05-02 05:21:38 +03:00
|
|
|
#include "core/settings.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
CoreManager::CoreManager(System& system, std::size_t core_index)
|
2020-01-26 23:14:18 +03:00
|
|
|
: global_scheduler{system.GlobalScheduler()}, physical_core{system.Kernel().PhysicalCore(
|
|
|
|
core_index)},
|
|
|
|
core_timing{system.CoreTiming()}, core_index{core_index} {}
|
2018-05-02 05:21:38 +03:00
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
CoreManager::~CoreManager() = default;
|
2018-09-18 01:15:09 +03:00
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
void CoreManager::RunLoop(bool tight_loop) {
|
2019-03-30 00:09:10 +03:00
|
|
|
Reschedule();
|
|
|
|
|
2018-05-02 05:21:38 +03:00
|
|
|
// If we don't have a currently active thread then don't execute instructions,
|
|
|
|
// instead advance to the next event and try to yield to the next thread
|
|
|
|
if (Kernel::GetCurrentThread() == nullptr) {
|
2018-07-02 19:13:26 +03:00
|
|
|
LOG_TRACE(Core, "Core-{} idling", core_index);
|
2019-09-10 04:37:29 +03:00
|
|
|
core_timing.Idle();
|
2018-05-02 05:21:38 +03:00
|
|
|
} else {
|
|
|
|
if (tight_loop) {
|
2020-01-26 01:55:32 +03:00
|
|
|
physical_core.Run();
|
2018-05-02 05:21:38 +03:00
|
|
|
} else {
|
2020-01-26 01:55:32 +03:00
|
|
|
physical_core.Step();
|
2018-05-02 05:21:38 +03:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 00:09:10 +03:00
|
|
|
core_timing.Advance();
|
2018-05-02 05:21:38 +03:00
|
|
|
|
|
|
|
Reschedule();
|
|
|
|
}
|
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
void CoreManager::SingleStep() {
|
2018-05-02 05:21:38 +03:00
|
|
|
return RunLoop(false);
|
|
|
|
}
|
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
void CoreManager::PrepareReschedule() {
|
2020-01-26 01:55:32 +03:00
|
|
|
physical_core.Stop();
|
2018-05-02 05:21:38 +03:00
|
|
|
}
|
|
|
|
|
2020-01-26 21:07:22 +03:00
|
|
|
void CoreManager::Reschedule() {
|
2018-08-13 01:50:44 +03:00
|
|
|
// Lock the global kernel mutex when we manipulate the HLE state
|
2019-06-19 16:11:18 +03:00
|
|
|
std::lock_guard lock(HLE::g_hle_lock);
|
2019-03-30 00:09:10 +03:00
|
|
|
|
|
|
|
global_scheduler.SelectThread(core_index);
|
2018-05-02 05:21:38 +03:00
|
|
|
|
2020-01-26 01:55:32 +03:00
|
|
|
physical_core.Scheduler().TryDoContextSwitch();
|
2019-10-12 15:21:51 +03:00
|
|
|
}
|
|
|
|
|
2018-05-02 05:21:38 +03:00
|
|
|
} // namespace Core
|