diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 4ad9cc69d5..2cbbf7010c 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp @@ -104,12 +104,10 @@ void CpuManager::MultiCoreRunGuestThread() { kernel.CurrentScheduler()->OnThreadStart(); while (true) { - auto* physical_core = &kernel.CurrentPhysicalCore(); - while (!physical_core->IsInterrupted()) { - physical_core->RunThread(thread); - physical_core = &kernel.CurrentPhysicalCore(); + auto& physical_core = kernel.CurrentPhysicalCore(); + while (!physical_core.IsInterrupted()) { + physical_core.RunThread(thread); } - HandleInterrupt(); } } diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 5c2b6a4a88..91c6f8e853 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -355,19 +355,8 @@ struct KernelCore::Impl { application_process->Open(); } - /// Sets the host thread ID for the caller. - u32 SetHostThreadId(std::size_t core_id) { - // This should only be called during core init. - ASSERT(tls_data.host_thread_id == UINT8_MAX); - - // The first four slots are reserved for CPU core threads - ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); - tls_data.host_thread_id = u8(core_id); - return tls_data.host_thread_id; - } - /// Gets the host thread ID for the caller - u32 GetHostThreadId() const { + [[nodiscard]] inline u32 GetHostThreadId() const noexcept { return tls_data.host_thread_id; } @@ -386,9 +375,12 @@ struct KernelCore::Impl { } /// Registers a CPU core thread by allocating a host thread ID for it - void RegisterCoreThread(std::size_t core_id) { + void RegisterCoreThread(std::size_t core_id) noexcept { + // This should only be called during core init. + ASSERT(tls_data.host_thread_id == UINT8_MAX); + // The first four slots are reserved for CPU core threads ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); - const auto this_id = SetHostThreadId(core_id); + const auto this_id = tls_data.host_thread_id = u8(core_id); if (!is_multicore) single_core_thread_id = this_id; } @@ -398,7 +390,7 @@ struct KernelCore::Impl { (void)GetHostDummyThread(existing_thread); } - [[nodiscard]] u32 GetCurrentHostThreadID() { + [[nodiscard]] inline u32 GetCurrentHostThreadID() noexcept { auto const this_id = GetHostThreadId(); if (!is_multicore && single_core_thread_id == this_id) return u32(system.GetCpuManager().CurrentCore()); @@ -930,11 +922,7 @@ const Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) const { } size_t KernelCore::CurrentPhysicalCoreIndex() const { - const u32 core_id = impl->GetCurrentHostThreadID(); - if (core_id >= Core::Hardware::NUM_CPU_CORES) { - return Core::Hardware::NUM_CPU_CORES - 1; - } - return core_id; + return impl->GetCurrentHostThreadID(); } Kernel::PhysicalCore& KernelCore::CurrentPhysicalCore() { diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp index e083ee1b0a..59b6c32b16 100644 --- a/src/core/hle/kernel/physical_core.cpp +++ b/src/core/hle/kernel/physical_core.cpp @@ -207,7 +207,7 @@ void PhysicalCore::Idle() { m_on_interrupt.wait(lk, [this] { return m_is_interrupted; }); } -bool PhysicalCore::IsInterrupted() const { +[[noinline]] bool PhysicalCore::IsInterrupted() const { return m_is_interrupted; } diff --git a/src/dynarmic/src/dynarmic/backend/x64/a32_interface.cpp b/src/dynarmic/src/dynarmic/backend/x64/a32_interface.cpp index 5afc41b864..7260542c3b 100644 --- a/src/dynarmic/src/dynarmic/backend/x64/a32_interface.cpp +++ b/src/dynarmic/src/dynarmic/backend/x64/a32_interface.cpp @@ -120,11 +120,13 @@ struct Jit::Impl { } void HaltExecution(HaltReason hr) { - Atomic::Or(&jit_state.halt_reason, static_cast(hr)); + Atomic::Or(&jit_state.halt_reason, u32(hr)); + Atomic::Barrier(); } void ClearHalt(HaltReason hr) { - Atomic::And(&jit_state.halt_reason, ~static_cast(hr)); + Atomic::And(&jit_state.halt_reason, ~u32(hr)); + Atomic::Barrier(); } void ClearExclusiveState() { diff --git a/src/dynarmic/src/dynarmic/backend/x64/a64_interface.cpp b/src/dynarmic/src/dynarmic/backend/x64/a64_interface.cpp index b6240fdb89..e1c29feb48 100644 --- a/src/dynarmic/src/dynarmic/backend/x64/a64_interface.cpp +++ b/src/dynarmic/src/dynarmic/backend/x64/a64_interface.cpp @@ -122,10 +122,12 @@ public: void HaltExecution(HaltReason hr) { Atomic::Or(&jit_state.halt_reason, u32(hr)); + Atomic::Barrier(); } void ClearHalt(HaltReason hr) { Atomic::And(&jit_state.halt_reason, ~u32(hr)); + Atomic::Barrier(); } u64 GetSP() const {