Message ID | 20230625021816.1734617-1-liu.yun@linux.dev (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | libbpf: kprobe.multi: feedback function counts by kernel traced | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
bpf/vmtest-bpf-next-PR | success | PR summary |
bpf/vmtest-bpf-next-VM_Test-8 | fail | Logs for test_maps on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for ShellCheck |
bpf/vmtest-bpf-next-VM_Test-6 | success | Logs for set-matrix |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for build for aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-4 | success | Logs for build for x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-5 | success | Logs for build for x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-3 | success | Logs for build for s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-9 | success | Logs for test_maps on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-19 | success | Logs for test_progs_no_alu32_parallel on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-20 | success | Logs for test_progs_no_alu32_parallel on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-22 | success | Logs for test_progs_parallel on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-25 | success | Logs for test_verifier on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-27 | success | Logs for test_verifier on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-29 | success | Logs for veristat |
bpf/vmtest-bpf-next-VM_Test-7 | success | Logs for test_maps on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-10 | success | Logs for test_maps on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-11 | success | Logs for test_progs on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-13 | fail | Logs for test_progs on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-14 | fail | Logs for test_progs on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-15 | success | Logs for test_progs_no_alu32 on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-17 | fail | Logs for test_progs_no_alu32 on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-18 | fail | Logs for test_progs_no_alu32 on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-21 | success | Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-23 | success | Logs for test_progs_parallel on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-24 | success | Logs for test_progs_parallel on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-28 | success | Logs for test_verifier on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-26 | success | Logs for test_verifier on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-16 | success | Logs for test_progs_no_alu32 on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-12 | success | Logs for test_progs on s390x with gcc |
On Sun, Jun 25, 2023 at 10:18:16AM +0800, Jackie Liu wrote: > From: Jackie Liu <liuyun01@kylinos.cn> > > When tracking functions through kprobe.multi, the number of tracked > functions cannot be directly obtained. Sometimes in order to calculate > this value, it is necessary to recalculate according to the pattern in > the program. This is unnecessary. It is calculated by libbpf feedback > through opts.cnt value, which can save resources. Example at [1]. > > [1] https://github.com/JackieLiu1/ketones/blob/master/src/funccount/funccount.c#L317 > > Signed-off-by: Jackie Liu <liuyun01@kylinos.cn> > --- > tools/lib/bpf/libbpf.c | 3 ++- > tools/lib/bpf/libbpf.h | 2 +- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index fca5d2e412c5..ed3f1202c570 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -10506,7 +10506,7 @@ static void kprobe_multi_resolve_reinit(struct kprobe_multi_resolve *res) > struct bpf_link * > bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > const char *pattern, > - const struct bpf_kprobe_multi_opts *opts) > + struct bpf_kprobe_multi_opts *opts) > { > LIBBPF_OPTS(bpf_link_create_opts, lopts); > struct kprobe_multi_resolve res = { > @@ -10582,6 +10582,7 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > } > link->fd = link_fd; > free(res.addrs); > + OPTS_SET(opts, cnt, res.cnt); hum I'm not sure it's good idea to use opts for output values there's ongoing patchset adding possibility to get this info/value via BPF_OBJ_GET_INFO_BY_FD syscall [1] jirka [1] https://lore.kernel.org/bpf/20230623141546.3751-1-laoar.shao@gmail.com/ > return link; > > error: > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index 0b7362397ea3..f860dacc6add 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -527,7 +527,7 @@ struct bpf_kprobe_multi_opts { > LIBBPF_API struct bpf_link * > bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > const char *pattern, > - const struct bpf_kprobe_multi_opts *opts); > + struct bpf_kprobe_multi_opts *opts); > > struct bpf_ksyscall_opts { > /* size of this struct, for forward/backward compatibility */ > -- > 2.25.1 >
On Mon, Jun 26, 2023 at 6:53 AM Jiri Olsa <olsajiri@gmail.com> wrote: > > On Sun, Jun 25, 2023 at 10:18:16AM +0800, Jackie Liu wrote: > > From: Jackie Liu <liuyun01@kylinos.cn> > > > > When tracking functions through kprobe.multi, the number of tracked > > functions cannot be directly obtained. Sometimes in order to calculate > > this value, it is necessary to recalculate according to the pattern in > > the program. This is unnecessary. It is calculated by libbpf feedback > > through opts.cnt value, which can save resources. Example at [1]. > > > > [1] https://github.com/JackieLiu1/ketones/blob/master/src/funccount/funccount.c#L317 > > > > Signed-off-by: Jackie Liu <liuyun01@kylinos.cn> > > --- > > tools/lib/bpf/libbpf.c | 3 ++- > > tools/lib/bpf/libbpf.h | 2 +- > > 2 files changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > index fca5d2e412c5..ed3f1202c570 100644 > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > @@ -10506,7 +10506,7 @@ static void kprobe_multi_resolve_reinit(struct kprobe_multi_resolve *res) > > struct bpf_link * > > bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > > const char *pattern, > > - const struct bpf_kprobe_multi_opts *opts) > > + struct bpf_kprobe_multi_opts *opts) > > { > > LIBBPF_OPTS(bpf_link_create_opts, lopts); > > struct kprobe_multi_resolve res = { > > @@ -10582,6 +10582,7 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > > } > > link->fd = link_fd; > > free(res.addrs); > > + OPTS_SET(opts, cnt, res.cnt); > > hum I'm not sure it's good idea to use opts for output values > We do use opts for output parameters in some cases, but in this case I think it's not strictly necessary for libbpf to report back on the number of resolved addresses. If an application really needs it, then getting it from BPF link info is one way, but I'd argue that an application should just do its own resolution if this is important for its logic. > there's ongoing patchset adding possibility to get this > info/value via BPF_OBJ_GET_INFO_BY_FD syscall [1] > > jirka > > [1] https://lore.kernel.org/bpf/20230623141546.3751-1-laoar.shao@gmail.com/ > > > return link; > > > > error: > > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > > index 0b7362397ea3..f860dacc6add 100644 > > --- a/tools/lib/bpf/libbpf.h > > +++ b/tools/lib/bpf/libbpf.h > > @@ -527,7 +527,7 @@ struct bpf_kprobe_multi_opts { > > LIBBPF_API struct bpf_link * > > bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > > const char *pattern, > > - const struct bpf_kprobe_multi_opts *opts); > > + struct bpf_kprobe_multi_opts *opts); > > > > struct bpf_ksyscall_opts { > > /* size of this struct, for forward/backward compatibility */ > > -- > > 2.25.1 > >
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fca5d2e412c5..ed3f1202c570 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -10506,7 +10506,7 @@ static void kprobe_multi_resolve_reinit(struct kprobe_multi_resolve *res) struct bpf_link * bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, const char *pattern, - const struct bpf_kprobe_multi_opts *opts) + struct bpf_kprobe_multi_opts *opts) { LIBBPF_OPTS(bpf_link_create_opts, lopts); struct kprobe_multi_resolve res = { @@ -10582,6 +10582,7 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, } link->fd = link_fd; free(res.addrs); + OPTS_SET(opts, cnt, res.cnt); return link; error: diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 0b7362397ea3..f860dacc6add 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -527,7 +527,7 @@ struct bpf_kprobe_multi_opts { LIBBPF_API struct bpf_link * bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, const char *pattern, - const struct bpf_kprobe_multi_opts *opts); + struct bpf_kprobe_multi_opts *opts); struct bpf_ksyscall_opts { /* size of this struct, for forward/backward compatibility */