diff --git a/src/julia_internal.h b/src/julia_internal.h index 72e948f1c0c2f..77757a9bba88b 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -223,6 +223,7 @@ extern volatile size_t profile_bt_size_max; extern volatile size_t profile_bt_size_cur; extern volatile int profile_running; extern volatile int profile_all_tasks; +extern int heartbeat_tid; // Mostly used to ensure we skip this thread in the CPU profiler. XXX: not implemented on Windows // Ensures that we can safely read the `live_tasks`field of every TLS when profiling. // We want to avoid the case that a GC gets interleaved with `jl_profile_task` and shrinks // the `live_tasks` array while we are reading it or frees tasks that are being profiled. diff --git a/src/signals-mach.c b/src/signals-mach.c index 24508a8902d5e..aac03b0d30108 100644 --- a/src/signals-mach.c +++ b/src/signals-mach.c @@ -829,6 +829,10 @@ void *mach_profile_listener(void *arg) for (int idx = nthreads; idx-- > 0; ) { // Stop the threads in random order. int i = randperm[idx]; + // skip heartbeat thread + if (i == heartbeat_tid) { + continue; + } jl_profile_thread_mach(i); } } diff --git a/src/threading.c b/src/threading.c index 962b4da91bb62..502f0d60acfe8 100644 --- a/src/threading.c +++ b/src/threading.c @@ -1085,6 +1085,7 @@ JL_DLLEXPORT int jl_setaffinity(int16_t tid, char *mask, int cpumasksize) { #include volatile int heartbeat_enabled; +int heartbeat_tid; // Mostly used to ensure we skip this thread in the CPU profiler. XXX: not implemented on Windows uv_thread_t heartbeat_uvtid; uv_sem_t heartbeat_on_sem, // jl_heartbeat_enable -> thread heartbeat_off_sem; // thread -> jl_heartbeat_enable @@ -1272,6 +1273,7 @@ void jl_heartbeat_threadfun(void *arg) jl_adopt_thread(); jl_task_t *ct = jl_current_task; jl_ptls_t ptls = ct->ptls; + heartbeat_tid = ptls->tid; // Don't hold up GC, this thread doesn't participate. uint8_t gc_state = jl_gc_safe_enter(ptls);