xref: /linux/tools/perf/util/bpf-filter.h (revision 9e906a9dead17d81d6c2687f65e159231d0e3286)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PERF_UTIL_BPF_FILTER_H
3 #define PERF_UTIL_BPF_FILTER_H
4 
5 #include <linux/list.h>
6 
7 #include "bpf_skel/sample-filter.h"
8 #include "util/debug.h"
9 
10 struct perf_bpf_filter_expr {
11 	struct list_head list;
12 	struct list_head groups;
13 	enum perf_bpf_filter_op op;
14 	int part;
15 	enum perf_bpf_filter_term term;
16 	unsigned long val;
17 };
18 
19 struct evsel;
20 struct target;
21 
22 /* path in BPF-fs for the pinned program and maps */
23 #define PERF_BPF_FILTER_PIN_PATH  "perf_filter"
24 
25 #ifdef HAVE_BPF_SKEL
26 struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(enum perf_bpf_filter_term term,
27 						       int part,
28 						       enum perf_bpf_filter_op op,
29 						       unsigned long val);
30 int perf_bpf_filter__parse(struct list_head *expr_head, const char *str);
31 int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target);
32 int perf_bpf_filter__destroy(struct evsel *evsel);
33 u64 perf_bpf_filter__lost_count(struct evsel *evsel);
34 int perf_bpf_filter__pin(void);
35 int perf_bpf_filter__unpin(void);
36 
37 #else /* !HAVE_BPF_SKEL */
38 
39 #include <errno.h>
40 
perf_bpf_filter__parse(struct list_head * expr_head __maybe_unused,const char * str __maybe_unused)41 static inline int perf_bpf_filter__parse(struct list_head *expr_head __maybe_unused,
42 					 const char *str __maybe_unused)
43 {
44 	pr_err("Error: BPF filter is requested but perf is not built with BPF.\n"
45 		"\tPlease make sure to build with libbpf and BPF skeleton.\n");
46 	return -EOPNOTSUPP;
47 }
perf_bpf_filter__prepare(struct evsel * evsel __maybe_unused,struct target * target __maybe_unused)48 static inline int perf_bpf_filter__prepare(struct evsel *evsel __maybe_unused,
49 					   struct target *target __maybe_unused)
50 {
51 	return -EOPNOTSUPP;
52 }
perf_bpf_filter__destroy(struct evsel * evsel __maybe_unused)53 static inline int perf_bpf_filter__destroy(struct evsel *evsel __maybe_unused)
54 {
55 	return -EOPNOTSUPP;
56 }
perf_bpf_filter__lost_count(struct evsel * evsel __maybe_unused)57 static inline u64 perf_bpf_filter__lost_count(struct evsel *evsel __maybe_unused)
58 {
59 	return 0;
60 }
perf_bpf_filter__pin(void)61 static inline int perf_bpf_filter__pin(void)
62 {
63 	return -EOPNOTSUPP;
64 }
perf_bpf_filter__unpin(void)65 static inline int perf_bpf_filter__unpin(void)
66 {
67 	return -EOPNOTSUPP;
68 }
69 #endif /* HAVE_BPF_SKEL*/
70 #endif /* PERF_UTIL_BPF_FILTER_H */
71