diff options
author | Daniel T. Lee <danieltimlee@gmail.com> | 2023-08-18 11:01:12 +0200 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-08-22 00:39:09 +0200 |
commit | e7e6c774f5d40244444f23b8c49dac2ded158d8c (patch) | |
tree | a6b348adf3883cbaaed55b2a273dd62b2eb416bf /samples/bpf/offwaketime_kern.c | |
parent | samples/bpf: fix warning with ignored-attributes (diff) | |
download | linux-e7e6c774f5d40244444f23b8c49dac2ded158d8c.tar.xz linux-e7e6c774f5d40244444f23b8c49dac2ded158d8c.zip |
samples/bpf: convert to vmlinux.h with tracing programs
This commit replaces separate headers with a single vmlinux.h to
tracing programs. Thanks to that, we no longer need to define the
argument structure for tracing programs directly. For example, argument
for the sched_switch tracpepoint (sched_switch_args) can be replaced
with the vmlinux.h provided trace_event_raw_sched_switch.
Additional defines have been added to the BPF program either directly
or through the inclusion of net_shared.h. Defined values are
PERF_MAX_STACK_DEPTH, IFNAMSIZ constants and __stringify() macro. This
change enables the BPF program to access internal structures with BTF
generated "vmlinux.h" header.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230818090119.477441-3-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/offwaketime_kern.c')
-rw-r--r-- | samples/bpf/offwaketime_kern.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 23f12b47e9e5..8e5105811178 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -4,14 +4,15 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include <uapi/linux/bpf.h> -#include <uapi/linux/ptrace.h> -#include <uapi/linux/perf_event.h> +#include "vmlinux.h" #include <linux/version.h> -#include <linux/sched.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> +#ifndef PERF_MAX_STACK_DEPTH +#define PERF_MAX_STACK_DEPTH 127 +#endif + #define _(P) \ ({ \ typeof(P) val; \ @@ -111,18 +112,8 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta) #if 1 /* taken from /sys/kernel/tracing/events/sched/sched_switch/format */ -struct sched_switch_args { - unsigned long long pad; - char prev_comm[TASK_COMM_LEN]; - int prev_pid; - int prev_prio; - long long prev_state; - char next_comm[TASK_COMM_LEN]; - int next_pid; - int next_prio; -}; SEC("tracepoint/sched/sched_switch") -int oncpu(struct sched_switch_args *ctx) +int oncpu(struct trace_event_raw_sched_switch *ctx) { /* record previous thread sleep time */ u32 pid = ctx->prev_pid; |