General: Move ARM_Interface into Threads.

This commit is contained in:
Fernando Sahmkow 2020-03-01 12:14:17 -04:00
parent 1b82ccec22
commit 1567824d2d
18 changed files with 136 additions and 170 deletions

View File

@ -148,6 +148,8 @@ public:
*/ */
virtual void SetTPIDR_EL0(u64 value) = 0; virtual void SetTPIDR_EL0(u64 value) = 0;
virtual void ChangeProcessorId(std::size_t new_core_id) = 0;
virtual void SaveContext(ThreadContext32& ctx) = 0; virtual void SaveContext(ThreadContext32& ctx) = 0;
virtual void SaveContext(ThreadContext64& ctx) = 0; virtual void SaveContext(ThreadContext64& ctx) = 0;
virtual void LoadContext(const ThreadContext32& ctx) = 0; virtual void LoadContext(const ThreadContext32& ctx) = 0;

View File

@ -165,6 +165,10 @@ void ARM_Dynarmic_32::SetTPIDR_EL0(u64 value) {
cp15->uprw = static_cast<u32>(value); cp15->uprw = static_cast<u32>(value);
} }
void ARM_Dynarmic_32::ChangeProcessorId(std::size_t new_core_id) {
// jit->ChangeProcessorId(new_core_id);
}
void ARM_Dynarmic_32::SaveContext(ThreadContext32& ctx) { void ARM_Dynarmic_32::SaveContext(ThreadContext32& ctx) {
Dynarmic::A32::Context context; Dynarmic::A32::Context context;
jit->SaveContext(context); jit->SaveContext(context);

View File

@ -47,6 +47,7 @@ public:
void SetTlsAddress(VAddr address) override; void SetTlsAddress(VAddr address) override;
void SetTPIDR_EL0(u64 value) override; void SetTPIDR_EL0(u64 value) override;
u64 GetTPIDR_EL0() const override; u64 GetTPIDR_EL0() const override;
void ChangeProcessorId(std::size_t new_core_id) override;
void SaveContext(ThreadContext32& ctx) override; void SaveContext(ThreadContext32& ctx) override;
void SaveContext(ThreadContext64& ctx) override {} void SaveContext(ThreadContext64& ctx) override {}

View File

@ -258,6 +258,10 @@ void ARM_Dynarmic_64::SetTPIDR_EL0(u64 value) {
cb->tpidr_el0 = value; cb->tpidr_el0 = value;
} }
void ARM_Dynarmic_64::ChangeProcessorId(std::size_t new_core_id) {
jit->ChangeProcessorId(new_core_id);
}
void ARM_Dynarmic_64::SaveContext(ThreadContext64& ctx) { void ARM_Dynarmic_64::SaveContext(ThreadContext64& ctx) {
ctx.cpu_registers = jit->GetRegisters(); ctx.cpu_registers = jit->GetRegisters();
ctx.sp = jit->GetSP(); ctx.sp = jit->GetSP();

View File

@ -46,6 +46,7 @@ public:
void SetTlsAddress(VAddr address) override; void SetTlsAddress(VAddr address) override;
void SetTPIDR_EL0(u64 value) override; void SetTPIDR_EL0(u64 value) override;
u64 GetTPIDR_EL0() const override; u64 GetTPIDR_EL0() const override;
void ChangeProcessorId(std::size_t new_core_id) override;
void SaveContext(ThreadContext32& ctx) override {} void SaveContext(ThreadContext32& ctx) override {}
void SaveContext(ThreadContext64& ctx) override; void SaveContext(ThreadContext64& ctx) override;

View File

@ -159,6 +159,10 @@ void ARM_Unicorn::SetTPIDR_EL0(u64 value) {
CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value)); CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value));
} }
void ARM_Unicorn::ChangeProcessorId(std::size_t new_core_id) {
core_index = new_core_id;
}
void ARM_Unicorn::Run() { void ARM_Unicorn::Run() {
if (GDBStub::IsServerEnabled()) { if (GDBStub::IsServerEnabled()) {
ExecuteInstructions(std::max(4000000U, 0U)); ExecuteInstructions(std::max(4000000U, 0U));

View File

@ -36,6 +36,7 @@ public:
void SetTlsAddress(VAddr address) override; void SetTlsAddress(VAddr address) override;
void SetTPIDR_EL0(u64 value) override; void SetTPIDR_EL0(u64 value) override;
u64 GetTPIDR_EL0() const override; u64 GetTPIDR_EL0() const override;
void ChangeProcessorId(std::size_t new_core_id) override;
void PrepareReschedule() override; void PrepareReschedule() override;
void ClearExclusiveState() override; void ClearExclusiveState() override;
void ExecuteInstructions(std::size_t num_instructions); void ExecuteInstructions(std::size_t num_instructions);

View File

@ -119,14 +119,6 @@ struct System::Impl {
: kernel{system}, fs_controller{system}, memory{system}, : kernel{system}, fs_controller{system}, memory{system},
cpu_manager{system}, reporter{system}, applet_manager{system} {} cpu_manager{system}, reporter{system}, applet_manager{system} {}
Kernel::PhysicalCore& CurrentPhysicalCore() {
return kernel.CurrentPhysicalCore();
}
Kernel::PhysicalCore& GetPhysicalCore(std::size_t index) {
return kernel.PhysicalCore(index);
}
ResultStatus Run() { ResultStatus Run() {
status = ResultStatus::Success; status = ResultStatus::Success;
@ -443,7 +435,7 @@ bool System::IsPoweredOn() const {
} }
void System::PrepareReschedule() { void System::PrepareReschedule() {
impl->CurrentPhysicalCore().Stop(); //impl->CurrentPhysicalCore().Stop();
} }
void System::PrepareReschedule(const u32 core_index) { void System::PrepareReschedule(const u32 core_index) {
@ -463,11 +455,11 @@ const TelemetrySession& System::TelemetrySession() const {
} }
ARM_Interface& System::CurrentArmInterface() { ARM_Interface& System::CurrentArmInterface() {
return impl->CurrentPhysicalCore().ArmInterface(); return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface();
} }
const ARM_Interface& System::CurrentArmInterface() const { const ARM_Interface& System::CurrentArmInterface() const {
return impl->CurrentPhysicalCore().ArmInterface(); return impl->kernel.CurrentScheduler().GetCurrentThread()->ArmInterface();
} }
std::size_t System::CurrentCoreIndex() const { std::size_t System::CurrentCoreIndex() const {
@ -477,27 +469,27 @@ std::size_t System::CurrentCoreIndex() const {
} }
Kernel::Scheduler& System::CurrentScheduler() { Kernel::Scheduler& System::CurrentScheduler() {
return impl->CurrentPhysicalCore().Scheduler(); return impl->kernel.CurrentScheduler();
} }
const Kernel::Scheduler& System::CurrentScheduler() const { const Kernel::Scheduler& System::CurrentScheduler() const {
return impl->CurrentPhysicalCore().Scheduler(); return impl->kernel.CurrentScheduler();
} }
Kernel::PhysicalCore& System::CurrentPhysicalCore() { Kernel::PhysicalCore& System::CurrentPhysicalCore() {
return impl->CurrentPhysicalCore(); return impl->kernel.CurrentPhysicalCore();
} }
const Kernel::PhysicalCore& System::CurrentPhysicalCore() const { const Kernel::PhysicalCore& System::CurrentPhysicalCore() const {
return impl->CurrentPhysicalCore(); return impl->kernel.CurrentPhysicalCore();
} }
Kernel::Scheduler& System::Scheduler(std::size_t core_index) { Kernel::Scheduler& System::Scheduler(std::size_t core_index) {
return impl->GetPhysicalCore(core_index).Scheduler(); return impl->kernel.Scheduler(core_index);
} }
const Kernel::Scheduler& System::Scheduler(std::size_t core_index) const { const Kernel::Scheduler& System::Scheduler(std::size_t core_index) const {
return impl->GetPhysicalCore(core_index).Scheduler(); return impl->kernel.Scheduler(core_index);
} }
/// Gets the global scheduler /// Gets the global scheduler
@ -527,11 +519,15 @@ const Kernel::Process* System::CurrentProcess() const {
} }
ARM_Interface& System::ArmInterface(std::size_t core_index) { ARM_Interface& System::ArmInterface(std::size_t core_index) {
return impl->GetPhysicalCore(core_index).ArmInterface(); auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread();
ASSERT(thread && !thread->IsHLEThread());
return thread->ArmInterface();
} }
const ARM_Interface& System::ArmInterface(std::size_t core_index) const { const ARM_Interface& System::ArmInterface(std::size_t core_index) const {
return impl->GetPhysicalCore(core_index).ArmInterface(); auto* thread = impl->kernel.Scheduler(core_index).GetCurrentThread();
ASSERT(thread && !thread->IsHLEThread());
return thread->ArmInterface();
} }
ExclusiveMonitor& System::Monitor() { ExclusiveMonitor& System::Monitor() {

View File

@ -28,21 +28,7 @@ CoreManager::CoreManager(System& system, std::size_t core_index)
CoreManager::~CoreManager() = default; CoreManager::~CoreManager() = default;
void CoreManager::RunLoop(bool tight_loop) { void CoreManager::RunLoop(bool tight_loop) {
Reschedule(); /// Deprecated
// 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) {
LOG_TRACE(Core, "Core-{} idling", core_index);
} else {
if (tight_loop) {
physical_core.Run();
} else {
physical_core.Step();
}
}
Reschedule();
} }
void CoreManager::SingleStep() { void CoreManager::SingleStep() {
@ -50,7 +36,7 @@ void CoreManager::SingleStep() {
} }
void CoreManager::PrepareReschedule() { void CoreManager::PrepareReschedule() {
physical_core.Stop(); //physical_core.Stop();
} }
void CoreManager::Reschedule() { void CoreManager::Reschedule() {

View File

@ -129,18 +129,17 @@ void CpuManager::MultiCoreRunGuestThread() {
void CpuManager::MultiCoreRunGuestLoop() { void CpuManager::MultiCoreRunGuestLoop() {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto* thread = kernel.CurrentScheduler().GetCurrentThread(); auto* thread = kernel.CurrentScheduler().GetCurrentThread();
auto host_context = thread->GetHostContext();
host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);
host_context.reset();
while (true) { while (true) {
auto& physical_core = kernel.CurrentPhysicalCore(); auto* physical_core = &kernel.CurrentPhysicalCore();
auto& arm_interface = thread->ArmInterface();
system.EnterDynarmicProfile(); system.EnterDynarmicProfile();
while (!physical_core.IsInterrupted()) { while (!physical_core->IsInterrupted()) {
physical_core.Run(); arm_interface.Run();
physical_core = &kernel.CurrentPhysicalCore();
} }
system.ExitDynarmicProfile(); system.ExitDynarmicProfile();
physical_core.ClearExclusive(); arm_interface.ClearExclusiveState();
auto& scheduler = physical_core.Scheduler(); auto& scheduler = kernel.CurrentScheduler();
scheduler.TryDoContextSwitch(); scheduler.TryDoContextSwitch();
} }
} }
@ -150,7 +149,7 @@ void CpuManager::MultiCoreRunIdleThread() {
while (true) { while (true) {
auto& physical_core = kernel.CurrentPhysicalCore(); auto& physical_core = kernel.CurrentPhysicalCore();
physical_core.Idle(); physical_core.Idle();
auto& scheduler = physical_core.Scheduler(); auto& scheduler = kernel.CurrentScheduler();
scheduler.TryDoContextSwitch(); scheduler.TryDoContextSwitch();
} }
} }
@ -229,14 +228,13 @@ void CpuManager::SingleCoreRunGuestThread() {
void CpuManager::SingleCoreRunGuestLoop() { void CpuManager::SingleCoreRunGuestLoop() {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto* thread = kernel.CurrentScheduler().GetCurrentThread(); auto* thread = kernel.CurrentScheduler().GetCurrentThread();
auto host_context = thread->GetHostContext();
host_context->SetRewindPoint(std::function<void(void*)>(GuestRewindFunction), this);
host_context.reset();
while (true) { while (true) {
auto& physical_core = kernel.CurrentPhysicalCore(); auto* physical_core = &kernel.CurrentPhysicalCore();
auto& arm_interface = thread->ArmInterface();
system.EnterDynarmicProfile(); system.EnterDynarmicProfile();
while (!physical_core.IsInterrupted()) { while (!physical_core->IsInterrupted()) {
physical_core.Run(); arm_interface.Run();
physical_core = &kernel.CurrentPhysicalCore();
preemption_count++; preemption_count++;
if (preemption_count % max_cycle_runs == 0) { if (preemption_count % max_cycle_runs == 0) {
break; break;
@ -246,7 +244,7 @@ void CpuManager::SingleCoreRunGuestLoop() {
thread->SetPhantomMode(true); thread->SetPhantomMode(true);
system.CoreTiming().Advance(); system.CoreTiming().Advance();
thread->SetPhantomMode(false); thread->SetPhantomMode(false);
physical_core.ClearExclusive(); arm_interface.ClearExclusiveState();
PreemptSingleCore(); PreemptSingleCore();
auto& scheduler = kernel.Scheduler(current_core); auto& scheduler = kernel.Scheduler(current_core);
scheduler.TryDoContextSwitch(); scheduler.TryDoContextSwitch();

View File

@ -19,7 +19,6 @@
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#include "core/arm/cpu_interrupt_handler.h" #include "core/arm/cpu_interrupt_handler.h"
#include "core/arm/exclusive_monitor.h" #include "core/arm/exclusive_monitor.h"
#include "core/arm/unicorn/arm_unicorn.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
@ -45,11 +44,6 @@
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h" #include "core/memory.h"
#ifdef ARCHITECTURE_x86_64
#include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/arm_dynarmic_64.h"
#endif
MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70)); MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
namespace Kernel { namespace Kernel {
@ -186,20 +180,8 @@ struct KernelCore::Impl {
exclusive_monitor = exclusive_monitor =
Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES); Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES);
for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { for (std::size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {
#ifdef ARCHITECTURE_x86_64 schedulers[i] = std::make_unique<Kernel::Scheduler>(system, i);
arm_interfaces_32[i] = cores.emplace_back(system, i, *schedulers[i], interrupts[i]);
std::make_unique<Core::ARM_Dynarmic_32>(system, interrupts, *exclusive_monitor, i);
arm_interfaces_64[i] =
std::make_unique<Core::ARM_Dynarmic_64>(system, interrupts, *exclusive_monitor, i);
#else
arm_interfaces_32[i] = std::make_shared<Core::ARM_Unicorn>(
system, interrupts, ARM_Unicorn::Arch::AArch32, i);
arm_interfaces_64[i] = std::make_shared<Core::ARM_Unicorn>(
system, interrupts, ARM_Unicorn::Arch::AArch64, i);
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif
cores.emplace_back(system, i, *exclusive_monitor, interrupts[i], *arm_interfaces_32[i],
*arm_interfaces_64[i]);
} }
} }
@ -268,10 +250,6 @@ struct KernelCore::Impl {
return; return;
} }
for (auto& core : cores) {
core.SetIs64Bit(process->Is64BitProcess());
}
u32 core_id = GetCurrentHostThreadID(); u32 core_id = GetCurrentHostThreadID();
if (core_id < Core::Hardware::NUM_CPU_CORES) { if (core_id < Core::Hardware::NUM_CPU_CORES) {
system.Memory().SetCurrentPageTable(*process, core_id); system.Memory().SetCurrentPageTable(*process, core_id);
@ -429,10 +407,7 @@ struct KernelCore::Impl {
std::array<std::shared_ptr<Thread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{}; std::array<std::shared_ptr<Thread>, Core::Hardware::NUM_CPU_CORES> suspend_threads{};
std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{}; std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES> interrupts{};
std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES> std::array<std::unique_ptr<Kernel::Scheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{};
arm_interfaces_32{};
std::array<std::unique_ptr<Core::ARM_Interface>, Core::Hardware::NUM_CPU_CORES>
arm_interfaces_64{};
bool is_multicore{}; bool is_multicore{};
std::thread::id single_core_thread_id{}; std::thread::id single_core_thread_id{};
@ -497,11 +472,11 @@ const Kernel::GlobalScheduler& KernelCore::GlobalScheduler() const {
} }
Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) { Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) {
return impl->cores[id].Scheduler(); return *impl->schedulers[id];
} }
const Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) const { const Kernel::Scheduler& KernelCore::Scheduler(std::size_t id) const {
return impl->cores[id].Scheduler(); return *impl->schedulers[id];
} }
Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) { Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) {
@ -525,11 +500,23 @@ const Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() const {
} }
Kernel::Scheduler& KernelCore::CurrentScheduler() { Kernel::Scheduler& KernelCore::CurrentScheduler() {
return CurrentPhysicalCore().Scheduler(); u32 core_id = impl->GetCurrentHostThreadID();
ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);
return *impl->schedulers[core_id];
} }
const Kernel::Scheduler& KernelCore::CurrentScheduler() const { const Kernel::Scheduler& KernelCore::CurrentScheduler() const {
return CurrentPhysicalCore().Scheduler(); u32 core_id = impl->GetCurrentHostThreadID();
ASSERT(core_id < Core::Hardware::NUM_CPU_CORES);
return *impl->schedulers[core_id];
}
std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& KernelCore::Interrupts() {
return impl->interrupts;
}
const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& KernelCore::Interrupts() const {
return impl->interrupts;
} }
Kernel::Synchronization& KernelCore::Synchronization() { Kernel::Synchronization& KernelCore::Synchronization() {
@ -557,15 +544,11 @@ const Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() const {
} }
void KernelCore::InvalidateAllInstructionCaches() { void KernelCore::InvalidateAllInstructionCaches() {
for (std::size_t i = 0; i < impl->global_scheduler.CpuCoresCount(); i++) { //TODO: Reimplement, this
PhysicalCore(i).ArmInterface().ClearInstructionCache();
}
} }
void KernelCore::PrepareReschedule(std::size_t id) { void KernelCore::PrepareReschedule(std::size_t id) {
if (id < impl->global_scheduler.CpuCoresCount()) { // TODO: Reimplement, this
impl->cores[id].Stop();
}
} }
void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) { void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {

View File

@ -4,15 +4,17 @@
#pragma once #pragma once
#include <array>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "core/hardware_properties.h"
#include "core/hle/kernel/memory/memory_types.h" #include "core/hle/kernel/memory/memory_types.h"
#include "core/hle/kernel/object.h" #include "core/hle/kernel/object.h"
namespace Core { namespace Core {
struct EmuThreadHandle; class CPUInterruptHandler;
class ExclusiveMonitor; class ExclusiveMonitor;
class System; class System;
} // namespace Core } // namespace Core
@ -144,6 +146,10 @@ public:
const Core::ExclusiveMonitor& GetExclusiveMonitor() const; const Core::ExclusiveMonitor& GetExclusiveMonitor() const;
std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts();
const std::array<Core::CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>& Interrupts() const;
void InvalidateAllInstructionCaches(); void InvalidateAllInstructionCaches();
/// Adds a port to the named port table /// Adds a port to the named port table

View File

@ -20,50 +20,21 @@
namespace Kernel { namespace Kernel {
PhysicalCore::PhysicalCore(Core::System& system, std::size_t id, PhysicalCore::PhysicalCore(Core::System& system, std::size_t id, Kernel::Scheduler& scheduler,
Core::ExclusiveMonitor& exclusive_monitor, Core::CPUInterruptHandler& interrupt_handler)
Core::CPUInterruptHandler& interrupt_handler, : interrupt_handler{interrupt_handler}, core_index{id}, scheduler{scheduler} {
Core::ARM_Interface& arm_interface32,
Core::ARM_Interface& arm_interface64)
: interrupt_handler{interrupt_handler}, core_index{id}, arm_interface_32{arm_interface32},
arm_interface_64{arm_interface64} {
scheduler = std::make_unique<Kernel::Scheduler>(system, core_index);
guard = std::make_unique<Common::SpinLock>(); guard = std::make_unique<Common::SpinLock>();
} }
PhysicalCore::~PhysicalCore() = default; PhysicalCore::~PhysicalCore() = default;
void PhysicalCore::Run() {
arm_interface->Run();
}
void PhysicalCore::ClearExclusive() {
arm_interface->ClearExclusiveState();
}
void PhysicalCore::Step() {
arm_interface->Step();
}
void PhysicalCore::Idle() { void PhysicalCore::Idle() {
interrupt_handler.AwaitInterrupt(); interrupt_handler.AwaitInterrupt();
} }
void PhysicalCore::Stop() {
arm_interface->PrepareReschedule();
}
void PhysicalCore::Shutdown() { void PhysicalCore::Shutdown() {
scheduler->Shutdown(); scheduler.Shutdown();
}
void PhysicalCore::SetIs64Bit(bool is_64_bit) {
if (is_64_bit) {
arm_interface = &arm_interface_64;
} else {
arm_interface = &arm_interface_32;
}
} }
void PhysicalCore::Interrupt() { void PhysicalCore::Interrupt() {

View File

@ -27,9 +27,9 @@ namespace Kernel {
class PhysicalCore { class PhysicalCore {
public: public:
PhysicalCore(Core::System& system, std::size_t id, Core::ExclusiveMonitor& exclusive_monitor, PhysicalCore(Core::System& system, std::size_t id,
Core::CPUInterruptHandler& interrupt_handler, Core::ARM_Interface& arm_interface32, Kernel::Scheduler& scheduler,
Core::ARM_Interface& arm_interface64); Core::CPUInterruptHandler& interrupt_handler);
~PhysicalCore(); ~PhysicalCore();
PhysicalCore(const PhysicalCore&) = delete; PhysicalCore(const PhysicalCore&) = delete;
@ -38,17 +38,7 @@ public:
PhysicalCore(PhysicalCore&&) = default; PhysicalCore(PhysicalCore&&) = default;
PhysicalCore& operator=(PhysicalCore&&) = default; PhysicalCore& operator=(PhysicalCore&&) = default;
/// Execute current jit state
void Run();
/// Clear Exclusive state.
void ClearExclusive();
/// Set this core in IdleState.
void Idle(); void Idle();
/// Execute a single instruction in current jit.
void Step();
/// Stop JIT execution/exit
void Stop();
/// Interrupt this physical core. /// Interrupt this physical core.
void Interrupt(); void Interrupt();
@ -63,14 +53,6 @@ public:
// Shutdown this physical core. // Shutdown this physical core.
void Shutdown(); void Shutdown();
Core::ARM_Interface& ArmInterface() {
return *arm_interface;
}
const Core::ARM_Interface& ArmInterface() const {
return *arm_interface;
}
bool IsMainCore() const { bool IsMainCore() const {
return core_index == 0; return core_index == 0;
} }
@ -84,22 +66,17 @@ public:
} }
Kernel::Scheduler& Scheduler() { Kernel::Scheduler& Scheduler() {
return *scheduler; return scheduler;
} }
const Kernel::Scheduler& Scheduler() const { const Kernel::Scheduler& Scheduler() const {
return *scheduler; return scheduler;
} }
void SetIs64Bit(bool is_64_bit);
private: private:
Core::CPUInterruptHandler& interrupt_handler; Core::CPUInterruptHandler& interrupt_handler;
std::size_t core_index; std::size_t core_index;
Core::ARM_Interface& arm_interface_32; Kernel::Scheduler& scheduler;
Core::ARM_Interface& arm_interface_64;
std::unique_ptr<Kernel::Scheduler> scheduler;
Core::ARM_Interface* arm_interface{};
std::unique_ptr<Common::SpinLock> guard; std::unique_ptr<Common::SpinLock> guard;
}; };

View File

@ -681,15 +681,16 @@ void Scheduler::SwitchContextStep2() {
new_thread->SetWasRunning(false); new_thread->SetWasRunning(false);
auto* const thread_owner_process = current_thread->GetOwnerProcess(); auto* const thread_owner_process = current_thread->GetOwnerProcess();
if (previous_process != thread_owner_process && thread_owner_process != nullptr) { if (thread_owner_process != nullptr) {
system.Kernel().MakeCurrentProcess(thread_owner_process); system.Kernel().MakeCurrentProcess(thread_owner_process);
} }
if (!new_thread->IsHLEThread()) { if (!new_thread->IsHLEThread()) {
auto& cpu_core = system.ArmInterface(core_id); Core::ARM_Interface& cpu_core = new_thread->ArmInterface();
cpu_core.LoadContext(new_thread->GetContext32()); cpu_core.LoadContext(new_thread->GetContext32());
cpu_core.LoadContext(new_thread->GetContext64()); cpu_core.LoadContext(new_thread->GetContext64());
cpu_core.SetTlsAddress(new_thread->GetTLSAddress()); cpu_core.SetTlsAddress(new_thread->GetTLSAddress());
cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0()); cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0());
cpu_core.ChangeProcessorId(this->core_id);
cpu_core.ClearExclusiveState(); cpu_core.ClearExclusiveState();
} }
} }
@ -722,18 +723,15 @@ void Scheduler::SwitchContext() {
} }
previous_thread->SetContinuousOnSVC(false); previous_thread->SetContinuousOnSVC(false);
previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks(); previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
previous_thread->SetIsRunning(false);
if (!previous_thread->IsHLEThread()) { if (!previous_thread->IsHLEThread()) {
auto& cpu_core = system.ArmInterface(core_id); Core::ARM_Interface& cpu_core = previous_thread->ArmInterface();
cpu_core.SaveContext(previous_thread->GetContext32()); cpu_core.SaveContext(previous_thread->GetContext32());
cpu_core.SaveContext(previous_thread->GetContext64()); cpu_core.SaveContext(previous_thread->GetContext64());
// Save the TPIDR_EL0 system register in case it was modified. // Save the TPIDR_EL0 system register in case it was modified.
previous_thread->SetTPIDR_EL0(cpu_core.GetTPIDR_EL0()); previous_thread->SetTPIDR_EL0(cpu_core.GetTPIDR_EL0());
cpu_core.ClearExclusiveState(); cpu_core.ClearExclusiveState();
} }
if (previous_thread->GetStatus() == ThreadStatus::Running) {
previous_thread->SetStatus(ThreadStatus::Ready);
}
previous_thread->SetIsRunning(false);
previous_thread->context_guard.unlock(); previous_thread->context_guard.unlock();
} }

View File

@ -1533,7 +1533,9 @@ static void SleepThread(Core::System& system, s64 nanoseconds) {
} }
if (is_redundant && !system.Kernel().IsMulticore()) { if (is_redundant && !system.Kernel().IsMulticore()) {
system.Kernel().ExitSVCProfile();
system.GetCpuManager().PreemptSingleCore(); system.GetCpuManager().PreemptSingleCore();
system.Kernel().EnterSVCProfile();
} }
} }
@ -2457,9 +2459,6 @@ void Call(Core::System& system, u32 immediate) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
kernel.EnterSVCProfile(); kernel.EnterSVCProfile();
auto* thread = system.CurrentScheduler().GetCurrentThread();
thread->SetContinuousOnSVC(true);
const FunctionDef* info = system.CurrentProcess()->Is64BitProcess() ? GetSVCInfo64(immediate) const FunctionDef* info = system.CurrentProcess()->Is64BitProcess() ? GetSVCInfo64(immediate)
: GetSVCInfo32(immediate); : GetSVCInfo32(immediate);
if (info) { if (info) {
@ -2473,12 +2472,6 @@ void Call(Core::System& system, u32 immediate) {
} }
kernel.ExitSVCProfile(); kernel.ExitSVCProfile();
if (!thread->IsContinuousOnSVC()) {
auto* host_context = thread->GetHostContext().get();
host_context->Rewind();
}
system.EnterDynarmicProfile(); system.EnterDynarmicProfile();
} }

View File

@ -13,6 +13,13 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/thread_queue_list.h" #include "common/thread_queue_list.h"
#include "core/arm/arm_interface.h" #include "core/arm/arm_interface.h"
#ifdef ARCHITECTURE_x86_64
#include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/arm_dynarmic_64.h"
#endif
#include "core/arm/cpu_interrupt_handler.h"
#include "core/arm/exclusive_monitor.h"
#include "core/arm/unicorn/arm_unicorn.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/core_timing_util.h" #include "core/core_timing_util.h"
@ -232,7 +239,27 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy
} }
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
// to initialize the context // to initialize the context
thread->arm_interface.reset();
if ((type_flags & THREADTYPE_HLE) == 0) { if ((type_flags & THREADTYPE_HLE) == 0) {
#ifdef ARCHITECTURE_x86_64
if (owner_process && !owner_process->Is64BitProcess()) {
thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_32>(
system, kernel.Interrupts(), kernel.GetExclusiveMonitor(), processor_id);
} else {
thread->arm_interface = std::make_unique<Core::ARM_Dynarmic_64>(
system, kernel.Interrupts(), kernel.GetExclusiveMonitor(), processor_id);
}
#else
if (owner_process && !owner_process->Is64BitProcess()) {
thread->arm_interface = std::make_shared<Core::ARM_Unicorn>(
system, kernel.Interrupts(), ARM_Unicorn::Arch::AArch32, processor_id);
} else {
thread->arm_interface = std::make_shared<Core::ARM_Unicorn>(
system, kernel.Interrupts(), ARM_Unicorn::Arch::AArch64, processor_id);
}
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif
ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top), ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top),
static_cast<u32>(entry_point), static_cast<u32>(arg)); static_cast<u32>(entry_point), static_cast<u32>(arg));
ResetThreadContext64(thread->context_64, stack_top, entry_point, arg); ResetThreadContext64(thread->context_64, stack_top, entry_point, arg);
@ -276,6 +303,14 @@ VAddr Thread::GetCommandBufferAddress() const {
return GetTLSAddress() + command_header_offset; return GetTLSAddress() + command_header_offset;
} }
Core::ARM_Interface& Thread::ArmInterface() {
return *arm_interface;
}
const Core::ARM_Interface& Thread::ArmInterface() const {
return *arm_interface;
}
void Thread::SetStatus(ThreadStatus new_status) { void Thread::SetStatus(ThreadStatus new_status) {
if (new_status == status) { if (new_status == status) {
return; return;

View File

@ -21,6 +21,7 @@ class Fiber;
} }
namespace Core { namespace Core {
class ARM_Interface;
class System; class System;
} // namespace Core } // namespace Core
@ -271,6 +272,10 @@ public:
void SetSynchronizationResults(SynchronizationObject* object, ResultCode result); void SetSynchronizationResults(SynchronizationObject* object, ResultCode result);
Core::ARM_Interface& ArmInterface();
const Core::ARM_Interface& ArmInterface() const;
SynchronizationObject* GetSignalingObject() const { SynchronizationObject* GetSignalingObject() const {
return signaling_object; return signaling_object;
} }
@ -617,9 +622,10 @@ private:
void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core); void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core);
Common::SpinLock context_guard{};
ThreadContext32 context_32{}; ThreadContext32 context_32{};
ThreadContext64 context_64{}; ThreadContext64 context_64{};
Common::SpinLock context_guard{}; std::unique_ptr<Core::ARM_Interface> arm_interface{};
std::shared_ptr<Common::Fiber> host_context{}; std::shared_ptr<Common::Fiber> host_context{};
u64 thread_id = 0; u64 thread_id = 0;