From 7371388e1d09e401783c42c95ce1013e5f67de33 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Fri, 17 Oct 2025 12:15:53 +1300 Subject: [PATCH] Add timing stats for IdString garbage collection --- kernel/driver.cc | 2 ++ kernel/register.cc | 5 +++++ kernel/register.h | 2 ++ kernel/rtlil.cc | 8 ++++++++ kernel/rtlil.h | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/kernel/driver.cc b/kernel/driver.cc index 795fd9fc5..eae9c5276 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -709,6 +709,8 @@ int main(int argc, char **argv) total_ns += it.second->runtime_ns + 1; timedat.insert(make_tuple(it.second->runtime_ns + 1, it.second->call_counter, it.first)); } + timedat.insert(make_tuple(RTLIL::OwningIdString::garbage_collection_ns() + 1, + RTLIL::OwningIdString::garbage_collection_count(), "id_gc")); if (timing_details) { diff --git a/kernel/register.cc b/kernel/register.cc index 1f8e4a9a5..3f5aa49ca 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -129,6 +129,11 @@ void Pass::post_execute(Pass::pre_post_exec_state_t state) int64_t time_ns = PerformanceTimer::query() - state.begin_ns; runtime_ns += time_ns; current_pass = state.parent_pass; + subtract_from_current_runtime_ns(time_ns); +} + +void Pass::subtract_from_current_runtime_ns(int64_t time_ns) +{ if (current_pass) current_pass->runtime_ns -= time_ns; } diff --git a/kernel/register.h b/kernel/register.h index b9c709dc1..78f9b430d 100644 --- a/kernel/register.h +++ b/kernel/register.h @@ -95,6 +95,8 @@ struct Pass bool experimental_flag = false; bool internal_flag = false; + static void subtract_from_current_runtime_ns(int64_t time_ns); + void experimental() { experimental_flag = true; } diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index b6cb8fec5..bcb10fad2 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -243,8 +243,12 @@ struct IdStringCollector { std::unordered_set live; }; +int64_t RTLIL::OwningIdString::gc_ns; +int RTLIL::OwningIdString::gc_count; + void RTLIL::OwningIdString::collect_garbage() { + int64_t start = PerformanceTimer::query(); #ifndef YOSYS_NO_IDS_REFCNT IdStringCollector collector; for (auto &[idx, design] : *RTLIL::Design::get_all_designs()) { @@ -288,6 +292,10 @@ void RTLIL::OwningIdString::collect_garbage() it = global_autoidx_id_prefix_storage_.erase(it); } #endif + int64_t time_ns = PerformanceTimer::query() - start; + Pass::subtract_from_current_runtime_ns(time_ns); + gc_ns += time_ns; + ++gc_count; } dict RTLIL::constpad; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 1d07b6296..ff98ee500 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -578,6 +578,8 @@ struct RTLIL::OwningIdString : public RTLIL::IdString { // Collect all non-owning references. static void collect_garbage(); + static int64_t garbage_collection_ns() { return gc_ns; } + static int garbage_collection_count() { return gc_count; } // Used by the ID() macro to create an IdString with no destructor whose string will // never be released. If ID() creates a closure-static `OwningIdString` then @@ -589,6 +591,9 @@ struct RTLIL::OwningIdString : public RTLIL::IdString { return result; } private: + static int64_t gc_ns; + static int gc_count; + void get_reference() { get_reference(index_);