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