blob: 660fca05bc93bd8f724a9f3cef3f0f3d86abb983 [file] [log] [blame]
Jiri Olsa89812fc2012-03-15 20:09:15 +01001
Zheng Yanac20de6f2012-06-15 14:31:39 +08002%option reentrant
3%option bison-bridge
Jiri Olsa89812fc2012-03-15 20:09:15 +01004%option prefix="parse_events_"
Jiri Olsa08d2f762012-05-21 09:12:52 +02005%option stack
Jiri Olsa6297d422015-04-22 21:10:17 +02006%option bison-locations
7%option yylineno
Jiri Olsa89812fc2012-03-15 20:09:15 +01008
9%{
10#include <errno.h>
11#include "../perf.h"
Jiri Olsa8f707d82012-03-15 20:09:16 +010012#include "parse-events.h"
Wang Nane571e022016-02-22 09:10:35 +000013#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010014
Zheng Yanac20de6f2012-06-15 14:31:39 +080015char *parse_events_get_text(yyscan_t yyscanner);
16YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
17
18static int __value(YYSTYPE *yylval, char *str, int base, int token)
Jiri Olsa89812fc2012-03-15 20:09:15 +010019{
Robert Richterb527bab2012-08-07 19:43:13 +020020 u64 num;
Jiri Olsa89812fc2012-03-15 20:09:15 +010021
22 errno = 0;
Robert Richterb527bab2012-08-07 19:43:13 +020023 num = strtoull(str, NULL, base);
Jiri Olsa89812fc2012-03-15 20:09:15 +010024 if (errno)
25 return PE_ERROR;
26
Zheng Yanac20de6f2012-06-15 14:31:39 +080027 yylval->num = num;
Jiri Olsa89812fc2012-03-15 20:09:15 +010028 return token;
29}
30
Zheng Yanac20de6f2012-06-15 14:31:39 +080031static int value(yyscan_t scanner, int base)
Jiri Olsa89812fc2012-03-15 20:09:15 +010032{
Zheng Yanac20de6f2012-06-15 14:31:39 +080033 YYSTYPE *yylval = parse_events_get_lval(scanner);
34 char *text = parse_events_get_text(scanner);
35
36 return __value(yylval, text, base, PE_VALUE);
Jiri Olsa89812fc2012-03-15 20:09:15 +010037}
38
Zheng Yanac20de6f2012-06-15 14:31:39 +080039static int raw(yyscan_t scanner)
Jiri Olsa89812fc2012-03-15 20:09:15 +010040{
Zheng Yanac20de6f2012-06-15 14:31:39 +080041 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);
Jiri Olsa89812fc2012-03-15 20:09:15 +010045}
46
Zheng Yanac20de6f2012-06-15 14:31:39 +080047static int str(yyscan_t scanner, int token)
Jiri Olsa89812fc2012-03-15 20:09:15 +010048{
Zheng Yanac20de6f2012-06-15 14:31:39 +080049 YYSTYPE *yylval = parse_events_get_lval(scanner);
50 char *text = parse_events_get_text(scanner);
51
52 yylval->str = strdup(text);
Jiri Olsa89812fc2012-03-15 20:09:15 +010053 return token;
54}
55
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060056/*
57 * This function is called when the parser gets two kind of input:
58 *
59 * @cfg1 or @cfg2=config
60 *
61 * The leading '@' is stripped off before 'cfg1' and 'cfg2=config' are given to
62 * bison. In the latter case it is necessary to keep the string intact so that
63 * the PMU kernel driver can determine what configurable is associated to
64 * 'config'.
65 */
66static int drv_str(yyscan_t scanner, int token)
67{
68 YYSTYPE *yylval = parse_events_get_lval(scanner);
69 char *text = parse_events_get_text(scanner);
70
71 /* Strip off the '@' */
72 yylval->str = strdup(text + 1);
73 return token;
74}
75
Jiri Olsa6297d422015-04-22 21:10:17 +020076#define REWIND(__alloc) \
77do { \
78 YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \
79 char *text = parse_events_get_text(yyscanner); \
80 \
81 if (__alloc) \
82 __yylval->str = strdup(text); \
83 \
84 yycolumn -= strlen(text); \
85 yyless(0); \
86} while (0)
87
Kan Liangba32a452014-10-07 11:08:51 -040088static int pmu_str_check(yyscan_t scanner)
89{
90 YYSTYPE *yylval = parse_events_get_lval(scanner);
91 char *text = parse_events_get_text(scanner);
92
93 yylval->str = strdup(text);
94 switch (perf_pmu__parse_check(text)) {
95 case PMU_EVENT_SYMBOL_PREFIX:
96 return PE_PMU_EVENT_PRE;
97 case PMU_EVENT_SYMBOL_SUFFIX:
98 return PE_PMU_EVENT_SUF;
99 case PMU_EVENT_SYMBOL:
100 return PE_KERNEL_PMU_EVENT;
101 default:
102 return PE_NAME;
103 }
104}
105
Zheng Yanac20de6f2012-06-15 14:31:39 +0800106static int sym(yyscan_t scanner, int type, int config)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100107{
Zheng Yanac20de6f2012-06-15 14:31:39 +0800108 YYSTYPE *yylval = parse_events_get_lval(scanner);
109
110 yylval->num = (type << 16) + config;
Jiri Olsacf3506d2012-07-04 00:00:43 +0200111 return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100112}
113
Zheng Yanac20de6f2012-06-15 14:31:39 +0800114static int term(yyscan_t scanner, int type)
Jiri Olsa8f707d82012-03-15 20:09:16 +0100115{
Zheng Yanac20de6f2012-06-15 14:31:39 +0800116 YYSTYPE *yylval = parse_events_get_lval(scanner);
117
118 yylval->num = type;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100119 return PE_TERM;
120}
121
Jiri Olsa6297d422015-04-22 21:10:17 +0200122#define YY_USER_ACTION \
123do { \
124 yylloc->last_column = yylloc->first_column; \
125 yylloc->first_column = yycolumn; \
126 yycolumn += yyleng; \
127} while (0);
128
Jiri Olsa89812fc2012-03-15 20:09:15 +0100129%}
130
Jiri Olsa08d2f762012-05-21 09:12:52 +0200131%x mem
Robert Richterac2ba9f2012-08-16 21:10:21 +0200132%s config
133%x event
Wang Nane571e022016-02-22 09:10:35 +0000134%x array
Robert Richterac2ba9f2012-08-16 21:10:21 +0200135
136group [^,{}/]*[{][^}]*[}][^,{}/]*
137event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
138event [^,{}/]+
Wang Nan2d470b62016-10-08 04:16:25 +0000139bpf_object [^,{}]+\.(o|bpf)
140bpf_source [^,{}]+\.c
Jiri Olsa08d2f762012-05-21 09:12:52 +0200141
Jiri Olsa89812fc2012-03-15 20:09:15 +0100142num_dec [0-9]+
143num_hex 0x[a-fA-F0-9]+
144num_raw_hex [a-fA-F0-9]+
Andi Kleen5b021dd2015-06-10 00:25:11 -0700145name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
Wang Nana34f3be2016-02-22 09:10:31 +0000146name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600147drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
Michael Ellermane9a7c412013-08-06 23:28:05 +1000148/* If you add a modifier you need to update check_modifier() */
Jiri Olsa7f94af72015-10-05 20:06:05 +0200149modifier_event [ukhpPGHSDI]+
Jiri Olsa75827322012-06-29 09:22:54 +0200150modifier_bp [rwx]{1,3}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100151
152%%
Jiri Olsa90e2b222012-06-15 14:31:40 +0800153
154%{
155 {
156 int start_token;
157
Robert Richterac2ba9f2012-08-16 21:10:21 +0200158 start_token = parse_events_get_extra(yyscanner);
159
160 if (start_token == PE_START_TERMS)
161 BEGIN(config);
162 else if (start_token == PE_START_EVENTS)
163 BEGIN(event);
164
Jiri Olsa90e2b222012-06-15 14:31:40 +0800165 if (start_token) {
166 parse_events_set_extra(NULL, yyscanner);
Jiri Olsa6297d422015-04-22 21:10:17 +0200167 /*
168 * The flex parser does not init locations variable
169 * via the scan_string interface, so we need do the
170 * init in here.
171 */
172 yycolumn = 0;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800173 return start_token;
174 }
175 }
176%}
177
Robert Richterac2ba9f2012-08-16 21:10:21 +0200178<event>{
179
180{group} {
Jiri Olsa6297d422015-04-22 21:10:17 +0200181 BEGIN(INITIAL);
182 REWIND(0);
Robert Richterac2ba9f2012-08-16 21:10:21 +0200183 }
184
185{event_pmu} |
Wang Nan84c86ca2015-10-14 12:41:14 +0000186{bpf_object} |
Wang Nand509db02015-10-14 12:41:20 +0000187{bpf_source} |
Robert Richterac2ba9f2012-08-16 21:10:21 +0200188{event} {
Jiri Olsa6297d422015-04-22 21:10:17 +0200189 BEGIN(INITIAL);
190 REWIND(1);
Robert Richterac2ba9f2012-08-16 21:10:21 +0200191 return PE_EVENT_NAME;
192 }
193
Robert Richterac2ba9f2012-08-16 21:10:21 +0200194<<EOF>> {
Jiri Olsa6297d422015-04-22 21:10:17 +0200195 BEGIN(INITIAL);
196 REWIND(0);
Robert Richterac2ba9f2012-08-16 21:10:21 +0200197 }
198
199}
200
Wang Nane571e022016-02-22 09:10:35 +0000201<array>{
202"]" { BEGIN(config); return ']'; }
203{num_dec} { return value(yyscanner, 10); }
204{num_hex} { return value(yyscanner, 16); }
205, { return ','; }
206"\.\.\." { return PE_ARRAY_RANGE; }
207}
208
Jiri Olsa82004222013-09-27 18:29:58 +0200209<config>{
Jiri Olsae64b0202015-04-22 21:10:21 +0200210 /*
Wang Nan17cb5f82016-02-19 11:43:57 +0000211 * Please update config_term_names when new static term is added.
Jiri Olsae64b0202015-04-22 21:10:21 +0200212 */
Jiri Olsa82004222013-09-27 18:29:58 +0200213config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
214config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
215config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
216name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
217period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
Namhyung Kim09af2a52015-08-09 15:45:23 +0900218freq { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ); }
Jiri Olsa82004222013-09-27 18:29:58 +0200219branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
Kan Liang32067712015-08-04 04:30:19 -0400220time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
Kan Liangd457c962015-08-11 06:30:47 -0400221call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
222stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
Arnaldo Carvalho de Melo792d48b2016-04-28 19:03:42 -0300223max-stack { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_STACK); }
Wang Nan374ce932015-10-28 10:55:02 +0000224inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
225no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
Wang Nan626a6b72016-07-14 08:34:45 +0000226overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
227no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
Jiri Olsa82004222013-09-27 18:29:58 +0200228, { return ','; }
229"/" { BEGIN(INITIAL); return '/'; }
230{name_minus} { return str(yyscanner, PE_NAME); }
Wang Nane571e022016-02-22 09:10:35 +0000231\[all\] { return PE_ARRAY_ALL; }
232"[" { BEGIN(array); return '['; }
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600233@{drv_cfg_term} { return drv_str(yyscanner, PE_DRV_CFG_TERM); }
Jiri Olsa82004222013-09-27 18:29:58 +0200234}
235
236<mem>{
237{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
238: { return ':'; }
Jacob Shin3741eb92014-05-29 17:26:51 +0200239"/" { return '/'; }
Jiri Olsa82004222013-09-27 18:29:58 +0200240{num_dec} { return value(yyscanner, 10); }
241{num_hex} { return value(yyscanner, 16); }
242 /*
243 * We need to separate 'mem:' scanner part, in order to get specific
244 * modifier bits parsed out. Otherwise we would need to handle PE_NAME
245 * and we'd need to parse it manually. During the escape from <mem>
246 * state we need to put the escaping char back, so we dont miss it.
247 */
248. { unput(*yytext); BEGIN(INITIAL); }
249 /*
250 * We destroy the scanner after reaching EOF,
251 * but anyway just to be sure get back to INIT state.
252 */
253<<EOF>> { BEGIN(INITIAL); }
254}
255
Zheng Yanac20de6f2012-06-15 14:31:39 +0800256cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
257stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
258stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
259instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
260cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
261cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
262branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
263branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
264bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
265ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
266cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
267task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
268page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
269minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
270major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
271context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
272cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
273alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
274emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
Adrian Hunterd22d1a22013-08-31 21:50:52 +0300275dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
Wang Nan03e0a7d2016-02-22 09:10:37 +0000276bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100277
Kan Liangba32a452014-10-07 11:08:51 -0400278 /*
279 * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately.
280 * Because the prefix cycles is mixed up with cpu-cycles.
281 * loads and stores are mixed up with cache event
282 */
283cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
284cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
285mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
286mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
Andi Kleen44b1e602016-05-30 12:49:42 -0300287topdown-[a-z-]+ { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
Kan Liangba32a452014-10-07 11:08:51 -0400288
Jiri Olsa89812fc2012-03-15 20:09:15 +0100289L1-dcache|l1-d|l1d|L1-data |
290L1-icache|l1-i|l1i|L1-instruction |
291LLC|L2 |
292dTLB|d-tlb|Data-TLB |
293iTLB|i-tlb|Instruction-TLB |
294branch|branches|bpu|btb|bpc |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800295node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100296
297load|loads|read |
298store|stores|write |
299prefetch|prefetches |
300speculative-read|speculative-load |
301refs|Reference|ops|access |
Zheng Yanac20de6f2012-06-15 14:31:39 +0800302misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100303
Jiri Olsa08d2f762012-05-21 09:12:52 +0200304mem: { BEGIN(mem); return PE_PREFIX_MEM; }
Zheng Yanac20de6f2012-06-15 14:31:39 +0800305r{num_raw_hex} { return raw(yyscanner); }
306{num_dec} { return value(yyscanner, 10); }
307{num_hex} { return value(yyscanner, 16); }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100308
Zheng Yanac20de6f2012-06-15 14:31:39 +0800309{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
Wang Nan84c86ca2015-10-14 12:41:14 +0000310{bpf_object} { return str(yyscanner, PE_BPF_OBJECT); }
Wang Nand509db02015-10-14 12:41:20 +0000311{bpf_source} { return str(yyscanner, PE_BPF_SOURCE); }
Kan Liangba32a452014-10-07 11:08:51 -0400312{name} { return pmu_str_check(yyscanner); }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200313"/" { BEGIN(config); return '/'; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100314- { return '-'; }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200315, { BEGIN(event); return ','; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100316: { return ':'; }
Robert Richterac2ba9f2012-08-16 21:10:21 +0200317"{" { BEGIN(event); return '{'; }
Jiri Olsa89efb022012-08-08 12:14:14 +0200318"}" { return '}'; }
Jiri Olsa89812fc2012-03-15 20:09:15 +0100319= { return '='; }
Jiri Olsa8c5f0a82012-07-04 00:00:39 +0200320\n { }
Jiri Olsa82004222013-09-27 18:29:58 +0200321. { }
Jiri Olsa08d2f762012-05-21 09:12:52 +0200322
Jiri Olsa89812fc2012-03-15 20:09:15 +0100323%%
324
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300325int parse_events_wrap(void *scanner __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100326{
327 return 1;
328}