diff options
author | Kui-Feng Lee <kuifeng@fb.com> | 2022-09-26 11:49:56 -0700 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2022-09-28 16:30:03 -0700 |
commit | b3e1331eb925a45df1cc5d02a725e5ea70da0e2e (patch) | |
tree | fabc71d53ef9ba11a14bdc8a5a8395ade410299f /tools/testing/selftests/bpf/progs/bpf_iter_task_file.c | |
parent | 2c4fe44fb020f3cce904da2ba9e42bb1c118e8a3 (diff) | |
download | linux-stable-b3e1331eb925a45df1cc5d02a725e5ea70da0e2e.tar.gz linux-stable-b3e1331eb925a45df1cc5d02a725e5ea70da0e2e.tar.bz2 linux-stable-b3e1331eb925a45df1cc5d02a725e5ea70da0e2e.zip |
selftests/bpf: Test parameterized task BPF iterators.
Test iterators of vma, files and tasks.
Ensure the API works appropriately to visit all tasks,
tasks in a process, or a particular task.
Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/bpf/20220926184957.208194-5-kuifeng@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/bpf_iter_task_file.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/bpf_iter_task_file.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_task_file.c b/tools/testing/selftests/bpf/progs/bpf_iter_task_file.c index 6e7b400888fe..b0255080662d 100644 --- a/tools/testing/selftests/bpf/progs/bpf_iter_task_file.c +++ b/tools/testing/selftests/bpf/progs/bpf_iter_task_file.c @@ -7,14 +7,16 @@ char _license[] SEC("license") = "GPL"; int count = 0; int tgid = 0; +int last_tgid = 0; +int unique_tgid_count = 0; SEC("iter/task_file") int dump_task_file(struct bpf_iter__task_file *ctx) { struct seq_file *seq = ctx->meta->seq; struct task_struct *task = ctx->task; - __u32 fd = ctx->fd; struct file *file = ctx->file; + __u32 fd = ctx->fd; if (task == (void *)0 || file == (void *)0) return 0; @@ -27,6 +29,11 @@ int dump_task_file(struct bpf_iter__task_file *ctx) if (tgid == task->tgid && task->tgid != task->pid) count++; + if (last_tgid != task->tgid) { + last_tgid = task->tgid; + unique_tgid_count++; + } + BPF_SEQ_PRINTF(seq, "%8d %8d %8d %lx\n", task->tgid, task->pid, fd, (long)file->f_op); return 0; |