Blame view

tools/perf/util/bpf-loader.h 6.09 KB
69d262a93   Wang Nan   perf ebpf: Add th...
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   Wang Nan   perf bpf: Improve...
11
  #include <bpf/libbpf.h>
4edf30e39   Wang Nan   perf bpf: Collect...
12
  #include "probe-event.h"
066dacbf2   Wang Nan   perf bpf: Add API...
13
  #include "evlist.h"
69d262a93   Wang Nan   perf ebpf: Add th...
14
  #include "debug.h"
d3e0ce393   Wang Nan   perf bpf: Improve...
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   Wang Nan   perf bpf: Rename ...
23
  	BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */
bfc077b4c   He Kuang   perf bpf: Add pro...
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   Wang Nan   perf bpf: Add API...
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   Wang Nan   perf tools: Enabl...
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   Wang Nan   perf tools: Suppo...
40
  	BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG,	/* Index too large */
d3e0ce393   Wang Nan   perf bpf: Improve...
41
42
  	__BPF_LOADER_ERRNO__END,
  };
69d262a93   Wang Nan   perf ebpf: Add th...
43
  struct bpf_object;
066dacbf2   Wang Nan   perf bpf: Add API...
44
  struct parse_events_term;
aa3abf30b   Wang Nan   perf tools: Creat...
45
  #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
69d262a93   Wang Nan   perf ebpf: Add th...
46

cd102d70f   Wang Nan   perf bpf: Rename ...
47
  typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event,
4edf30e39   Wang Nan   perf bpf: Collect...
48
  					int fd, void *arg);
69d262a93   Wang Nan   perf ebpf: Add th...
49
  #ifdef HAVE_LIBBPF_SUPPORT
d509db047   Wang Nan   perf tools: Compi...
50
  struct bpf_object *bpf__prepare_load(const char *filename, bool source);
d3e0ce393   Wang Nan   perf bpf: Improve...
51
52
  int bpf__strerror_prepare_load(const char *filename, bool source,
  			       int err, char *buf, size_t size);
69d262a93   Wang Nan   perf ebpf: Add th...
53

ba1fae431   Wang Nan   perf test: Add 'p...
54
55
  struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
  					    const char *name);
69d262a93   Wang Nan   perf ebpf: Add th...
56
  void bpf__clear(void);
aa3abf30b   Wang Nan   perf tools: Creat...
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   Wang Nan   perf tools: Load ...
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   Wang Nan   perf bpf: Rename ...
65
66
  int bpf__foreach_event(struct bpf_object *obj,
  		       bpf_prog_iter_callback_t func, void *arg);
066dacbf2   Wang Nan   perf bpf: Add API...
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   Wang Nan   perf record: Appl...
75
76
  int bpf__apply_obj_config(void);
  int bpf__strerror_apply_obj_config(int err, char *buf, size_t size);
d78885739   Wang Nan   perf bpf: Clone b...
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   Wang Nan   perf ebpf: Add th...
81
  #else
a43783aee   Arnaldo Carvalho de Melo   perf tools: Inclu...
82
  #include <errno.h>
69d262a93   Wang Nan   perf ebpf: Add th...
83
  static inline struct bpf_object *
d509db047   Wang Nan   perf tools: Compi...
84
85
  bpf__prepare_load(const char *filename __maybe_unused,
  		  bool source __maybe_unused)
69d262a93   Wang Nan   perf ebpf: Add th...
86
87
88
89
90
  {
  	pr_debug("ERROR: eBPF object loading is disabled during compiling.
  ");
  	return ERR_PTR(-ENOTSUP);
  }
ba1fae431   Wang Nan   perf test: Add 'p...
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   Wang Nan   perf ebpf: Add th...
97
  static inline void bpf__clear(void) { }
aa3abf30b   Wang Nan   perf tools: Creat...
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   Wang Nan   perf tools: Load ...
101
  static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
aa3abf30b   Wang Nan   perf tools: Creat...
102
103
  
  static inline int
cd102d70f   Wang Nan   perf bpf: Rename ...
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   Wang Nan   perf bpf: Collect...
107
108
109
110
111
  {
  	return 0;
  }
  
  static inline int
066dacbf2   Wang Nan   perf bpf: Add API...
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   Wang Nan   perf record: Appl...
121
122
123
124
125
126
  bpf__apply_obj_config(void)
  {
  	return 0;
  }
  
  static inline int
d78885739   Wang Nan   perf bpf: Clone b...
127
128
129
130
131
132
  bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused)
  {
  	return 0;
  }
  
  static inline int
aa3abf30b   Wang Nan   perf tools: Creat...
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   Wang Nan   perf bpf: Improve...
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   Wang Nan   perf tools: Creat...
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   Wang Nan   perf tools: Load ...
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   Wang Nan   perf bpf: Add API...
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   Wang Nan   perf record: Appl...
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   Wang Nan   perf bpf: Clone b...
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   Wang Nan   perf ebpf: Add th...
192
193
  #endif
  #endif