Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753049AbbH0KnR (ORCPT ); Thu, 27 Aug 2015 06:43:17 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:35860 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752072AbbH0Kms (ORCPT ); Thu, 27 Aug 2015 06:42:48 -0400 From: Kaixu Xia To: , , , , , , , CC: , , , 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 Message-ID: <1440672142-89311-5-git-send-email-xiakaixu@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1440672142-89311-1-git-send-email-xiakaixu@huawei.com> References: <1440672142-89311-1-git-send-email-xiakaixu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1986 Lines: 79 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 --- 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 #include #include +#include #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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/