Blame view
tools/perf/util/bpf-loader.h
6.09 KB
69d262a93
|
1 2 3 4 5 6 7 8 9 10 |
/* * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> * Copyright (C) 2015, Huawei Inc. */ #ifndef __BPF_LOADER_H #define __BPF_LOADER_H #include <linux/compiler.h> #include <linux/err.h> #include <string.h> |
d3e0ce393
|
11 |
#include <bpf/libbpf.h> |
4edf30e39
|
12 |
#include "probe-event.h" |
066dacbf2
|
13 |
#include "evlist.h" |
69d262a93
|
14 |
#include "debug.h" |
d3e0ce393
|
15 16 17 18 19 20 21 22 |
enum bpf_loader_errno { __BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100, /* Invalid config string */ BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START, BPF_LOADER_ERRNO__GROUP, /* Invalid group name */ BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */ BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */ BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */ |
0bb934901
|
23 |
BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */ |
bfc077b4c
|
24 25 26 |
BPF_LOADER_ERRNO__PROLOGUE, /* Failed to generate prologue */ BPF_LOADER_ERRNO__PROLOGUE2BIG, /* Prologue too big for program */ BPF_LOADER_ERRNO__PROLOGUEOOB, /* Offset out of bound for prologue */ |
066dacbf2
|
27 28 29 30 31 32 33 34 |
BPF_LOADER_ERRNO__OBJCONF_OPT, /* Invalid object config option */ BPF_LOADER_ERRNO__OBJCONF_CONF, /* Config value not set (lost '=')) */ BPF_LOADER_ERRNO__OBJCONF_MAP_OPT, /* Invalid object map config option */ BPF_LOADER_ERRNO__OBJCONF_MAP_NOTEXIST, /* Target map not exist */ BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE, /* Incorrect value type for map */ BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE, /* Incorrect map type */ BPF_LOADER_ERRNO__OBJCONF_MAP_KEYSIZE, /* Incorrect map key size */ BPF_LOADER_ERRNO__OBJCONF_MAP_VALUESIZE,/* Incorrect map value size */ |
7630b3e28
|
35 36 37 38 39 |
BPF_LOADER_ERRNO__OBJCONF_MAP_NOEVT, /* Event not found for map setting */ BPF_LOADER_ERRNO__OBJCONF_MAP_MAPSIZE, /* Invalid map size for event setting */ BPF_LOADER_ERRNO__OBJCONF_MAP_EVTDIM, /* Event dimension too large */ BPF_LOADER_ERRNO__OBJCONF_MAP_EVTINH, /* Doesn't support inherit event */ BPF_LOADER_ERRNO__OBJCONF_MAP_EVTTYPE, /* Wrong event type for map */ |
2d055bf25
|
40 |
BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG, /* Index too large */ |
d3e0ce393
|
41 42 |
__BPF_LOADER_ERRNO__END, }; |
69d262a93
|
43 |
struct bpf_object; |
066dacbf2
|
44 |
struct parse_events_term; |
aa3abf30b
|
45 |
#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" |
69d262a93
|
46 |
|
cd102d70f
|
47 |
typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event, |
4edf30e39
|
48 |
int fd, void *arg); |
69d262a93
|
49 |
#ifdef HAVE_LIBBPF_SUPPORT |
d509db047
|
50 |
struct bpf_object *bpf__prepare_load(const char *filename, bool source); |
d3e0ce393
|
51 52 |
int bpf__strerror_prepare_load(const char *filename, bool source, int err, char *buf, size_t size); |
69d262a93
|
53 |
|
ba1fae431
|
54 55 |
struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name); |
69d262a93
|
56 |
void bpf__clear(void); |
aa3abf30b
|
57 58 59 60 61 |
int bpf__probe(struct bpf_object *obj); int bpf__unprobe(struct bpf_object *obj); int bpf__strerror_probe(struct bpf_object *obj, int err, char *buf, size_t size); |
1e5e3ee8f
|
62 63 64 |
int bpf__load(struct bpf_object *obj); int bpf__strerror_load(struct bpf_object *obj, int err, char *buf, size_t size); |
cd102d70f
|
65 66 |
int bpf__foreach_event(struct bpf_object *obj, bpf_prog_iter_callback_t func, void *arg); |
066dacbf2
|
67 68 69 70 71 72 73 74 |
int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term, struct perf_evlist *evlist, int *error_pos); int bpf__strerror_config_obj(struct bpf_object *obj, struct parse_events_term *term, struct perf_evlist *evlist, int *error_pos, int err, char *buf, size_t size); |
8690a2a77
|
75 76 |
int bpf__apply_obj_config(void); int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); |
d78885739
|
77 78 79 80 |
int bpf__setup_stdout(struct perf_evlist *evlist); int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, char *buf, size_t size); |
69d262a93
|
81 |
#else |
a43783aee
|
82 |
#include <errno.h> |
69d262a93
|
83 |
static inline struct bpf_object * |
d509db047
|
84 85 |
bpf__prepare_load(const char *filename __maybe_unused, bool source __maybe_unused) |
69d262a93
|
86 87 88 89 90 |
{ pr_debug("ERROR: eBPF object loading is disabled during compiling. "); return ERR_PTR(-ENOTSUP); } |
ba1fae431
|
91 92 93 94 95 96 |
static inline struct bpf_object * bpf__prepare_load_buffer(void *obj_buf __maybe_unused, size_t obj_buf_sz __maybe_unused) { return ERR_PTR(-ENOTSUP); } |
69d262a93
|
97 |
static inline void bpf__clear(void) { } |
aa3abf30b
|
98 99 100 |
static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} |
1e5e3ee8f
|
101 |
static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } |
aa3abf30b
|
102 103 |
static inline int |
cd102d70f
|
104 105 106 |
bpf__foreach_event(struct bpf_object *obj __maybe_unused, bpf_prog_iter_callback_t func __maybe_unused, void *arg __maybe_unused) |
4edf30e39
|
107 108 109 110 111 |
{ return 0; } static inline int |
066dacbf2
|
112 113 114 115 116 117 118 119 120 |
bpf__config_obj(struct bpf_object *obj __maybe_unused, struct parse_events_term *term __maybe_unused, struct perf_evlist *evlist __maybe_unused, int *error_pos __maybe_unused) { return 0; } static inline int |
8690a2a77
|
121 122 123 124 125 126 |
bpf__apply_obj_config(void) { return 0; } static inline int |
d78885739
|
127 128 129 130 131 132 |
bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) { return 0; } static inline int |
aa3abf30b
|
133 134 135 136 137 138 139 140 141 142 143 |
__bpf_strerror(char *buf, size_t size) { if (!size) return 0; strncpy(buf, "ERROR: eBPF object loading is disabled during compiling. ", size); buf[size - 1] = '\0'; return 0; } |
d3e0ce393
|
144 145 146 147 148 149 150 151 |
static inline int bpf__strerror_prepare_load(const char *filename __maybe_unused, bool source __maybe_unused, int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
aa3abf30b
|
152 153 154 155 156 157 158 |
static inline int bpf__strerror_probe(struct bpf_object *obj __maybe_unused, int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
1e5e3ee8f
|
159 160 161 162 163 164 165 |
static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
066dacbf2
|
166 167 168 169 170 171 172 173 174 175 176 |
static inline int bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused, struct parse_events_term *term __maybe_unused, struct perf_evlist *evlist __maybe_unused, int *error_pos __maybe_unused, int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
8690a2a77
|
177 178 179 180 181 182 183 |
static inline int bpf__strerror_apply_obj_config(int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
d78885739
|
184 185 186 187 188 189 190 191 |
static inline int bpf__strerror_setup_stdout(struct perf_evlist *evlist __maybe_unused, int err __maybe_unused, char *buf, size_t size) { return __bpf_strerror(buf, size); } |
69d262a93
|
192 193 |
#endif #endif |