bpftrace icon indicating copy to clipboard operation
bpftrace copied to clipboard

thread-local storage

Open brendangregg opened this issue 6 years ago • 0 comments

Variables keyed by thread ID will commonly used, and maybe this should be a new data type. Eg, the @start[tid] in this example:

kprobe:sys_read
{
  @start[tid] = nsecs;
}

kretprobe:sys_read / @start[tid] /
{
  @times = quantize(nsecs - @start[tid]);
  @start[tid] = delete();
}

If this became a new data type, then I'd consider one of two things for cleanup:

  • When thread-local variables are used, bpftrace adds on a kprobe/tracepoint for thread destruction, with code to clean up all those variables. I don't think we should make people do that manually every time, it should be automatic.
  • Kernel support, with appropriate cleanup: eg, a new BPF_MAP_TYPE_PERTHREAD_HASH (that'd be a question for @4ast).

brendangregg avatar Mar 10 '18 20:03 brendangregg