xref: /openbmc/linux/tools/perf/util/bpf_counter.h (revision ffe66bbe)
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 read;
22 	bpf_counter_evsel_op destroy;
23 	bpf_counter_evsel_install_pe_op install_pe;
24 };
25 
26 struct bpf_counter {
27 	void *skel;
28 	struct list_head list;
29 };
30 
31 #ifdef HAVE_BPF_SKEL
32 
33 int bpf_counter__load(struct evsel *evsel, struct target *target);
34 int bpf_counter__enable(struct evsel *evsel);
35 int bpf_counter__read(struct evsel *evsel);
36 void bpf_counter__destroy(struct evsel *evsel);
37 int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd);
38 
39 #else /* HAVE_BPF_SKEL */
40 
41 #include<linux/err.h>
42 
43 static inline int bpf_counter__load(struct evsel *evsel __maybe_unused,
44 				    struct target *target __maybe_unused)
45 {
46 	return 0;
47 }
48 
49 static inline int bpf_counter__enable(struct evsel *evsel __maybe_unused)
50 {
51 	return 0;
52 }
53 
54 static inline int bpf_counter__read(struct evsel *evsel __maybe_unused)
55 {
56 	return -EAGAIN;
57 }
58 
59 static inline void bpf_counter__destroy(struct evsel *evsel __maybe_unused)
60 {
61 }
62 
63 static inline int bpf_counter__install_pe(struct evsel *evsel __maybe_unused,
64 					  int cpu __maybe_unused,
65 					  int fd __maybe_unused)
66 {
67 	return 0;
68 }
69 
70 #endif /* HAVE_BPF_SKEL */
71 
72 #endif /* __PERF_BPF_COUNTER_H */
73