xref: /linux/tools/perf/util/bpf-filter.h (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
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 
perf_bpf_filter__parse(struct list_head * expr_head __maybe_unused,const char * str __maybe_unused)39 static inline int perf_bpf_filter__parse(struct list_head *expr_head __maybe_unused,
40 					 const char *str __maybe_unused)
41 {
42 	pr_err("Error: BPF filter is requested but perf is not built with BPF.\n"
43 		"\tPlease make sure to build with libbpf and BPF skeleton.\n");
44 	return -EOPNOTSUPP;
45 }
perf_bpf_filter__prepare(struct evsel * evsel __maybe_unused,struct target * target __maybe_unused)46 static inline int perf_bpf_filter__prepare(struct evsel *evsel __maybe_unused,
47 					   struct target *target __maybe_unused)
48 {
49 	return -EOPNOTSUPP;
50 }
perf_bpf_filter__destroy(struct evsel * evsel __maybe_unused)51 static inline int perf_bpf_filter__destroy(struct evsel *evsel __maybe_unused)
52 {
53 	return -EOPNOTSUPP;
54 }
perf_bpf_filter__lost_count(struct evsel * evsel __maybe_unused)55 static inline u64 perf_bpf_filter__lost_count(struct evsel *evsel __maybe_unused)
56 {
57 	return 0;
58 }
perf_bpf_filter__pin(void)59 static inline int perf_bpf_filter__pin(void)
60 {
61 	return -EOPNOTSUPP;
62 }
perf_bpf_filter__unpin(void)63 static inline int perf_bpf_filter__unpin(void)
64 {
65 	return -EOPNOTSUPP;
66 }
67 #endif /* HAVE_BPF_SKEL*/
68 #endif /* PERF_UTIL_BPF_FILTER_H */
69