Commit 3c9b1644 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by David S. Miller

samples/bpf: tracepoint example

modify offwaketime to work with sched/sched_switch tracepoint
instead of kprobe into finish_task_switch
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c0766040
...@@ -73,7 +73,7 @@ int waker(struct pt_regs *ctx) ...@@ -73,7 +73,7 @@ int waker(struct pt_regs *ctx)
return 0; return 0;
} }
static inline int update_counts(struct pt_regs *ctx, u32 pid, u64 delta) static inline int update_counts(void *ctx, u32 pid, u64 delta)
{ {
struct key_t key = {}; struct key_t key = {};
struct wokeby_t *woke; struct wokeby_t *woke;
...@@ -100,15 +100,33 @@ static inline int update_counts(struct pt_regs *ctx, u32 pid, u64 delta) ...@@ -100,15 +100,33 @@ static inline int update_counts(struct pt_regs *ctx, u32 pid, u64 delta)
return 0; return 0;
} }
#if 1
/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
struct sched_switch_args {
unsigned long long pad;
char prev_comm[16];
int prev_pid;
int prev_prio;
long long prev_state;
char next_comm[16];
int next_pid;
int next_prio;
};
SEC("tracepoint/sched/sched_switch")
int oncpu(struct sched_switch_args *ctx)
{
/* record previous thread sleep time */
u32 pid = ctx->prev_pid;
#else
SEC("kprobe/finish_task_switch") SEC("kprobe/finish_task_switch")
int oncpu(struct pt_regs *ctx) int oncpu(struct pt_regs *ctx)
{ {
struct task_struct *p = (void *) PT_REGS_PARM1(ctx); struct task_struct *p = (void *) PT_REGS_PARM1(ctx);
/* record previous thread sleep time */
u32 pid = _(p->pid);
#endif
u64 delta, ts, *tsp; u64 delta, ts, *tsp;
u32 pid;
/* record previous thread sleep time */
pid = _(p->pid);
ts = bpf_ktime_get_ns(); ts = bpf_ktime_get_ns();
bpf_map_update_elem(&start, &pid, &ts, BPF_ANY); bpf_map_update_elem(&start, &pid, &ts, BPF_ANY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment