Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / bpf-loader.h
blob25251d63164ceee62acfc7231aecdc4caec4d24b
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
4 * Copyright (C) 2015, Huawei Inc.
5 */
6 #ifndef __BPF_LOADER_H
7 #define __BPF_LOADER_H
9 #include <linux/compiler.h>
10 #include <linux/err.h>
11 #include <bpf/libbpf.h>
13 enum bpf_loader_errno {
14 __BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100,
15 /* Invalid config string */
16 BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START,
17 BPF_LOADER_ERRNO__GROUP, /* Invalid group name */
18 BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */
19 BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */
20 BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */
21 BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */
22 BPF_LOADER_ERRNO__PROLOGUE, /* Failed to generate prologue */
23 BPF_LOADER_ERRNO__PROLOGUE2BIG, /* Prologue too big for program */
24 BPF_LOADER_ERRNO__PROLOGUEOOB, /* Offset out of bound for prologue */
25 BPF_LOADER_ERRNO__OBJCONF_OPT, /* Invalid object config option */
26 BPF_LOADER_ERRNO__OBJCONF_CONF, /* Config value not set (lost '=')) */
27 BPF_LOADER_ERRNO__OBJCONF_MAP_OPT, /* Invalid object map config option */
28 BPF_LOADER_ERRNO__OBJCONF_MAP_NOTEXIST, /* Target map not exist */
29 BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE, /* Incorrect value type for map */
30 BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE, /* Incorrect map type */
31 BPF_LOADER_ERRNO__OBJCONF_MAP_KEYSIZE, /* Incorrect map key size */
32 BPF_LOADER_ERRNO__OBJCONF_MAP_VALUESIZE,/* Incorrect map value size */
33 BPF_LOADER_ERRNO__OBJCONF_MAP_NOEVT, /* Event not found for map setting */
34 BPF_LOADER_ERRNO__OBJCONF_MAP_MAPSIZE, /* Invalid map size for event setting */
35 BPF_LOADER_ERRNO__OBJCONF_MAP_EVTDIM, /* Event dimension too large */
36 BPF_LOADER_ERRNO__OBJCONF_MAP_EVTINH, /* Doesn't support inherit event */
37 BPF_LOADER_ERRNO__OBJCONF_MAP_EVTTYPE, /* Wrong event type for map */
38 BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG, /* Index too large */
39 __BPF_LOADER_ERRNO__END,
42 struct evsel;
43 struct evlist;
44 struct bpf_object;
45 struct parse_events_term;
46 #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
48 typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event,
49 int fd, struct bpf_object *obj, void *arg);
51 #ifdef HAVE_LIBBPF_SUPPORT
52 struct bpf_object *bpf__prepare_load(const char *filename, bool source);
53 int bpf__strerror_prepare_load(const char *filename, bool source,
54 int err, char *buf, size_t size);
56 struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
57 const char *name);
59 void bpf__clear(void);
61 int bpf__probe(struct bpf_object *obj);
62 int bpf__unprobe(struct bpf_object *obj);
63 int bpf__strerror_probe(struct bpf_object *obj, int err,
64 char *buf, size_t size);
66 int bpf__load(struct bpf_object *obj);
67 int bpf__strerror_load(struct bpf_object *obj, int err,
68 char *buf, size_t size);
69 int bpf__foreach_event(struct bpf_object *obj,
70 bpf_prog_iter_callback_t func, void *arg);
72 int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term,
73 struct evlist *evlist, int *error_pos);
74 int bpf__strerror_config_obj(struct bpf_object *obj,
75 struct parse_events_term *term,
76 struct evlist *evlist,
77 int *error_pos, int err, char *buf,
78 size_t size);
79 int bpf__apply_obj_config(void);
80 int bpf__strerror_apply_obj_config(int err, char *buf, size_t size);
82 int bpf__setup_stdout(struct evlist *evlist);
83 struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name);
84 int bpf__strerror_setup_output_event(struct evlist *evlist, int err, char *buf, size_t size);
85 #else
86 #include <errno.h>
87 #include <string.h>
88 #include "debug.h"
90 static inline struct bpf_object *
91 bpf__prepare_load(const char *filename __maybe_unused,
92 bool source __maybe_unused)
94 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
95 return ERR_PTR(-ENOTSUP);
98 static inline struct bpf_object *
99 bpf__prepare_load_buffer(void *obj_buf __maybe_unused,
100 size_t obj_buf_sz __maybe_unused)
102 return ERR_PTR(-ENOTSUP);
105 static inline void bpf__clear(void) { }
107 static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
108 static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
109 static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
111 static inline int
112 bpf__foreach_event(struct bpf_object *obj __maybe_unused,
113 bpf_prog_iter_callback_t func __maybe_unused,
114 void *arg __maybe_unused)
116 return 0;
119 static inline int
120 bpf__config_obj(struct bpf_object *obj __maybe_unused,
121 struct parse_events_term *term __maybe_unused,
122 struct evlist *evlist __maybe_unused,
123 int *error_pos __maybe_unused)
125 return 0;
128 static inline int
129 bpf__apply_obj_config(void)
131 return 0;
134 static inline int
135 bpf__setup_stdout(struct evlist *evlist __maybe_unused)
137 return 0;
140 static inline struct evsel *
141 bpf__setup_output_event(struct evlist *evlist __maybe_unused, const char *name __maybe_unused)
143 return NULL;
146 static inline int
147 __bpf_strerror(char *buf, size_t size)
149 if (!size)
150 return 0;
151 strncpy(buf,
152 "ERROR: eBPF object loading is disabled during compiling.\n",
153 size);
154 buf[size - 1] = '\0';
155 return 0;
158 static inline
159 int bpf__strerror_prepare_load(const char *filename __maybe_unused,
160 bool source __maybe_unused,
161 int err __maybe_unused,
162 char *buf, size_t size)
164 return __bpf_strerror(buf, size);
167 static inline int
168 bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
169 int err __maybe_unused,
170 char *buf, size_t size)
172 return __bpf_strerror(buf, size);
175 static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
176 int err __maybe_unused,
177 char *buf, size_t size)
179 return __bpf_strerror(buf, size);
182 static inline int
183 bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused,
184 struct parse_events_term *term __maybe_unused,
185 struct evlist *evlist __maybe_unused,
186 int *error_pos __maybe_unused,
187 int err __maybe_unused,
188 char *buf, size_t size)
190 return __bpf_strerror(buf, size);
193 static inline int
194 bpf__strerror_apply_obj_config(int err __maybe_unused,
195 char *buf, size_t size)
197 return __bpf_strerror(buf, size);
200 static inline int
201 bpf__strerror_setup_output_event(struct evlist *evlist __maybe_unused,
202 int err __maybe_unused, char *buf, size_t size)
204 return __bpf_strerror(buf, size);
207 #endif
209 static inline int bpf__strerror_setup_stdout(struct evlist *evlist, int err, char *buf, size_t size)
211 return bpf__strerror_setup_output_event(evlist, err, buf, size);
213 #endif