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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-05-03 00:16:12 -04:00
|
|
|
#include <atomic>
|
2018-05-02 21:26:14 -04:00
|
|
|
#include <condition_variable>
|
2018-09-17 18:15:09 -04:00
|
|
|
#include <cstddef>
|
2018-05-01 22:21:38 -04:00
|
|
|
#include <memory>
|
2018-05-02 21:26:14 -04:00
|
|
|
#include <mutex>
|
2018-05-01 22:21:38 -04:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
2019-03-29 17:09:10 -04:00
|
|
|
class GlobalScheduler;
|
2019-06-19 09:11:18 -04:00
|
|
|
class Scheduler;
|
2019-04-02 09:22:53 -04:00
|
|
|
} // namespace Kernel
|
2018-05-01 22:21:38 -04:00
|
|
|
|
2019-03-04 16:02:59 -05:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2019-02-14 12:42:58 -05:00
|
|
|
namespace Core::Timing {
|
|
|
|
class CoreTiming;
|
|
|
|
}
|
|
|
|
|
2018-05-01 22:21:38 -04:00
|
|
|
namespace Core {
|
|
|
|
|
2018-08-24 21:43:32 -04:00
|
|
|
class ARM_Interface;
|
2018-09-17 18:15:09 -04:00
|
|
|
class ExclusiveMonitor;
|
2018-08-24 21:43:32 -04:00
|
|
|
|
2018-05-02 21:26:14 -04:00
|
|
|
constexpr unsigned NUM_CPU_CORES{4};
|
|
|
|
|
|
|
|
class CpuBarrier {
|
|
|
|
public:
|
2018-05-03 00:16:12 -04:00
|
|
|
bool IsAlive() const {
|
|
|
|
return !end;
|
|
|
|
}
|
2018-05-02 21:26:14 -04:00
|
|
|
|
2018-05-03 00:16:12 -04:00
|
|
|
void NotifyEnd();
|
2018-05-02 21:26:14 -04:00
|
|
|
|
2018-05-03 00:16:12 -04:00
|
|
|
bool Rendezvous();
|
2018-05-02 21:26:14 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned cores_waiting{NUM_CPU_CORES};
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable condition;
|
2018-05-03 00:16:12 -04:00
|
|
|
std::atomic<bool> end{};
|
2018-05-02 21:26:14 -04:00
|
|
|
};
|
|
|
|
|
2018-05-01 22:21:38 -04:00
|
|
|
class Cpu {
|
|
|
|
public:
|
2019-03-04 16:02:59 -05:00
|
|
|
Cpu(System& system, ExclusiveMonitor& exclusive_monitor, CpuBarrier& cpu_barrier,
|
|
|
|
std::size_t core_index);
|
2018-09-17 18:15:09 -04:00
|
|
|
~Cpu();
|
2018-05-01 22:21:38 -04:00
|
|
|
|
|
|
|
void RunLoop(bool tight_loop = true);
|
|
|
|
|
|
|
|
void SingleStep();
|
|
|
|
|
|
|
|
void PrepareReschedule();
|
|
|
|
|
2018-05-02 22:36:51 -04:00
|
|
|
ARM_Interface& ArmInterface() {
|
2018-05-01 22:21:38 -04:00
|
|
|
return *arm_interface;
|
|
|
|
}
|
|
|
|
|
2018-05-02 22:36:51 -04:00
|
|
|
const ARM_Interface& ArmInterface() const {
|
|
|
|
return *arm_interface;
|
|
|
|
}
|
|
|
|
|
2018-10-15 09:25:11 -04:00
|
|
|
Kernel::Scheduler& Scheduler() {
|
|
|
|
return *scheduler;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Kernel::Scheduler& Scheduler() const {
|
|
|
|
return *scheduler;
|
2018-05-01 22:21:38 -04:00
|
|
|
}
|
|
|
|
|
2018-05-02 21:26:14 -04:00
|
|
|
bool IsMainCore() const {
|
|
|
|
return core_index == 0;
|
|
|
|
}
|
|
|
|
|
2018-09-15 09:21:06 -04:00
|
|
|
std::size_t CoreIndex() const {
|
2018-07-03 09:28:46 -04:00
|
|
|
return core_index;
|
|
|
|
}
|
|
|
|
|
2019-10-12 08:21:51 -04:00
|
|
|
void Shutdown();
|
|
|
|
|
2018-10-15 08:53:01 -04:00
|
|
|
static std::unique_ptr<ExclusiveMonitor> MakeExclusiveMonitor(std::size_t num_cores);
|
2018-07-03 09:28:46 -04:00
|
|
|
|
2018-05-01 22:21:38 -04:00
|
|
|
private:
|
|
|
|
void Reschedule();
|
|
|
|
|
2018-09-25 16:04:53 -04:00
|
|
|
std::unique_ptr<ARM_Interface> arm_interface;
|
2018-10-15 08:42:06 -04:00
|
|
|
CpuBarrier& cpu_barrier;
|
2019-03-29 17:09:10 -04:00
|
|
|
Kernel::GlobalScheduler& global_scheduler;
|
2018-10-15 09:25:11 -04:00
|
|
|
std::unique_ptr<Kernel::Scheduler> scheduler;
|
2019-02-14 12:42:58 -05:00
|
|
|
Timing::CoreTiming& core_timing;
|
2018-05-01 22:21:38 -04:00
|
|
|
|
2018-08-12 18:51:47 -04:00
|
|
|
std::atomic<bool> reschedule_pending = false;
|
2018-09-15 09:21:06 -04:00
|
|
|
std::size_t core_index;
|
2018-05-01 22:21:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Core
|