From a5eb11d79f458f947ab28a8b401286ebd8b48c91 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 18 Oct 2020 20:09:39 +0300 Subject: [PATCH] Improve cpu_thread::suspend_all (TSX-FA) Add prefetching of cpu->state fields. --- rpcs3/Emu/CPU/CPUThread.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index fc3e55af0b..57b8c663c2 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -782,6 +782,15 @@ bool cpu_thread::suspend_work::push(cpu_thread* _this, bool cancel_if_not_suspen // First thread to push the work to the workload list pauses all threads and processes it std::lock_guard lock(ctr->cpu_suspend_lock); + // Try to prefetch cpu->state earlier + for_all_cpu([&](cpu_thread* cpu) + { + if (cpu != _this) + { + _m_prefetchw(&cpu->state); + } + }); + // Copy of thread bits decltype(ctr->cpu_copy_bits) copy2{}; @@ -804,8 +813,6 @@ bool cpu_thread::suspend_work::push(cpu_thread* _this, bool cancel_if_not_suspen } }); - busy_wait(500); - while (std::accumulate(std::begin(ctr->cpu_copy_bits), std::end(ctr->cpu_copy_bits), u64{0}, std::bit_or())) { // Check only CPUs which haven't acknowledged their waiting state yet @@ -842,6 +849,13 @@ bool cpu_thread::suspend_work::push(cpu_thread* _this, bool cancel_if_not_suspen while (prev); } + for_all_cpu([&](cpu_thread* cpu) + { + _m_prefetchw(&cpu->state); + }); + + _m_prefetchw(&g_suspend_counter); + // Execute all stored workload for (s32 prio = max_prio; prio >= min_prio; prio--) {