diff options
-rw-r--r-- | tools/perf/util/bpf-loader.c | 22 | ||||
-rw-r--r-- | tools/perf/util/bpf-loader.h | 11 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 6 |
3 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 56f6fe8cf318..727955858d00 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c | |||
@@ -243,6 +243,18 @@ int bpf__unprobe(struct bpf_object *obj) | |||
243 | return ret; | 243 | return ret; |
244 | } | 244 | } |
245 | 245 | ||
246 | int bpf__load(struct bpf_object *obj) | ||
247 | { | ||
248 | int err; | ||
249 | |||
250 | err = bpf_object__load(obj); | ||
251 | if (err) { | ||
252 | pr_debug("bpf: load objects failed\n"); | ||
253 | return err; | ||
254 | } | ||
255 | return 0; | ||
256 | } | ||
257 | |||
246 | #define bpf__strerror_head(err, buf, size) \ | 258 | #define bpf__strerror_head(err, buf, size) \ |
247 | char sbuf[STRERR_BUFSIZE], *emsg;\ | 259 | char sbuf[STRERR_BUFSIZE], *emsg;\ |
248 | if (!size)\ | 260 | if (!size)\ |
@@ -275,3 +287,13 @@ int bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |||
275 | bpf__strerror_end(buf, size); | 287 | bpf__strerror_end(buf, size); |
276 | return 0; | 288 | return 0; |
277 | } | 289 | } |
290 | |||
291 | int bpf__strerror_load(struct bpf_object *obj __maybe_unused, | ||
292 | int err, char *buf, size_t size) | ||
293 | { | ||
294 | bpf__strerror_head(err, buf, size); | ||
295 | bpf__strerror_entry(EINVAL, "%s: Are you root and runing a CONFIG_BPF_SYSCALL kernel?", | ||
296 | emsg) | ||
297 | bpf__strerror_end(buf, size); | ||
298 | return 0; | ||
299 | } | ||
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index b819622dc7ce..b091ceb19c48 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h | |||
@@ -23,6 +23,9 @@ int bpf__unprobe(struct bpf_object *obj); | |||
23 | int bpf__strerror_probe(struct bpf_object *obj, int err, | 23 | int bpf__strerror_probe(struct bpf_object *obj, int err, |
24 | char *buf, size_t size); | 24 | char *buf, size_t size); |
25 | 25 | ||
26 | int bpf__load(struct bpf_object *obj); | ||
27 | int bpf__strerror_load(struct bpf_object *obj, int err, | ||
28 | char *buf, size_t size); | ||
26 | #else | 29 | #else |
27 | static inline struct bpf_object * | 30 | static inline struct bpf_object * |
28 | bpf__prepare_load(const char *filename __maybe_unused) | 31 | bpf__prepare_load(const char *filename __maybe_unused) |
@@ -35,6 +38,7 @@ static inline void bpf__clear(void) { } | |||
35 | 38 | ||
36 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} | 39 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} |
37 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} | 40 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} |
41 | static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } | ||
38 | 42 | ||
39 | static inline int | 43 | static inline int |
40 | __bpf_strerror(char *buf, size_t size) | 44 | __bpf_strerror(char *buf, size_t size) |
@@ -55,5 +59,12 @@ bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |||
55 | { | 59 | { |
56 | return __bpf_strerror(buf, size); | 60 | return __bpf_strerror(buf, size); |
57 | } | 61 | } |
62 | |||
63 | static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, | ||
64 | int err __maybe_unused, | ||
65 | char *buf, size_t size) | ||
66 | { | ||
67 | return __bpf_strerror(buf, size); | ||
68 | } | ||
58 | #endif | 69 | #endif |
59 | #endif | 70 | #endif |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 10a946779f46..c3aabeb63e88 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -561,6 +561,12 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data, | |||
561 | goto errout; | 561 | goto errout; |
562 | } | 562 | } |
563 | 563 | ||
564 | err = bpf__load(obj); | ||
565 | if (err) { | ||
566 | bpf__strerror_load(obj, err, errbuf, sizeof(errbuf)); | ||
567 | goto errout; | ||
568 | } | ||
569 | |||
564 | /* | 570 | /* |
565 | * Temporary add a dummy event here so we can check whether | 571 | * Temporary add a dummy event here so we can check whether |
566 | * basic bpf loader works. Following patches will replace | 572 | * basic bpf loader works. Following patches will replace |