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