pineapple-src/src/core/cpu_manager.h

104 lines
2.6 KiB
C
Raw Normal View History

2022-04-23 14:49:07 -04:00
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-12-28 10:15:37 -05:00
#pragma once
#include <array>
#include <atomic>
#include <functional>
#include <memory>
#include <thread>
#include "common/fiber.h"
#include "common/thread.h"
#include "core/hardware_properties.h"
namespace Common {
class Event;
class Fiber;
} // namespace Common
namespace Core {
class System;
class CpuManager {
public:
2021-05-16 05:38:19 -04:00
explicit CpuManager(System& system_);
2020-12-28 10:15:37 -05:00
CpuManager(const CpuManager&) = delete;
CpuManager(CpuManager&&) = delete;
~CpuManager();
CpuManager& operator=(const CpuManager&) = delete;
CpuManager& operator=(CpuManager&&) = delete;
/// Sets if emulation is multicore or single core, must be set before Initialize
2021-05-05 04:10:21 -04:00
void SetMulticore(bool is_multi) {
is_multicore = is_multi;
2020-12-28 10:15:37 -05:00
}
/// Sets if emulation is using an asynchronous GPU.
2021-05-05 04:10:21 -04:00
void SetAsyncGpu(bool is_async) {
is_async_gpu = is_async;
2020-12-28 10:15:37 -05:00
}
void Initialize();
void Shutdown();
void Pause(bool paused);
static std::function<void(void*)> GetGuestThreadStartFunc();
static std::function<void(void*)> GetIdleThreadStartFunc();
static std::function<void(void*)> GetSuspendThreadStartFunc();
void* GetStartFuncParamater();
void PreemptSingleCore(bool from_running_enviroment = true);
std::size_t CurrentCore() const {
return current_core.load();
}
private:
static void GuestThreadFunction(void* cpu_manager);
static void GuestRewindFunction(void* cpu_manager);
static void IdleThreadFunction(void* cpu_manager);
static void SuspendThreadFunction(void* cpu_manager);
void MultiCoreRunGuestThread();
void MultiCoreRunGuestLoop();
void MultiCoreRunIdleThread();
void MultiCoreRunSuspendThread();
void SingleCoreRunGuestThread();
void SingleCoreRunGuestLoop();
void SingleCoreRunIdleThread();
void SingleCoreRunSuspendThread();
2021-09-03 20:08:38 -04:00
static void ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager, std::size_t core);
2020-12-28 10:15:37 -05:00
2021-09-03 20:08:38 -04:00
void RunThread(std::stop_token stop_token, std::size_t core);
2020-12-28 10:15:37 -05:00
struct CoreData {
2021-03-05 20:58:44 -05:00
std::shared_ptr<Common::Fiber> host_context;
2021-09-03 20:08:38 -04:00
std::jthread host_thread;
2020-12-28 10:15:37 -05:00
};
std::atomic<bool> running_mode{};
2022-06-10 16:06:26 -04:00
std::atomic<bool> pause_state{};
std::unique_ptr<Common::Barrier> pause_barrier{};
std::mutex pause_lock{};
2020-12-28 10:15:37 -05:00
std::array<CoreData, Core::Hardware::NUM_CPU_CORES> core_data{};
bool is_async_gpu{};
bool is_multicore{};
std::atomic<std::size_t> current_core{};
std::size_t idle_count{};
static constexpr std::size_t max_cycle_runs = 5;
System& system;
};
} // namespace Core