xref: /openbmc/linux/tools/perf/util/bpf_counter.h (revision 249592bf)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_BPF_COUNTER_H
3 #define __PERF_BPF_COUNTER_H 1
4 
5 #include <linux/list.h>
6 
7 struct evsel;
8 struct target;
9 struct bpf_counter;
10 
11 typedef int (*bpf_counter_evsel_op)(struct evsel *evsel);
12 typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel,
13 					   struct target *target);
14 typedef int (*bpf_counter_evsel_install_pe_op)(struct evsel *evsel,
15 					       int cpu,
16 					       int fd);
17 
18 struct bpf_counter_ops {
19 	bpf_counter_evsel_target_op load;
20 	bpf_counter_evsel_op enable;
21 	bpf_counter_evsel_op disable;
22 	bpf_counter_evsel_op read;
23 	bpf_counter_evsel_op destroy;
24 	bpf_counter_evsel_install_pe_op install_pe;
25 };
26 
27 struct bpf_counter {
28 	void *skel;
29 	struct list_head list;
30 };
31 
32 #ifdef HAVE_BPF_SKEL
33 
34 int bpf_counter__load(struct evsel *evsel, struct target *target);
35 int bpf_counter__enable(struct evsel *evsel);
36 int bpf_counter__disable(struct evsel *evsel);
37 int bpf_counter__read(struct evsel *evsel);
38 void bpf_counter__destroy(struct evsel *evsel);
39 int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd);
40 
41 #else /* HAVE_BPF_SKEL */
42 
43 #include <linux/err.h>
44 
45 static inline int bpf_counter__load(struct evsel *evsel __maybe_unused,
46 				    struct target *target __maybe_unused)
47 {
48 	return 0;
49 }
50 
51 static inline int bpf_counter__enable(struct evsel *evsel __maybe_unused)
52 {
53 	return 0;
54 }
55 
56 static inline int bpf_counter__disable(struct evsel *evsel __maybe_unused)
57 {
58 	return 0;
59 }
60 
61 static inline int bpf_counter__read(struct evsel *evsel __maybe_unused)
62 {
63 	return -EAGAIN;
64 }
65 
66 static inline void bpf_counter__destroy(struct evsel *evsel __maybe_unused)
67 {
68 }
69 
70 static inline int bpf_counter__install_pe(struct evsel *evsel __maybe_unused,
71 					  int cpu __maybe_unused,
72 					  int fd __maybe_unused)
73 {
74 	return 0;
75 }
76 
77 #endif /* HAVE_BPF_SKEL */
78 
79 #endif /* __PERF_BPF_COUNTER_H */
80