aboutsummaryrefslogtreecommitdiffstats
path: root/samples/bpf
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@fb.com>2016-04-06 21:43:30 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-07 21:04:27 -0400
commit3c9b16448cf6924c203e3c01696c87fcbfb71fc6 (patch)
treed4c9d8fbef001900eba025c6f864af4b484d8ba0 /samples/bpf
parentc07660409ec954403776200cec1dd04b2db851f8 (diff)
samples/bpf: tracepoint example
modify offwaketime to work with sched/sched_switch tracepoint instead of kprobe into finish_task_switch Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf')
-rw-r--r--samples/bpf/offwaketime_kern.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c
index c0aa5a9b9c48..983629a31c79 100644
--- a/samples/bpf/offwaketime_kern.c
+++ b/samples/bpf/offwaketime_kern.c
@@ -73,7 +73,7 @@ int waker(struct pt_regs *ctx)
73 return 0; 73 return 0;
74} 74}
75 75
76static inline int update_counts(struct pt_regs *ctx, u32 pid, u64 delta) 76static inline int update_counts(void *ctx, u32 pid, u64 delta)
77{ 77{
78 struct key_t key = {}; 78 struct key_t key = {};
79 struct wokeby_t *woke; 79 struct wokeby_t *woke;
@@ -100,15 +100,33 @@ static inline int update_counts(struct pt_regs *ctx, u32 pid, u64 delta)
100 return 0; 100 return 0;
101} 101}
102 102
103#if 1
104/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
105struct sched_switch_args {
106 unsigned long long pad;
107 char prev_comm[16];
108 int prev_pid;
109 int prev_prio;
110 long long prev_state;
111 char next_comm[16];
112 int next_pid;
113 int next_prio;
114};
115SEC("tracepoint/sched/sched_switch")
116int oncpu(struct sched_switch_args *ctx)
117{
118 /* record previous thread sleep time */
119 u32 pid = ctx->prev_pid;
120#else
103SEC("kprobe/finish_task_switch") 121SEC("kprobe/finish_task_switch")
104int oncpu(struct pt_regs *ctx) 122int oncpu(struct pt_regs *ctx)
105{ 123{
106 struct task_struct *p = (void *) PT_REGS_PARM1(ctx); 124 struct task_struct *p = (void *) PT_REGS_PARM1(ctx);
125 /* record previous thread sleep time */
126 u32 pid = _(p->pid);
127#endif
107 u64 delta, ts, *tsp; 128 u64 delta, ts, *tsp;
108 u32 pid;
109 129
110 /* record previous thread sleep time */
111 pid = _(p->pid);
112 ts = bpf_ktime_get_ns(); 130 ts = bpf_ktime_get_ns();
113 bpf_map_update_elem(&start, &pid, &ts, BPF_ANY); 131 bpf_map_update_elem(&start, &pid, &ts, BPF_ANY);
114 132