1 %option prefix="perf_bpf_filter_"
7 #include <linux/perf_event.h>
9 #include "bpf-filter.h"
10 #include "bpf-filter-bison.h"
12 extern int perf_bpf_filter_needs_path;
14 static int sample(enum perf_bpf_filter_term term)
16 perf_bpf_filter_needs_path = 0;
17 perf_bpf_filter_lval.sample.term = term;
18 perf_bpf_filter_lval.sample.part = 0;
22 static int sample_part(enum perf_bpf_filter_term term, int part)
24 perf_bpf_filter_needs_path = 0;
25 perf_bpf_filter_lval.sample.term = term;
26 perf_bpf_filter_lval.sample.part = part;
30 static int sample_path(enum perf_bpf_filter_term term)
32 perf_bpf_filter_needs_path = 1;
33 perf_bpf_filter_lval.sample.term = term;
34 perf_bpf_filter_lval.sample.part = 0;
35 return BFT_SAMPLE_PATH;
38 static int operator(enum perf_bpf_filter_op op)
40 perf_bpf_filter_lval.op = op;
44 static int value(int base)
49 num = strtoul(perf_bpf_filter_text, NULL, base);
53 perf_bpf_filter_lval.num = num;
57 static int constant(int val)
59 perf_bpf_filter_lval.num = val;
63 static int path_or_error(void)
65 if (!perf_bpf_filter_needs_path) {
66 printf("perf_bpf_filter: Error: Unexpected item: %s\n",
67 perf_bpf_filter_text);
70 perf_bpf_filter_lval.path = perf_bpf_filter_text;
77 num_hex 0[Xx][0-9a-fA-F]+
80 ident [_a-zA-Z][_a-zA-Z0-9]+
84 {num_dec} { return value(10); }
85 {num_hex} { return value(16); }
88 ip { return sample(PBF_TERM_IP); }
89 id { return sample(PBF_TERM_ID); }
90 tid { return sample(PBF_TERM_TID); }
91 pid { return sample_part(PBF_TERM_TID, 1); }
92 cpu { return sample(PBF_TERM_CPU); }
93 time { return sample(PBF_TERM_TIME); }
94 addr { return sample(PBF_TERM_ADDR); }
95 period { return sample(PBF_TERM_PERIOD); }
96 txn { return sample(PBF_TERM_TRANSACTION); }
97 weight { return sample(PBF_TERM_WEIGHT); }
98 weight1 { return sample_part(PBF_TERM_WEIGHT_STRUCT, 1); }
99 weight2 { return sample_part(PBF_TERM_WEIGHT_STRUCT, 2); }
100 weight3 { return sample_part(PBF_TERM_WEIGHT_STRUCT, 3); }
101 ins_lat { return sample_part(PBF_TERM_WEIGHT_STRUCT, 2); } /* alias for weight2 */
102 p_stage_cyc { return sample_part(PBF_TERM_WEIGHT_STRUCT, 3); } /* alias for weight3 */
103 retire_lat { return sample_part(PBF_TERM_WEIGHT_STRUCT, 3); } /* alias for weight3 */
104 phys_addr { return sample(PBF_TERM_PHYS_ADDR); }
105 code_pgsz { return sample(PBF_TERM_CODE_PAGE_SIZE); }
106 data_pgsz { return sample(PBF_TERM_DATA_PAGE_SIZE); }
107 mem_op { return sample_part(PBF_TERM_DATA_SRC, 1); }
108 mem_lvlnum { return sample_part(PBF_TERM_DATA_SRC, 2); }
109 mem_lvl { return sample_part(PBF_TERM_DATA_SRC, 2); } /* alias for mem_lvlnum */
110 mem_snoop { return sample_part(PBF_TERM_DATA_SRC, 3); } /* include snoopx */
111 mem_remote { return sample_part(PBF_TERM_DATA_SRC, 4); }
112 mem_lock { return sample_part(PBF_TERM_DATA_SRC, 5); }
113 mem_dtlb { return sample_part(PBF_TERM_DATA_SRC, 6); }
114 mem_blk { return sample_part(PBF_TERM_DATA_SRC, 7); }
115 mem_hops { return sample_part(PBF_TERM_DATA_SRC, 8); }
116 uid { return sample(PBF_TERM_UID); }
117 gid { return sample(PBF_TERM_GID); }
118 cgroup { return sample_path(PBF_TERM_CGROUP); }
120 "==" { return operator(PBF_OP_EQ); }
121 "!=" { return operator(PBF_OP_NEQ); }
122 ">" { return operator(PBF_OP_GT); }
123 "<" { return operator(PBF_OP_LT); }
124 ">=" { return operator(PBF_OP_GE); }
125 "<=" { return operator(PBF_OP_LE); }
126 "&" { return operator(PBF_OP_AND); }
128 na { return constant(PERF_MEM_OP_NA); }
129 load { return constant(PERF_MEM_OP_LOAD); }
130 store { return constant(PERF_MEM_OP_STORE); }
131 pfetch { return constant(PERF_MEM_OP_PFETCH); }
132 exec { return constant(PERF_MEM_OP_EXEC); }
134 l1 { return constant(PERF_MEM_LVLNUM_L1); }
135 l2 { return constant(PERF_MEM_LVLNUM_L2); }
136 l3 { return constant(PERF_MEM_LVLNUM_L3); }
137 l4 { return constant(PERF_MEM_LVLNUM_L4); }
138 cxl { return constant(PERF_MEM_LVLNUM_CXL); }
139 io { return constant(PERF_MEM_LVLNUM_IO); }
140 any_cache { return constant(PERF_MEM_LVLNUM_ANY_CACHE); }
141 lfb { return constant(PERF_MEM_LVLNUM_LFB); }
142 ram { return constant(PERF_MEM_LVLNUM_RAM); }
143 pmem { return constant(PERF_MEM_LVLNUM_PMEM); }
145 none { return constant(PERF_MEM_SNOOP_NONE); }
146 hit { return constant(PERF_MEM_SNOOP_HIT); }
147 miss { return constant(PERF_MEM_SNOOP_MISS); }
148 hitm { return constant(PERF_MEM_SNOOP_HITM); }
149 fwd { return constant(PERF_MEM_SNOOPX_FWD); }
150 peer { return constant(PERF_MEM_SNOOPX_PEER); }
152 remote { return constant(PERF_MEM_REMOTE_REMOTE); }
154 locked { return constant(PERF_MEM_LOCK_LOCKED); }
156 l1_hit { return constant(PERF_MEM_TLB_L1 | PERF_MEM_TLB_HIT); }
157 l1_miss { return constant(PERF_MEM_TLB_L1 | PERF_MEM_TLB_MISS); }
158 l2_hit { return constant(PERF_MEM_TLB_L2 | PERF_MEM_TLB_HIT); }
159 l2_miss { return constant(PERF_MEM_TLB_L2 | PERF_MEM_TLB_MISS); }
160 any_hit { return constant(PERF_MEM_TLB_HIT); }
161 any_miss { return constant(PERF_MEM_TLB_MISS); }
162 walk { return constant(PERF_MEM_TLB_WK); }
163 os { return constant(PERF_MEM_TLB_OS); }
164 fault { return constant(PERF_MEM_TLB_OS); } /* alias for os */
166 by_data { return constant(PERF_MEM_BLK_DATA); }
167 by_addr { return constant(PERF_MEM_BLK_ADDR); }
169 hops0 { return constant(PERF_MEM_HOPS_0); }
170 hops1 { return constant(PERF_MEM_HOPS_1); }
171 hops2 { return constant(PERF_MEM_HOPS_2); }
172 hops3 { return constant(PERF_MEM_HOPS_3); }
175 "||" { return BFT_LOGICAL_OR; }
177 {path} { return path_or_error(); }