iovisor / iovisor/bcc

helper for per-task variables

Open
#193 0 comments 0 reactions 1 assignee Claimed by @4ast View on GitHub
enhancement prio:medium
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

It will likely be common to store data with the current on-CPU task (ie, PID/thread), for example, timestamps, arguments, etc., that are then later retrieved by another event for the same task.

Eg, the vfsreadlat.c example does this to store a timestamp from function entry to return:

``` C
struct key_t {
u32 pid;
};

BPF_HASH(start, struct key_t);

int do_entry(struct pt_regs *ctx)
{
struct key_t key = {};
u64 ts, *val;

key.pid = bpf_get_current_pid_tgid();
ts = bpf_ktime_get_ns();
start.update(&key, &ts);
return 0;
}

int do_return(struct pt_regs *ctx)
{
struct key_t key = {};
u64 *tsp, delta;

key.pid = bpf_get_current_pid_tgid();
tsp = start.lookup(&key);
[...]
```

Imagine something like:

``` C
BPF_TASK_VAR(start, u64);

void do_entry(struct pt_regs *ctx)
{
start.set(bpf_ktime_get_ns());
}

void do_return(struct pt_regs *ctx)
{
u64 *tsp, delta;

tsp = start.get();
[...]
```

Or better ("start = bpf_ktime_get_ns()", etc).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.