diff options
author | Yonghong Song <yhs@fb.com> | 2020-05-09 10:59:17 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-05-09 17:05:27 -0700 |
commit | c09add2fbc5aece00a5b54a48ce39fd4e3284d87 (patch) | |
tree | 221ce4b3c6ae0308ad18857624954760580abdf5 /tools/lib/bpf/bpf_tracing.h | |
parent | 9c5f8a1008a121e4c6b24af211034e24b0b63081 (diff) | |
download | linux-c09add2fbc5aece00a5b54a48ce39fd4e3284d87.tar.gz linux-c09add2fbc5aece00a5b54a48ce39fd4e3284d87.tar.bz2 linux-c09add2fbc5aece00a5b54a48ce39fd4e3284d87.zip |
tools/libbpf: Add bpf_iter support
Two new libbpf APIs are added to support bpf_iter:
- bpf_program__attach_iter
Given a bpf program and additional parameters, which is
none now, returns a bpf_link.
- bpf_iter_create
syscall level API to create a bpf iterator.
The macro BPF_SEQ_PRINTF are also introduced. The format
looks like:
BPF_SEQ_PRINTF(seq, "task id %d\n", pid);
This macro can help bpf program writers with
nicer bpf_seq_printf syntax similar to the kernel one.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200509175917.2476936-1-yhs@fb.com
Diffstat (limited to 'tools/lib/bpf/bpf_tracing.h')
-rw-r--r-- | tools/lib/bpf/bpf_tracing.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index f3f3c3fb98cb..cf97d07692b4 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -413,4 +413,20 @@ typeof(name(0)) name(struct pt_regs *ctx) \ } \ static __always_inline typeof(name(0)) ____##name(struct pt_regs *ctx, ##args) +/* + * BPF_SEQ_PRINTF to wrap bpf_seq_printf to-be-printed values + * in a structure. + */ +#define BPF_SEQ_PRINTF(seq, fmt, args...) \ + ({ \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \ + static const char ___fmt[] = fmt; \ + unsigned long long ___param[] = { args }; \ + _Pragma("GCC diagnostic pop") \ + int ___ret = bpf_seq_printf(seq, ___fmt, sizeof(___fmt), \ + ___param, sizeof(___param)); \ + ___ret; \ + }) + #endif |