]>
Commit | Line | Data |
---|---|---|
89812fc8 | 1 | |
ac20de6f ZY |
2 | %option reentrant |
3 | %option bison-bridge | |
89812fc8 | 4 | %option prefix="parse_events_" |
08d2f762 | 5 | %option stack |
6297d423 JO |
6 | %option bison-locations |
7 | %option yylineno | |
89812fc8 JO |
8 | |
9 | %{ | |
10 | #include <errno.h> | |
11 | #include "../perf.h" | |
12 | #include "parse-events-bison.h" | |
8f707d84 | 13 | #include "parse-events.h" |
89812fc8 | 14 | |
ac20de6f ZY |
15 | char *parse_events_get_text(yyscan_t yyscanner); |
16 | YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); | |
17 | ||
18 | static int __value(YYSTYPE *yylval, char *str, int base, int token) | |
89812fc8 | 19 | { |
b527bab5 | 20 | u64 num; |
89812fc8 JO |
21 | |
22 | errno = 0; | |
b527bab5 | 23 | num = strtoull(str, NULL, base); |
89812fc8 JO |
24 | if (errno) |
25 | return PE_ERROR; | |
26 | ||
ac20de6f | 27 | yylval->num = num; |
89812fc8 JO |
28 | return token; |
29 | } | |
30 | ||
ac20de6f | 31 | static int value(yyscan_t scanner, int base) |
89812fc8 | 32 | { |
ac20de6f ZY |
33 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
34 | char *text = parse_events_get_text(scanner); | |
35 | ||
36 | return __value(yylval, text, base, PE_VALUE); | |
89812fc8 JO |
37 | } |
38 | ||
ac20de6f | 39 | static int raw(yyscan_t scanner) |
89812fc8 | 40 | { |
ac20de6f ZY |
41 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
42 | char *text = parse_events_get_text(scanner); | |
43 | ||
44 | return __value(yylval, text + 1, 16, PE_RAW); | |
89812fc8 JO |
45 | } |
46 | ||
ac20de6f | 47 | static int str(yyscan_t scanner, int token) |
89812fc8 | 48 | { |
ac20de6f ZY |
49 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
50 | char *text = parse_events_get_text(scanner); | |
51 | ||
52 | yylval->str = strdup(text); | |
89812fc8 JO |
53 | return token; |
54 | } | |
55 | ||
6297d423 JO |
56 | #define REWIND(__alloc) \ |
57 | do { \ | |
58 | YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ | |
59 | char *text = parse_events_get_text(yyscanner); \ | |
60 | \ | |
61 | if (__alloc) \ | |
62 | __yylval->str = strdup(text); \ | |
63 | \ | |
64 | yycolumn -= strlen(text); \ | |
65 | yyless(0); \ | |
66 | } while (0) | |
67 | ||
ba32a451 KL |
68 | static int pmu_str_check(yyscan_t scanner) |
69 | { | |
70 | YYSTYPE *yylval = parse_events_get_lval(scanner); | |
71 | char *text = parse_events_get_text(scanner); | |
72 | ||
73 | yylval->str = strdup(text); | |
74 | switch (perf_pmu__parse_check(text)) { | |
75 | case PMU_EVENT_SYMBOL_PREFIX: | |
76 | return PE_PMU_EVENT_PRE; | |
77 | case PMU_EVENT_SYMBOL_SUFFIX: | |
78 | return PE_PMU_EVENT_SUF; | |
79 | case PMU_EVENT_SYMBOL: | |
80 | return PE_KERNEL_PMU_EVENT; | |
81 | default: | |
82 | return PE_NAME; | |
83 | } | |
84 | } | |
85 | ||
ac20de6f | 86 | static int sym(yyscan_t scanner, int type, int config) |
89812fc8 | 87 | { |
ac20de6f ZY |
88 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
89 | ||
90 | yylval->num = (type << 16) + config; | |
cf3506dc | 91 | return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; |
89812fc8 JO |
92 | } |
93 | ||
ac20de6f | 94 | static int term(yyscan_t scanner, int type) |
8f707d84 | 95 | { |
ac20de6f ZY |
96 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
97 | ||
98 | yylval->num = type; | |
8f707d84 JO |
99 | return PE_TERM; |
100 | } | |
101 | ||
6297d423 JO |
102 | #define YY_USER_ACTION \ |
103 | do { \ | |
104 | yylloc->last_column = yylloc->first_column; \ | |
105 | yylloc->first_column = yycolumn; \ | |
106 | yycolumn += yyleng; \ | |
107 | } while (0); | |
108 | ||
89812fc8 JO |
109 | %} |
110 | ||
08d2f762 | 111 | %x mem |
ac2ba9f3 RR |
112 | %s config |
113 | %x event | |
114 | ||
115 | group [^,{}/]*[{][^}]*[}][^,{}/]* | |
116 | event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* | |
117 | event [^,{}/]+ | |
08d2f762 | 118 | |
89812fc8 JO |
119 | num_dec [0-9]+ |
120 | num_hex 0x[a-fA-F0-9]+ | |
121 | num_raw_hex [a-fA-F0-9]+ | |
5b021ddf AK |
122 | name [a-zA-Z_*?][a-zA-Z0-9_*?.]* |
123 | name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]* | |
e9a7c414 | 124 | /* If you add a modifier you need to update check_modifier() */ |
a1e12da4 | 125 | modifier_event [ukhpGHSDI]+ |
7582732f | 126 | modifier_bp [rwx]{1,3} |
89812fc8 JO |
127 | |
128 | %% | |
90e2b22d JO |
129 | |
130 | %{ | |
131 | { | |
132 | int start_token; | |
133 | ||
ac2ba9f3 RR |
134 | start_token = parse_events_get_extra(yyscanner); |
135 | ||
136 | if (start_token == PE_START_TERMS) | |
137 | BEGIN(config); | |
138 | else if (start_token == PE_START_EVENTS) | |
139 | BEGIN(event); | |
140 | ||
90e2b22d JO |
141 | if (start_token) { |
142 | parse_events_set_extra(NULL, yyscanner); | |
6297d423 JO |
143 | /* |
144 | * The flex parser does not init locations variable | |
145 | * via the scan_string interface, so we need do the | |
146 | * init in here. | |
147 | */ | |
148 | yycolumn = 0; | |
90e2b22d JO |
149 | return start_token; |
150 | } | |
151 | } | |
152 | %} | |
153 | ||
ac2ba9f3 RR |
154 | <event>{ |
155 | ||
156 | {group} { | |
6297d423 JO |
157 | BEGIN(INITIAL); |
158 | REWIND(0); | |
ac2ba9f3 RR |
159 | } |
160 | ||
161 | {event_pmu} | | |
162 | {event} { | |
6297d423 JO |
163 | BEGIN(INITIAL); |
164 | REWIND(1); | |
ac2ba9f3 RR |
165 | return PE_EVENT_NAME; |
166 | } | |
167 | ||
ac2ba9f3 | 168 | <<EOF>> { |
6297d423 JO |
169 | BEGIN(INITIAL); |
170 | REWIND(0); | |
ac2ba9f3 RR |
171 | } |
172 | ||
173 | } | |
174 | ||
82004223 | 175 | <config>{ |
e64b020b JO |
176 | /* |
177 | * Please update formats_error_string any time | |
178 | * new static term is added. | |
179 | */ | |
82004223 JO |
180 | config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } |
181 | config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } | |
182 | config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } | |
183 | name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } | |
184 | period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } | |
185 | branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } | |
186 | , { return ','; } | |
187 | "/" { BEGIN(INITIAL); return '/'; } | |
188 | {name_minus} { return str(yyscanner, PE_NAME); } | |
189 | } | |
190 | ||
191 | <mem>{ | |
192 | {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } | |
193 | : { return ':'; } | |
3741eb9f | 194 | "/" { return '/'; } |
82004223 JO |
195 | {num_dec} { return value(yyscanner, 10); } |
196 | {num_hex} { return value(yyscanner, 16); } | |
197 | /* | |
198 | * We need to separate 'mem:' scanner part, in order to get specific | |
199 | * modifier bits parsed out. Otherwise we would need to handle PE_NAME | |
200 | * and we'd need to parse it manually. During the escape from <mem> | |
201 | * state we need to put the escaping char back, so we dont miss it. | |
202 | */ | |
203 | . { unput(*yytext); BEGIN(INITIAL); } | |
204 | /* | |
205 | * We destroy the scanner after reaching EOF, | |
206 | * but anyway just to be sure get back to INIT state. | |
207 | */ | |
208 | <<EOF>> { BEGIN(INITIAL); } | |
209 | } | |
210 | ||
ac20de6f ZY |
211 | cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
212 | stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } | |
213 | stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } | |
214 | instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } | |
215 | cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } | |
216 | cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } | |
217 | branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } | |
218 | branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } | |
219 | bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } | |
220 | ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } | |
221 | cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } | |
222 | task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } | |
223 | page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } | |
224 | minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } | |
225 | major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } | |
226 | context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } | |
227 | cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } | |
228 | alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } | |
229 | emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } | |
d22d1a2a | 230 | dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } |
89812fc8 | 231 | |
ba32a451 KL |
232 | /* |
233 | * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately. | |
234 | * Because the prefix cycles is mixed up with cpu-cycles. | |
235 | * loads and stores are mixed up with cache event | |
236 | */ | |
237 | cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); } | |
238 | cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); } | |
239 | mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); } | |
240 | mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); } | |
241 | ||
89812fc8 JO |
242 | L1-dcache|l1-d|l1d|L1-data | |
243 | L1-icache|l1-i|l1i|L1-instruction | | |
244 | LLC|L2 | | |
245 | dTLB|d-tlb|Data-TLB | | |
246 | iTLB|i-tlb|Instruction-TLB | | |
247 | branch|branches|bpu|btb|bpc | | |
ac20de6f | 248 | node { return str(yyscanner, PE_NAME_CACHE_TYPE); } |
89812fc8 JO |
249 | |
250 | load|loads|read | | |
251 | store|stores|write | | |
252 | prefetch|prefetches | | |
253 | speculative-read|speculative-load | | |
254 | refs|Reference|ops|access | | |
ac20de6f | 255 | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } |
89812fc8 | 256 | |
08d2f762 | 257 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } |
ac20de6f ZY |
258 | r{num_raw_hex} { return raw(yyscanner); } |
259 | {num_dec} { return value(yyscanner, 10); } | |
260 | {num_hex} { return value(yyscanner, 16); } | |
89812fc8 | 261 | |
ac20de6f | 262 | {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } |
ba32a451 | 263 | {name} { return pmu_str_check(yyscanner); } |
ac2ba9f3 | 264 | "/" { BEGIN(config); return '/'; } |
89812fc8 | 265 | - { return '-'; } |
ac2ba9f3 | 266 | , { BEGIN(event); return ','; } |
89812fc8 | 267 | : { return ':'; } |
ac2ba9f3 | 268 | "{" { BEGIN(event); return '{'; } |
89efb029 | 269 | "}" { return '}'; } |
89812fc8 | 270 | = { return '='; } |
8c5f0a84 | 271 | \n { } |
82004223 | 272 | . { } |
08d2f762 | 273 | |
89812fc8 JO |
274 | %% |
275 | ||
1d037ca1 | 276 | int parse_events_wrap(void *scanner __maybe_unused) |
89812fc8 JO |
277 | { |
278 | return 1; | |
279 | } |