xref: /linux/tools/perf/util/bpf_counter.h (revision ec714e371f22f716a04e6ecb2a24988c92b26911)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_BPF_COUNTER_H
3 #define __PERF_BPF_COUNTER_H 1
4 
5 struct evsel;
6 struct target;
7 
8 #ifdef HAVE_BPF_SKEL
9 
10 typedef int (*bpf_counter_evsel_op)(struct evsel *evsel);
11 typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel,
12 					   struct target *target);
13 typedef int (*bpf_counter_evsel_install_pe_op)(struct evsel *evsel,
14 					       int cpu_map_idx,
15 					       int fd);
16 
17 /* Shared ops between bpf_counter, bpf_counter_cgroup, etc. */
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 int bpf_counter__load(struct evsel *evsel, struct target *target);
28 int bpf_counter__enable(struct evsel *evsel);
29 int bpf_counter__disable(struct evsel *evsel);
30 int bpf_counter__read(struct evsel *evsel);
31 void bpf_counter__destroy(struct evsel *evsel);
32 int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd);
33 
34 int bperf_trigger_reading(int prog_fd, int cpu);
35 void set_max_rlimit(void);
36 
37 #else /* HAVE_BPF_SKEL */
38 
39 #include <linux/err.h>
40 
bpf_counter__load(struct evsel * evsel __maybe_unused,struct target * target __maybe_unused)41 static inline int bpf_counter__load(struct evsel *evsel __maybe_unused,
42 				    struct target *target __maybe_unused)
43 {
44 	return 0;
45 }
46 
bpf_counter__enable(struct evsel * evsel __maybe_unused)47 static inline int bpf_counter__enable(struct evsel *evsel __maybe_unused)
48 {
49 	return 0;
50 }
51 
bpf_counter__disable(struct evsel * evsel __maybe_unused)52 static inline int bpf_counter__disable(struct evsel *evsel __maybe_unused)
53 {
54 	return 0;
55 }
56 
bpf_counter__read(struct evsel * evsel __maybe_unused)57 static inline int bpf_counter__read(struct evsel *evsel __maybe_unused)
58 {
59 	return -EAGAIN;
60 }
61 
bpf_counter__destroy(struct evsel * evsel __maybe_unused)62 static inline void bpf_counter__destroy(struct evsel *evsel __maybe_unused)
63 {
64 }
65 
bpf_counter__install_pe(struct evsel * evsel __maybe_unused,int cpu __maybe_unused,int fd __maybe_unused)66 static inline int bpf_counter__install_pe(struct evsel *evsel __maybe_unused,
67 					  int cpu __maybe_unused,
68 					  int fd __maybe_unused)
69 {
70 	return 0;
71 }
72 
73 #endif /* HAVE_BPF_SKEL */
74 
75 #endif /* __PERF_BPF_COUNTER_H */
76