diff options
| author | Ilya Leoshkevich <[email protected]> | 2025-08-06 16:22:41 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2025-08-07 16:01:41 +0000 |
| commit | 9474e27a24a41e55d0ac2b77d8171fddec7dbb87 (patch) | |
| tree | ebc01697c97408eaf8e24073cb5c1d913af08fe3 /tools/lib/bpf/libbpf.c | |
| parent | bpf: Fix memory leak of bpf_scc_info objects (diff) | |
| download | kernel-9474e27a24a41e55d0ac2b77d8171fddec7dbb87.tar.gz kernel-9474e27a24a41e55d0ac2b77d8171fddec7dbb87.zip | |
libbpf: Add the ability to suppress perf event enablement
Automatically enabling a perf event after attaching a BPF prog to it is
not always desirable.
Add a new "dont_enable" field to struct bpf_perf_event_opts. While
introducing "enable" instead would be nicer in that it would avoid
a double negation in the implementation, it would make
DECLARE_LIBBPF_OPTS() less efficient.
Acked-by: Eduard Zingerman <[email protected]>
Suggested-by: Jiri Olsa <[email protected]>
Tested-by: Thomas Richter <[email protected]>
Co-developed-by: Thomas Richter <[email protected]>
Signed-off-by: Thomas Richter <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
| -rw-r--r-- | tools/lib/bpf/libbpf.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fb4d92c5c339..8f5a81b672e1 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -10965,11 +10965,14 @@ struct bpf_link *bpf_program__attach_perf_event_opts(const struct bpf_program *p } link->link.fd = pfd; } - if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { - err = -errno; - pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", - prog->name, pfd, errstr(err)); - goto err_out; + + if (!OPTS_GET(opts, dont_enable, false)) { + if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { + err = -errno; + pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", + prog->name, pfd, errstr(err)); + goto err_out; + } } return &link->link; |
