[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1436361268-234530-35-git-send-email-wangnan0@huawei.com>
Date: Wed, 8 Jul 2015 13:14:23 +0000
From: Wang Nan <wangnan0@...wei.com>
To: <acme@...nel.org>, <ast@...mgrid.com>
CC: <linux-kernel@...r.kernel.org>, <lizefan@...wei.com>,
<hekuang@...wei.com>, <xiakaixu@...wei.com>, <pi3orama@....com>
Subject: [PATCH v11 34/39] perf record: Load all eBPF object into kernel
This patch utilizes bpf_load_object() provided by libbpf to load all
objects into kernel.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
---
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 33b213a..6d943a7 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1128,6 +1128,18 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
goto out_symbol_exit;
}
+ /*
+ * bpf__probe() also calls symbol__init() if there are probe
+ * events in bpf objects, so calling symbol_exit when failure
+ * 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 df3f471..f68ba33 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -241,3 +241,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_safe(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_safe(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 374aec0..ae0dc9b 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -14,6 +14,7 @@
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
@@ -26,6 +27,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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists