Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip heartbeat thread from CPU profile #201

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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
d-netto marked this conversation as resolved.
Show resolved Hide resolved
// 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.
Expand Down
4 changes: 4 additions & 0 deletions src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,10 @@ static void *signal_listener(void *arg)
for (int idx = nthreads; idx-- > 0; ) {
// Stop the threads in the random order.
int i = randperm[idx];
// skip heartbeat thread
if (i == heartbeat_tid) {
continue;
}
// do backtrace for profiler
if (profile_running) {
jl_profile_thread_unix(i, &signal_context);
Expand Down
2 changes: 2 additions & 0 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ JL_DLLEXPORT int jl_alignment(size_t sz)
#include <time.h>

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
Expand Down Expand Up @@ -1130,6 +1131,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);
Expand Down
Loading