ARM: dts: kirkwood: gpio-leds fixes for linkstation ls-wvl/vl
[linux/fpc-iii.git] / tools / perf / util / parse-events.l
blob58c5831ffd5c22133f48a4c1a3a07721c71362fa
2 %option reentrant
3 %option bison-bridge
4 %option prefix="parse_events_"
5 %option stack
6 %option bison-locations
7 %option yylineno
9 %{
10 #include <errno.h>
11 #include "../perf.h"
12 #include "parse-events-bison.h"
13 #include "parse-events.h"
15 char *parse_events_get_text(yyscan_t yyscanner);
16 YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
18 static int __value(YYSTYPE *yylval, char *str, int base, int token)
20         u64 num;
22         errno = 0;
23         num = strtoull(str, NULL, base);
24         if (errno)
25                 return PE_ERROR;
27         yylval->num = num;
28         return token;
31 static int value(yyscan_t scanner, int base)
33         YYSTYPE *yylval = parse_events_get_lval(scanner);
34         char *text = parse_events_get_text(scanner);
36         return __value(yylval, text, base, PE_VALUE);
39 static int raw(yyscan_t scanner)
41         YYSTYPE *yylval = parse_events_get_lval(scanner);
42         char *text = parse_events_get_text(scanner);
44         return __value(yylval, text + 1, 16, PE_RAW);
47 static int str(yyscan_t scanner, int token)
49         YYSTYPE *yylval = parse_events_get_lval(scanner);
50         char *text = parse_events_get_text(scanner);
52         yylval->str = strdup(text);
53         return token;
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)
68 static int pmu_str_check(yyscan_t scanner)
70         YYSTYPE *yylval = parse_events_get_lval(scanner);
71         char *text = parse_events_get_text(scanner);
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         }
86 static int sym(yyscan_t scanner, int type, int config)
88         YYSTYPE *yylval = parse_events_get_lval(scanner);
90         yylval->num = (type << 16) + config;
91         return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
94 static int term(yyscan_t scanner, int type)
96         YYSTYPE *yylval = parse_events_get_lval(scanner);
98         yylval->num = type;
99         return PE_TERM;
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);
111 %x mem
112 %s config
113 %x event
115 group           [^,{}/]*[{][^}]*[}][^,{}/]*
116 event_pmu       [^,{}/]+[/][^/]*[/][^,{}/]*
117 event           [^,{}/]+
118 bpf_object      .*\.(o|bpf)
119 bpf_source      .*\.c
121 num_dec         [0-9]+
122 num_hex         0x[a-fA-F0-9]+
123 num_raw_hex     [a-fA-F0-9]+
124 name            [a-zA-Z_*?][a-zA-Z0-9_*?.]*
125 name_minus      [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
126 /* If you add a modifier you need to update check_modifier() */
127 modifier_event  [ukhpPGHSDI]+
128 modifier_bp     [rwx]{1,3}
133         {
134                 int start_token;
136                 start_token = parse_events_get_extra(yyscanner);
138                 if (start_token == PE_START_TERMS)
139                         BEGIN(config);
140                 else if (start_token == PE_START_EVENTS)
141                         BEGIN(event);
143                 if (start_token) {
144                         parse_events_set_extra(NULL, yyscanner);
145                         /*
146                          * The flex parser does not init locations variable
147                          * via the scan_string interface, so we need do the
148                          * init in here.
149                          */
150                         yycolumn = 0;
151                         return start_token;
152                 }
153          }
156 <event>{
158 {group}         {
159                         BEGIN(INITIAL);
160                         REWIND(0);
161                 }
163 {event_pmu}     |
164 {bpf_object}    |
165 {bpf_source}    |
166 {event}         {
167                         BEGIN(INITIAL);
168                         REWIND(1);
169                         return PE_EVENT_NAME;
170                 }
172 <<EOF>>         {
173                         BEGIN(INITIAL);
174                         REWIND(0);
175                 }
179 <config>{
180         /*
181          * Please update parse_events_formats_error_string any time
182          * new static term is added.
183          */
184 config                  { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
185 config1                 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
186 config2                 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
187 name                    { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
188 period                  { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
189 freq                    { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ); }
190 branch_type             { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
191 time                    { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
192 call-graph              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
193 stack-size              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
194 inherit                 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
195 no-inherit              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
196 ,                       { return ','; }
197 "/"                     { BEGIN(INITIAL); return '/'; }
198 {name_minus}            { return str(yyscanner, PE_NAME); }
201 <mem>{
202 {modifier_bp}           { return str(yyscanner, PE_MODIFIER_BP); }
203 :                       { return ':'; }
204 "/"                     { return '/'; }
205 {num_dec}               { return value(yyscanner, 10); }
206 {num_hex}               { return value(yyscanner, 16); }
207         /*
208          * We need to separate 'mem:' scanner part, in order to get specific
209          * modifier bits parsed out. Otherwise we would need to handle PE_NAME
210          * and we'd need to parse it manually. During the escape from <mem>
211          * state we need to put the escaping char back, so we dont miss it.
212          */
213 .                       { unput(*yytext); BEGIN(INITIAL); }
214         /*
215          * We destroy the scanner after reaching EOF,
216          * but anyway just to be sure get back to INIT state.
217          */
218 <<EOF>>                 { BEGIN(INITIAL); }
221 cpu-cycles|cycles                               { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
222 stalled-cycles-frontend|idle-cycles-frontend    { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
223 stalled-cycles-backend|idle-cycles-backend      { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
224 instructions                                    { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
225 cache-references                                { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
226 cache-misses                                    { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
227 branch-instructions|branches                    { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
228 branch-misses                                   { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
229 bus-cycles                                      { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
230 ref-cycles                                      { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
231 cpu-clock                                       { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
232 task-clock                                      { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
233 page-faults|faults                              { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
234 minor-faults                                    { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
235 major-faults                                    { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
236 context-switches|cs                             { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
237 cpu-migrations|migrations                       { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
238 alignment-faults                                { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
239 emulation-faults                                { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
240 dummy                                           { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
242         /*
243          * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately.
244          * Because the prefix cycles is mixed up with cpu-cycles.
245          * loads and stores are mixed up with cache event
246          */
247 cycles-ct                                       { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
248 cycles-t                                        { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
249 mem-loads                                       { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
250 mem-stores                                      { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
252 L1-dcache|l1-d|l1d|L1-data              |
253 L1-icache|l1-i|l1i|L1-instruction       |
254 LLC|L2                                  |
255 dTLB|d-tlb|Data-TLB                     |
256 iTLB|i-tlb|Instruction-TLB              |
257 branch|branches|bpu|btb|bpc             |
258 node                                    { return str(yyscanner, PE_NAME_CACHE_TYPE); }
260 load|loads|read                         |
261 store|stores|write                      |
262 prefetch|prefetches                     |
263 speculative-read|speculative-load       |
264 refs|Reference|ops|access               |
265 misses|miss                             { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
267 mem:                    { BEGIN(mem); return PE_PREFIX_MEM; }
268 r{num_raw_hex}          { return raw(yyscanner); }
269 {num_dec}               { return value(yyscanner, 10); }
270 {num_hex}               { return value(yyscanner, 16); }
272 {modifier_event}        { return str(yyscanner, PE_MODIFIER_EVENT); }
273 {bpf_object}            { return str(yyscanner, PE_BPF_OBJECT); }
274 {bpf_source}            { return str(yyscanner, PE_BPF_SOURCE); }
275 {name}                  { return pmu_str_check(yyscanner); }
276 "/"                     { BEGIN(config); return '/'; }
277 -                       { return '-'; }
278 ,                       { BEGIN(event); return ','; }
279 :                       { return ':'; }
280 "{"                     { BEGIN(event); return '{'; }
281 "}"                     { return '}'; }
282 =                       { return '='; }
283 \n                      { }
284 .                       { }
288 int parse_events_wrap(void *scanner __maybe_unused)
290         return 1;