From 3b79815b2c7433e9242d50334ebf065d5d9c4517 Mon Sep 17 00:00:00 2001 From: K Pamnany Date: Tue, 14 Oct 2025 09:25:44 -0400 Subject: [PATCH] Add `wake_all_threads_time` metric Accumulates the time spent in the all-threads wakeup loop in `jl_wakeup_thread`. --- src/partr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/partr.c b/src/partr.c index 33631dc83c05a..d3b81fbaa36e3 100644 --- a/src/partr.c +++ b/src/partr.c @@ -279,6 +279,13 @@ static void wake_libuv(void) JL_NOTSAFEPOINT JULIA_DEBUG_SLEEPWAKE( io_wakeup_leave = cycleclock() ); } +_Atomic(uint64_t) wake_all_threads_time = 0; + +JL_DLLEXPORT uint64_t jl_get_wake_all_threads_time(void) +{ + return jl_atomic_load_relaxed(&wake_all_threads_time); +} + /* ensure thread tid is awake if necessary */ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) JL_NOTSAFEPOINT { @@ -317,12 +324,15 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) JL_NOTSAFEPOINT // something added to the multi-queue: notify all threads // in the future, we might want to instead wake some fraction of threads, // and let each of those wake additional threads if they find work + uint64_t tw = jl_hrtime(); int anysleep = 0; int nthreads = jl_atomic_load_acquire(&jl_n_threads); for (tid = 0; tid < nthreads; tid++) { if (tid != self) anysleep |= wake_thread(tid); } + tw = jl_hrtime() - tw; + jl_atomic_fetch_add_relaxed(&wake_all_threads_time, tw); // check if we need to notify uv_run too if (uvlock != ct && anysleep) { jl_fence();