From 3888b0429c25a1ad90abeeb28d9f802439a0e3ad Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 12 Nov 2020 05:52:22 +0300 Subject: [PATCH] atomic.cpp: print some stats on stop --- rpcs3/Emu/System.cpp | 34 ++++++++++++++++++++++++++++++++++ rpcs3/util/atomic.cpp | 17 +++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 9026bed07d..7e0943e9e8 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -86,6 +86,11 @@ namespace struct progress_dialog_server; } +namespace atomic_wait +{ + extern void parse_hashtable(bool(*cb)(u64 id, u16 refs, u32 ptr, u32 stats)); +} + template<> void fmt_class_string::format(std::string& out, u64 arg) { @@ -1875,6 +1880,35 @@ void Emulator::Stop(bool restart) jit_runtime::finalize(); + static u64 aw_refs = 0; + static u64 aw_colm = 0; + static u64 aw_colc = 0; + static u64 aw_used = 0; + + aw_refs = 0; + aw_colm = 0; + aw_colc = 0; + aw_used = 0; + + atomic_wait::parse_hashtable([](u64 id, u16 refs, u32 ptr, u32 stats) -> bool + { + aw_refs += refs; + aw_used += ptr != 0; + + stats = (stats & 0xaaaaaaaa) / 2 + (stats & 0x55555555); + stats = (stats & 0xcccccccc) / 4 + (stats & 0x33333333); + stats = (stats & 0xf0f0f0f0) / 16 + (stats & 0xf0f0f0f); + stats = (stats & 0xff00ff00) / 256 + (stats & 0xff00ff); + stats = (stats >> 16) + (stats & 0xffff); + + aw_colm = std::max(aw_colm, stats); + aw_colc += stats != 0; + + return false; + }); + + sys_log.notice("Atomic wait hashtable stats: [in_use=%u, used=%u, max_collision_weight=%u, total_collisions=%u]", aw_refs, aw_used, aw_colm, aw_colc); + if (restart) { // Reload with prior configs. diff --git a/rpcs3/util/atomic.cpp b/rpcs3/util/atomic.cpp index 341f82bd71..a3bb983507 100644 --- a/rpcs3/util/atomic.cpp +++ b/rpcs3/util/atomic.cpp @@ -1556,3 +1556,20 @@ atomic_wait_engine::notify_all(const void* data, u32 size, __m128i mask, __m128i s_tls_notify_cb(data, -1); } + +namespace atomic_wait +{ + extern void parse_hashtable(bool(*cb)(u64 id, u16 refs, u32 ptr, u32 stats)) + { + for (u64 i = 0; i < s_hashtable_size; i++) + { + const auto root = &s_hashtable[i]; + const auto slot = root->bits.load(); + + if (cb(i, static_cast(slot.ref), root->first_ptr.load(), root->diff_lz | root->diff_tz | root->diff_pop)) + { + break; + } + } + } +}