Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add USDTs for multiq insert/deletemin
Browse files Browse the repository at this point in the history
Co-authored-by: Takafumi Arakaki <[email protected]>
jpsamaroo and tkf committed Dec 19, 2021
1 parent c569075 commit 7ec1f00
Showing 4 changed files with 60 additions and 2 deletions.
32 changes: 32 additions & 0 deletions contrib/bpftrace/rt_all.bt
Original file line number Diff line number Diff line change
@@ -7,11 +7,13 @@ BEGIN

usdt:usr/lib/libjulia-internal.so:julia:rt__run__task
{
@resume[ustack] = count();
printf("Task running: %x (with PTLS %x)\n", arg0, arg1);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__pause__task
{
@pause[ustack] = count();
printf("Task pausing: %x (with PTLS %x)\n", arg0, arg1);
}

@@ -29,3 +31,33 @@ usdt:usr/lib/libjulia-internal.so:julia:rt__finish__process__events
{
printf("Task processed libuv events: %x\n", arg0);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__insert__success
{
printf("Multiq insert success: PTLS %x\n", arg0);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__insert__full
{
printf("Multiq insert failed (full): PTLS %x\n", arg0);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__deletemin__trylock_success
{
printf("Multiq deletemin lock acquired: PTLS %x, heap %d\n", arg0, arg1);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__deletemin__trylock_failed
{
printf("Multiq deletemin lock busy: PTLS %x\n", arg0);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__deletemin__success
{
printf("Multiq deletemin success: PTLS %x got task %x\n", arg0, arg1);
}

usdt:usr/lib/libjulia-internal.so:julia:rt__multiq__deletemin__emptyish
{
printf("Multiq deletemin failed (empty): PTLS %x\n", arg0);
}
12 changes: 12 additions & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
@@ -1537,6 +1537,12 @@ uint16_t __gnu_f2h_ieee(float param) JL_NOTSAFEPOINT;
#define JL_PROBE_RT_NEW_TASK(parent, child, ptls) do ; while (0)
#define JL_PROBE_RT_START_PROCESS_EVENTS(task) do ; while (0)
#define JL_PROBE_RT_FINISH_PROCESS_EVENTS(task) do ; while (0)
#define JL_PROBE_RT_MULTIQ_INSERT_SUCCESS(ptls) do ; while (0)
#define JL_PROBE_RT_MULTIQ_INSERT_FULL(ptls) do ; while (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_SUCCESS(ptls, heap) do ; while (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_FAILED(ptls) do ; while (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_SUCCESS(ptls, task) do ; while (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_EMPTYISH(ptls) do ; while (0)

#define JL_PROBE_GC_BEGIN_ENABLED() (0)
#define JL_PROBE_GC_STOP_THE_WORLD_ENABLED() (0)
@@ -1551,6 +1557,12 @@ uint16_t __gnu_f2h_ieee(float param) JL_NOTSAFEPOINT;
#define JL_PROBE_RT_NEW_TASK_ENABLED() (0)
#define JL_PROBE_RT_START_PROCESS_EVENTS_ENABLED() (0)
#define JL_PROBE_RT_FINISH_PROCESS_EVENTS_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_INSERT_SUCCESS_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_INSERT_FULL_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_SUCCESS_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_FAILED_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_SUCCESS_ENABLED() (0)
#define JL_PROBE_RT_MULTIQ_DELETEMIN_EMPTYISH_ENABLED() (0)
#endif

#endif
12 changes: 10 additions & 2 deletions src/partr.c
Original file line number Diff line number Diff line change
@@ -142,6 +142,7 @@ static inline int multiq_insert(jl_task_t *task, int16_t priority)
if (jl_atomic_load_relaxed(&heaps[rn].ntasks) >= tasks_per_heap) {
uv_mutex_unlock(&heaps[rn].lock);
// multiq insertion failed, increase #tasks per heap
JL_PROBE_RT_MULTIQ_INSERT_FULL(ptls);
return -1;
}

@@ -154,6 +155,7 @@ static inline int multiq_insert(jl_task_t *task, int16_t priority)
jl_atomic_store_relaxed(&heaps[rn].prio, task->prio);
uv_mutex_unlock(&heaps[rn].lock);

JL_PROBE_RT_MULTIQ_INSERT_SUCCESS(ptls);
return 0;
}

@@ -179,17 +181,22 @@ static inline jl_task_t *multiq_deletemin(void)
else if (prio1 == prio2 && prio1 == INT16_MAX)
continue;
if (uv_mutex_trylock(&heaps[rn1].lock) == 0) {
if (prio1 == jl_atomic_load_relaxed(&heaps[rn1].prio))
if (prio1 == jl_atomic_load_relaxed(&heaps[rn1].prio)) {
JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_SUCCESS(ptls, i);
break;
}
uv_mutex_unlock(&heaps[rn1].lock);
}
}
if (i == heap_p)
if (i == heap_p) {
JL_PROBE_RT_MULTIQ_DELETEMIN_EMPTYISH(ptls);
return NULL;
}

task = heaps[rn1].tasks[0];
if (!jl_set_task_tid(task, ptls->tid)) {
uv_mutex_unlock(&heaps[rn1].lock);
JL_PROBE_RT_MULTIQ_DELETEMIN_TRYLOCK_FAILED(ptls);
goto retry;
}
int32_t ntasks = jl_atomic_load_relaxed(&heaps[rn1].ntasks) - 1;
@@ -204,6 +211,7 @@ static inline jl_task_t *multiq_deletemin(void)
jl_atomic_store_relaxed(&heaps[rn1].prio, prio1);
uv_mutex_unlock(&heaps[rn1].lock);

JL_PROBE_RT_MULTIQ_DELETEMIN_SUCCESS(ptls, task);
return task;
}

6 changes: 6 additions & 0 deletions src/uprobes.d
Original file line number Diff line number Diff line change
@@ -15,6 +15,12 @@ provider julia {
probe rt__new__task(jl_task_t *parent, jl_task_t *child, jl_ptls_t ptls);
probe rt__start__process__events(jl_task_t *task);
probe rt__finish__process__events(jl_task_t *task);
probe rt__multiq__insert__success(jl_ptls_t ptls);
probe rt__multiq__insert__full(jl_ptls_t ptls);
probe rt__multiq__deletemin__trylock_success(jl_ptls_t ptls, int32_t heap);
probe rt__multiq__deletemin__trylock_failed(jl_ptls_t ptls);
probe rt__multiq__deletemin__success(jl_ptls_t ptls, jl_task_t task);
probe rt__multiq__deletemin__emptyish(jl_ptls_t ptls);
};

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

0 comments on commit 7ec1f00

Please sign in to comment.