aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/bpf-loader.c22
-rw-r--r--tools/perf/util/bpf-loader.h11
-rw-r--r--tools/perf/util/parse-events.c6
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
246int 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
291int 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);
23int bpf__strerror_probe(struct bpf_object *obj, int err, 23int bpf__strerror_probe(struct bpf_object *obj, int err,
24 char *buf, size_t size); 24 char *buf, size_t size);
25 25
26int bpf__load(struct bpf_object *obj);
27int bpf__strerror_load(struct bpf_object *obj, int err,
28 char *buf, size_t size);
26#else 29#else
27static inline struct bpf_object * 30static inline struct bpf_object *
28bpf__prepare_load(const char *filename __maybe_unused) 31bpf__prepare_load(const char *filename __maybe_unused)
@@ -35,6 +38,7 @@ static inline void bpf__clear(void) { }
35 38
36static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} 39static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
37static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} 40static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
41static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
38 42
39static inline int 43static 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
63static 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