mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-03 15:19:07 +08:00
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 <eddyz87@gmail.com> Suggested-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Thomas Richter <tmricht@linux.ibm.com> Co-developed-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20250806162417.19666-2-iii@linux.ibm.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
df60ff2a29
commit
8ce18b6b73
13
src/libbpf.c
13
src/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;
|
||||
|
||||
Reference in New Issue
Block a user