Messages in this thread Patch in this message | | | From | Kaixu Xia <> | Subject | [RFC PATCH 4/4] bpf tools: Enable/disable the perf events stored in 'struct bpf_object' | Date | Thu, 27 Aug 2015 10:42:22 +0000 |
| |
This patch enable/disable the perf events stored in 'struct bpf_object' at the appropriate time. These events we're interested in come from 'maps' sections.
Signed-off-by: Kaixu Xia <xiakaixu@huawei.com> --- tools/lib/bpf/libbpf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 2b3940e..7fab959 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -20,6 +20,7 @@ #include <linux/list.h> #include <libelf.h> #include <gelf.h> +#include <sys/ioctl.h> #include "libbpf.h" #include "bpf.h" @@ -972,6 +973,32 @@ bpf_object__load_progs(struct bpf_object *obj) return 0; } +static int +bpf_object__maps_event_enable(struct bpf_object *obj) +{ + int i; + int nr_bpf_event = obj->nr_bpf_event_fds; + + for (i = 0; i < nr_bpf_event; i++) + ioctl((int)obj->bpf_event_fds[i], + PERF_EVENT_IOC_ENABLE, 0); + + return 0; +} + +static void bpf_object__maps_event_close(struct bpf_object *obj) +{ + int i; + int nr_bpf_event = obj->nr_bpf_event_fds; + + for (i = 0; i < nr_bpf_event; i++) { + int maps_event_fd = (int)obj->bpf_event_fds[i]; + + ioctl(maps_event_fd, PERF_EVENT_IOC_DISABLE, 0); + close(maps_event_fd); + } +} + static int bpf_object__validate(struct bpf_object *obj) { if (obj->kern_version == 0) { @@ -1072,6 +1099,8 @@ int bpf_object__load(struct bpf_object *obj) goto out; if (bpf_object__load_progs(obj)) goto out; + if (bpf_object__maps_event_enable(obj)) + goto out; return 0; out: @@ -1087,6 +1116,7 @@ void bpf_object__close(struct bpf_object *obj) if (!obj) return; + bpf_object__maps_event_close(obj); bpf_object__elf_finish(obj); bpf_object__unload(obj); -- 1.8.3.4
| |