Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1203809
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 07/27] perf record: Load all eBPF object into kernel |
| Date | 2015-08-10 08:30 +0200 |
| Message-ID | <pVOKR-5XF-11@gated-at.bofh.it> (permalink) |
| References | <pVOBb-5JE-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
This patch utilizes bpf_object__load() provided by libbpf to load all
objects into kernel.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/n/1436445342-1402-24-git-send-email-wangnan0@huawei.com
---
tools/perf/builtin-record.c | 15 +++++++++++++++
tools/perf/util/bpf-loader.c | 28 ++++++++++++++++++++++++++++
tools/perf/util/bpf-loader.h | 10 ++++++++++
3 files changed, 53 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index aebf086..a64f0c9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1145,6 +1145,21 @@ 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");
+
+ bpf__strerror_load(err, errbuf, sizeof(errbuf));
+ pr_err("\t%s\n", errbuf);
+ 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 b44a874..8ac8b23 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -267,6 +267,25 @@ out:
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_debug("bpf: load objects failed\n");
+ goto errout;
+ }
+ }
+ return 0;
+errout:
+ bpf_object__for_each_safe(obj, tmp)
+ bpf_object__unload(obj);
+ return err;
+}
+
#define bpf__strerror_head(err, buf, size) \
char sbuf[STRERR_BUFSIZE], *emsg;\
if (err < 0)\
@@ -306,3 +325,12 @@ int bpf__strerror_probe(int err, char *buf, size_t size)
bpf__strerror_end();
return 0;
}
+
+int bpf__strerror_load(int err, char *buf, size_t size)
+{
+ bpf__strerror_head(err, buf, size);
+ bpf__strerror_entry(EINVAL, "%s: add -v to see detail. Run a CONFIG_BPF_SYSCALL kernel?",
+ emsg)
+ bpf__strerror_end();
+ return 0;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 3f5ddfa..01805d6 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -19,6 +19,9 @@ int bpf__probe(void);
int bpf__unprobe(void);
int bpf__strerror_probe(int err, char *buf, size_t size);
+int bpf__load(void);
+int bpf__strerror_load(int err, char *buf, size_t size);
+
void bpf__clear(void);
#else
static inline int bpf__prepare_load(const char *filename __maybe_unused)
@@ -29,6 +32,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) { }
static inline int
@@ -53,5 +57,11 @@ static inline int bpf__strerror_probe(int err __maybe_unused,
{
return __bpf_strerror(buf, size);
}
+
+static inline int bpf__strerror_load(int err __maybe_unused,
+ char *buf, size_t size)
+{
+ return __bpf_strerror(buf, size);
+}
#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/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/27] perf tools: filtering events using eBPF programs Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:20 +0200 [PATCH 23/27] perf tools: Generate prologue for BPF programs Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:20 +0200 [PATCH 18/27] perf probe: Reset args and nargs for probe_trace_event when failure Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:20 +0200 [PATCH 02/27] perf ebpf: Add the libbpf glue Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 07/27] perf record: Load all eBPF object into kernel Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 10/27] perf tools: Suppress probing messages when probing by BPF loading Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 20/27] perf tools: Add BPF_PROLOGUE config options for further patches Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 25/27] perf record: Support custom vmlinux path Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 16/27] bpf tools: Load a program with different instances using preprocessor Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 09/27] perf tools: Attach eBPF program to perf event Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 01/27] perf tools: Make perf depend on libbpf Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 12/27] perf tools: Infrastructure for compiling scriptlets when passing '.c' to --event Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 11/27] perf record: Add clang options for compiling BPF scripts Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 04/27] perf probe: Attach trace_probe_event with perf_probe_event Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 08/27] perf tools: Add bpf_fd field to evsel and config it Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 03/27] perf tools: Enable passing bpf object file to --event Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200 [PATCH 13/27] perf tests: Enforce LLVM test for BPF test Wang Nan <wangnan0@huawei.com> - 2015-08-10 08:30 +0200
csiph-web