]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - tools/perf/util/bpf-loader.h
Merge branch 'ras-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / tools / perf / util / bpf-loader.h
1 /*
2  * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3  * Copyright (C) 2015, Huawei Inc.
4  */
5 #ifndef __BPF_LOADER_H
6 #define __BPF_LOADER_H
7
8 #include <linux/compiler.h>
9 #include <linux/err.h>
10 #include <string.h>
11 #include "probe-event.h"
12 #include "debug.h"
13
14 struct bpf_object;
15 #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
16
17 typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
18                                         int fd, void *arg);
19
20 #ifdef HAVE_LIBBPF_SUPPORT
21 struct bpf_object *bpf__prepare_load(const char *filename, bool source);
22
23 void bpf__clear(void);
24
25 int bpf__probe(struct bpf_object *obj);
26 int bpf__unprobe(struct bpf_object *obj);
27 int bpf__strerror_probe(struct bpf_object *obj, int err,
28                         char *buf, size_t size);
29
30 int bpf__load(struct bpf_object *obj);
31 int bpf__strerror_load(struct bpf_object *obj, int err,
32                        char *buf, size_t size);
33 int bpf__foreach_tev(struct bpf_object *obj,
34                      bpf_prog_iter_callback_t func, void *arg);
35 #else
36 static inline struct bpf_object *
37 bpf__prepare_load(const char *filename __maybe_unused,
38                   bool source __maybe_unused)
39 {
40         pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
41         return ERR_PTR(-ENOTSUP);
42 }
43
44 static inline void bpf__clear(void) { }
45
46 static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
47 static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
48 static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
49
50 static inline int
51 bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
52                  bpf_prog_iter_callback_t func __maybe_unused,
53                  void *arg __maybe_unused)
54 {
55         return 0;
56 }
57
58 static inline int
59 __bpf_strerror(char *buf, size_t size)
60 {
61         if (!size)
62                 return 0;
63         strncpy(buf,
64                 "ERROR: eBPF object loading is disabled during compiling.\n",
65                 size);
66         buf[size - 1] = '\0';
67         return 0;
68 }
69
70 static inline int
71 bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
72                     int err __maybe_unused,
73                     char *buf, size_t size)
74 {
75         return __bpf_strerror(buf, size);
76 }
77
78 static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
79                                      int err __maybe_unused,
80                                      char *buf, size_t size)
81 {
82         return __bpf_strerror(buf, size);
83 }
84 #endif
85 #endif