Skip to content

Commit

Permalink
Add USDTs for task switch and allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed Dec 17, 2021
1 parent 7855e85 commit f729150
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions contrib/bpftrace/rt_all.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bpftrace

BEGIN
{
printf("Tracing Julia Task events... Hit Ctrl-C to end.\n");
}
usdt:usr/lib/libjulia-internal.so:julia:rt__ctx__switch
{
printf("Task switch from %x to %x (with PTLS %x)\n", arg0, arg1, arg2);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__new__task
{
printf("Task %x created by parent %x (with PTLS %x)\n", arg1, arg0, arg2);
}
7 changes: 6 additions & 1 deletion doc/src/devdocs/probes.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ the probe handler.
3. `julia:gc__mark__begin`: Beginning the mark phase
4. `julia:gc__mark_end(scanned_bytes, perm_scanned)`: Mark phase ended
5. `julia:gc__sweep_begin(full)`: Starting sweep
6. `julia:gc__sweep_end()`: Sweep phase finished
6. `julia:gc__sweep_end`: Sweep phase finished
7. `julia:gc__end`: GC is finished, other threads continue work
8. `julia:gc__finalizer`: Initial GC thread has finished running finalizers

### Task runtime probes

1. `julia:rt__ctx__switch(last, next, ptls)`: Switching from task `last` to task `next` on thread associated with PTLS `ptls`.
2. `julia:rt__new__task(parent, child, ptls)`: Task `parent` created task `child` on thread associated with PTLS `ptls`.

#### GC stop-the-world latency

An example `bpftrace` script is given in `contrib/gc_stop_the_world_latency.bt`
Expand Down
4 changes: 4 additions & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,8 @@ uint16_t __gnu_f2h_ieee(float param) JL_NOTSAFEPOINT;
#define JL_PROBE_GC_SWEEP_END() do ; while (0)
#define JL_PROBE_GC_END() do ; while (0)
#define JL_PROBE_GC_FINALIZER() do ; while (0)
#define JL_PROBE_RT_CTX_SWITCH(last, next, ptls) do ; while (0)
#define JL_PROBE_RT_NEW_TASK(parent, child, ptls) do ; while (0)

#define JL_PROBE_GC_BEGIN_ENABLED() (0)
#define JL_PROBE_GC_STOP_THE_WORLD_ENABLED() (0)
Expand All @@ -1541,6 +1543,8 @@ uint16_t __gnu_f2h_ieee(float param) JL_NOTSAFEPOINT;
#define JL_PROBE_GC_SWEEP_END_ENABLED() (0)
#define JL_PROBE_GC_END_ENABLED() (0)
#define JL_PROBE_GC_FINALIZER_ENABLED() (0)
#define JL_PROBE_RT_CTX_SWITCH_ENABLED() (0)
#define JL_PROBE_RT_NEW_TASK_ENABLED() (0)
#endif

#endif
3 changes: 3 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ static void ctx_switch(jl_task_t *lastt)
// none of these locks should be held across a task switch
assert(ptls->locks.len == 0);

JL_PROBE_RT_CTX_SWITCH(lastt, t, ptls);

#ifdef _COMPILER_TSAN_ENABLED_
if (lastt->ctx.tsan_state != __tsan_get_current_fiber()) {
// Something went really wrong - don't even assume that we can
Expand Down Expand Up @@ -753,6 +755,7 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion
{
jl_task_t *ct = jl_current_task;
jl_task_t *t = (jl_task_t*)jl_gc_alloc(ct->ptls, sizeof(jl_task_t), jl_task_type);
JL_PROBE_RT_NEW_TASK(ct, t, ct->ptls);
t->copy_stack = 0;
if (ssize == 0) {
// stack size unspecified; use default
Expand Down
3 changes: 3 additions & 0 deletions src/uprobes.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ provider julia {
probe gc__sweep__end();
probe gc__end();
probe gc__finalizer();

probe rt__ctx__switch(jl_task_t *last, jl_task_t *next, jl_ptls_t ptls);
probe rt__new__task(jl_task_t *parent, jl_task_t *child, jl_ptls_t ptls);
};

#pragma D attributes Evolving/Evolving/Common provider julia provider
Expand Down

0 comments on commit f729150

Please sign in to comment.