From 95dbcf2fd752b4a87ef0a96398aa4f41234d6456 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 29 Oct 2020 05:09:21 +0300 Subject: [PATCH] Logs: add callback for cpu_thread to set cpu_flag::wait May improve waiting time in critical suspend_all ops. --- rpcs3/Emu/CPU/CPUThread.cpp | 24 ++++++++++++++++++++++++ rpcs3/util/logs.cpp | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index b7f3f16f02..30206ada27 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -24,6 +24,8 @@ LOG_CHANNEL(sys_log, "SYS"); static thread_local u64 s_tls_thread_slot = -1; +extern thread_local void(*g_tls_log_control)(const char* fmt, u64 progress); + template <> void fmt_class_string::format(std::string& out, u64 arg) { @@ -469,6 +471,26 @@ void cpu_thread::operator()() } }); + g_tls_log_control = [](const char* fmt, u64 progress) + { + static thread_local bool wait_set = false; + + cpu_thread* _cpu = get_current_cpu_thread(); + + if (progress == 0 && !(_cpu->state & cpu_flag::wait)) + { + _cpu->state += cpu_flag::wait + cpu_flag::temp; + wait_set = true; + return; + } + + if (progress == umax && std::exchange(wait_set, false)) + { + verify(HERE), !_cpu->check_state(); + return; + } + }; + static thread_local struct thread_cleanup_t { cpu_thread* _this; @@ -494,6 +516,8 @@ void cpu_thread::operator()() atomic_storage_futex::set_notify_callback(nullptr); + g_tls_log_control = [](const char*, u64){}; + g_fxo->get()->remove(_this, s_tls_thread_slot); _this = nullptr; diff --git a/rpcs3/util/logs.cpp b/rpcs3/util/logs.cpp index 2c87866054..5f6ec3ae69 100644 --- a/rpcs3/util/logs.cpp +++ b/rpcs3/util/logs.cpp @@ -31,6 +31,9 @@ static std::string empty_string() // Thread-specific log prefix provider thread_local std::string(*g_tls_log_prefix)() = &empty_string; +// Another thread-specific callback +thread_local void(*g_tls_log_control)(const char* fmt, u64 progress) = [](const char*, u64){}; + template<> void fmt_class_string::format(std::string& out, u64 arg) { @@ -314,6 +317,9 @@ void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, ...) co // Get timestamp const u64 stamp = get_stamp(); + // Notify start operation + g_tls_log_control(fmt, 0); + // Get text, extract va_args /*constinit thread_local*/ std::string text; /*constinit thread_local*/ std::basic_string args; @@ -361,6 +367,9 @@ void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, ...) co lis->log(stamp, *this, prefix, text); lis = lis->m_next; } + + // Notify end operation + g_tls_log_control(fmt, -1); } logs::file_writer::file_writer(const std::string& name, u64 max_size)