core_manager.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <condition_variable>
  5. #include <mutex>
  6. #include "common/logging/log.h"
  7. #include "core/arm/exclusive_monitor.h"
  8. #include "core/arm/unicorn/arm_unicorn.h"
  9. #include "core/core.h"
  10. #include "core/core_manager.h"
  11. #include "core/core_timing.h"
  12. #include "core/hle/kernel/kernel.h"
  13. #include "core/hle/kernel/physical_core.h"
  14. #include "core/hle/kernel/scheduler.h"
  15. #include "core/hle/kernel/thread.h"
  16. #include "core/hle/lock.h"
  17. #include "core/settings.h"
  18. namespace Core {
  19. CoreManager::CoreManager(System& system, std::size_t core_index)
  20. : global_scheduler{system.GlobalScheduler()}, physical_core{system.Kernel().PhysicalCore(
  21. core_index)},
  22. core_timing{system.CoreTiming()}, core_index{core_index} {}
  23. CoreManager::~CoreManager() = default;
  24. void CoreManager::RunLoop(bool tight_loop) {
  25. Reschedule();
  26. // If we don't have a currently active thread then don't execute instructions,
  27. // instead advance to the next event and try to yield to the next thread
  28. if (Kernel::GetCurrentThread() == nullptr) {
  29. LOG_TRACE(Core, "Core-{} idling", core_index);
  30. core_timing.Idle();
  31. } else {
  32. if (tight_loop) {
  33. physical_core.Run();
  34. } else {
  35. physical_core.Step();
  36. }
  37. }
  38. core_timing.Advance();
  39. Reschedule();
  40. }
  41. void CoreManager::SingleStep() {
  42. return RunLoop(false);
  43. }
  44. void CoreManager::PrepareReschedule() {
  45. physical_core.Stop();
  46. }
  47. void CoreManager::Reschedule() {
  48. // Lock the global kernel mutex when we manipulate the HLE state
  49. std::lock_guard lock(HLE::g_hle_lock);
  50. global_scheduler.SelectThread(core_index);
  51. physical_core.Scheduler().TryDoContextSwitch();
  52. }
  53. } // namespace Core