Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbbFIFxD (ORCPT ); Tue, 9 Jun 2015 01:53:03 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:40931 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932297AbbFIFvh (ORCPT ); Tue, 9 Jun 2015 01:51:37 -0400 From: Wang Nan To: , , , , , , , , , , CC: , , , , Subject: [RFC PATCH v6 29/32] perf record: Load all eBPF object into kernel Date: Tue, 9 Jun 2015 05:50:33 +0000 Message-ID: <1433829036-23687-30-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1433829036-23687-1-git-send-email-wangnan0@huawei.com> References: <1433829036-23687-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.200] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.55767ED8.0038,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c29ba24de4a19220b2bd3f3b6b054614 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2536 Lines: 88 This patch utilizes bpf_load_object() provided by libbpf to load all objects into kernel. Signed-off-by: Wang Nan --- tools/perf/builtin-record.c | 12 ++++++++++++ tools/perf/util/bpf-loader.c | 19 +++++++++++++++++++ tools/perf/util/bpf-loader.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index a7c178e..5ce9d4a 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1121,6 +1121,18 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) return err; } + /* + * bpf__probe() also calls symbol__init() if there are probe + * events in bpf objects, so calling symbol_exit when failuer + * is safe. If there is no probe event, bpf__load() always + * success. + */ + err = bpf__load(); + if (err) { + pr_err("Loading BPF programs failed\n"); + goto out_symbol_exit; + } + symbol__init(NULL); if (symbol_conf.kptr_restrict) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 8c0bf46..45282e9 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -420,3 +420,22 @@ int bpf__probe(void) return err < 0 ? err : 0; } + +int bpf__load(void) +{ + struct bpf_object *obj, *tmp; + int err = 0; + + bpf_object__for_each(obj, tmp) { + err = bpf_object__load(obj); + if (err) { + pr_err("bpf: load objects failed\n"); + goto errout; + } + } + return 0; +errout: + bpf_object__for_each(obj, tmp) + bpf_object__unload(obj); + return err; +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index 7387fb6..e9c5f61 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -23,6 +23,7 @@ extern int perf_bpf_config(const char *var, const char *value); int bpf__prepare_load(const char *filename, bool source); int bpf__probe(void); int bpf__unprobe(void); +int bpf__load(void); void bpf__clear(void); #else @@ -34,6 +35,7 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused) static inline int bpf__probe(void) { return 0; } static inline int bpf__unprobe(void) { return 0; } +static inline int bpf__load(void) { return 0; } static inline void bpf__clear(void) { } #endif #endif -- 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/