From 213a19c9f36dd1bdf13b4b6f30e3a6c9033771b6 Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Sun, 24 Mar 2024 09:38:26 +0200 Subject: [PATCH] Add logging for CallFromMainThread --- Utilities/Thread.h | 5 +++++ rpcs3/Emu/Cell/SPUThread.cpp | 2 +- rpcs3/Emu/System.cpp | 22 ++++++++++++---------- rpcs3/Emu/System.h | 14 +++++++++++--- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Utilities/Thread.h b/Utilities/Thread.h index afdbc9d934..96b20d6960 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -218,6 +218,11 @@ public: // Get current thread name static std::string get_name() { + if (!g_tls_this_thread) + { + return "not named_thread"; + } + return *g_tls_this_thread->m_tname.load(); } diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 04731f5925..f9d9ab3906 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -5253,7 +5253,7 @@ s64 spu_thread::get_ch_value(u32 ch) } } - const bool seed = (utils::get_tsc() >> 8) % 100; + const usz seed = (utils::get_tsc() >> 8) % 100; #ifdef __linux__ const bool reservation_busy_waiting = false; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 3055711cc5..ed8ee4a077 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -161,17 +161,16 @@ void fmt_class_string::format(std::string& out, u64 arg) }); } -void Emulator::CallFromMainThread(std::function&& func, atomic_t* wake_up, bool track_emu_state, u64 stop_ctr) const +void Emulator::CallFromMainThread(std::function&& func, atomic_t* wake_up, bool track_emu_state, u64 stop_ctr, u32 line, u32 col, const char* file, const char* fun) const { - if (!track_emu_state) + std::function final_func = [this, before = IsStopped(), track_emu_state, thread_name = thread_ctrl::get_name(), src = src_loc{line, col, file, fun} + , count = (stop_ctr == umax ? +m_stop_ctr : stop_ctr), func = std::move(func)] { - m_cb.call_from_main_thread(std::move(func), wake_up); - return; - } + const bool call_it = (!track_emu_state || (count == m_stop_ctr && before == IsStopped())); - std::function final_func = [this, before = IsStopped(), count = (stop_ctr == umax ? +m_stop_ctr : stop_ctr), func = std::move(func)] - { - if (count == m_stop_ctr && before == IsStopped()) + sys_log.trace("Callback from thread '%s' at [%s] is %s", thread_name, src, call_it ? "called" : "skipped"); + + if (call_it) { func(); } @@ -184,14 +183,17 @@ void Emulator::BlockingCallFromMainThread(std::function&& func, u32 line { atomic_t wake_up = 0; - CallFromMainThread(std::move(func), &wake_up); + sys_log.trace("Blocking Callback from thread '%s' at [%s] is queued", thread_ctrl::get_name(), src_loc{line, col, file, fun}); + + CallFromMainThread(std::move(func), &wake_up, true, umax, line, col, file, fun); while (!wake_up) { if (!thread_ctrl::get_current()) { - fmt::throw_exception("Current thread null while calling BlockingCallFromMainThread from %s", src_loc{line, col, file, fun}); + fmt::throw_exception("Calling thread of BlockingCallFromMainThread is not of named_thread<>, calling from %s", src_loc{line, col, file, fun}); } + wake_up.wait(0); } } diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 232dc427f2..2f9dd53163 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -183,7 +183,11 @@ public: } // Call from the GUI thread - void CallFromMainThread(std::function&& func, atomic_t* wake_up = nullptr, bool track_emu_state = true, u64 stop_ctr = umax) const; + void CallFromMainThread(std::function&& func, atomic_t* wake_up = nullptr, bool track_emu_state = true, u64 stop_ctr = umax, + u32 line = __builtin_LINE(), + u32 col = __builtin_COLUMN(), + const char* file = __builtin_FILE(), + const char* fun = __builtin_FUNCTION()) const; // Blocking call from the GUI thread void BlockingCallFromMainThread(std::function&& func, @@ -200,9 +204,13 @@ public: return stop_counter_t{+m_stop_ctr}; } - void CallFromMainThread(std::function&& func, stop_counter_t counter) const + void CallFromMainThread(std::function&& func, stop_counter_t counter, + u32 line = __builtin_LINE(), + u32 col = __builtin_COLUMN(), + const char* file = __builtin_FILE(), + const char* fun = __builtin_FUNCTION()) const { - CallFromMainThread(std::move(func), nullptr, true, static_cast(counter)); + CallFromMainThread(std::move(func), nullptr, true, static_cast(counter), line, col, file, fun); } void PostponeInitCode(std::function&& func)