Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 2 | %option reentrant |
| 3 | %option bison-bridge |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 4 | %option prefix="parse_events_" |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 5 | %option stack |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 6 | |
| 7 | %{ |
| 8 | #include <errno.h> |
| 9 | #include "../perf.h" |
| 10 | #include "parse-events-bison.h" |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 11 | #include "parse-events.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 12 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 13 | char *parse_events_get_text(yyscan_t yyscanner); |
| 14 | YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); |
| 15 | |
| 16 | static int __value(YYSTYPE *yylval, char *str, int base, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 17 | { |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 18 | u64 num; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 19 | |
| 20 | errno = 0; |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 21 | num = strtoull(str, NULL, base); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 22 | if (errno) |
| 23 | return PE_ERROR; |
| 24 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 25 | yylval->num = num; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 26 | return token; |
| 27 | } |
| 28 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 29 | static int value(yyscan_t scanner, int base) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 30 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 31 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 32 | char *text = parse_events_get_text(scanner); |
| 33 | |
| 34 | return __value(yylval, text, base, PE_VALUE); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 37 | static int raw(yyscan_t scanner) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 38 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 39 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 40 | char *text = parse_events_get_text(scanner); |
| 41 | |
| 42 | return __value(yylval, text + 1, 16, PE_RAW); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 45 | static int str(yyscan_t scanner, int token) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 46 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 47 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 48 | char *text = parse_events_get_text(scanner); |
| 49 | |
| 50 | yylval->str = strdup(text); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 51 | return token; |
| 52 | } |
| 53 | |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 54 | static int pmu_str_check(yyscan_t scanner) |
| 55 | { |
| 56 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 57 | char *text = parse_events_get_text(scanner); |
| 58 | |
| 59 | yylval->str = strdup(text); |
| 60 | switch (perf_pmu__parse_check(text)) { |
| 61 | case PMU_EVENT_SYMBOL_PREFIX: |
| 62 | return PE_PMU_EVENT_PRE; |
| 63 | case PMU_EVENT_SYMBOL_SUFFIX: |
| 64 | return PE_PMU_EVENT_SUF; |
| 65 | case PMU_EVENT_SYMBOL: |
| 66 | return PE_KERNEL_PMU_EVENT; |
| 67 | default: |
| 68 | return PE_NAME; |
| 69 | } |
| 70 | } |
| 71 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 72 | static int sym(yyscan_t scanner, int type, int config) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 73 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 74 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 75 | |
| 76 | yylval->num = (type << 16) + config; |
Jiri Olsa | cf3506d | 2012-07-04 00:00:43 +0200 | [diff] [blame] | 77 | return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 80 | static int term(yyscan_t scanner, int type) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 81 | { |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 82 | YYSTYPE *yylval = parse_events_get_lval(scanner); |
| 83 | |
| 84 | yylval->num = type; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 85 | return PE_TERM; |
| 86 | } |
| 87 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 88 | %} |
| 89 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 90 | %x mem |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 91 | %s config |
| 92 | %x event |
| 93 | |
| 94 | group [^,{}/]*[{][^}]*[}][^,{}/]* |
| 95 | event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* |
| 96 | event [^,{}/]+ |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 97 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 98 | num_dec [0-9]+ |
| 99 | num_hex 0x[a-fA-F0-9]+ |
| 100 | num_raw_hex [a-fA-F0-9]+ |
| 101 | name [a-zA-Z_*?][a-zA-Z0-9_*?]* |
Andi Kleen | eef9ba9 | 2012-11-05 14:50:52 +0100 | [diff] [blame] | 102 | name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]* |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 103 | /* If you add a modifier you need to update check_modifier() */ |
| 104 | modifier_event [ukhpGHSD]+ |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 105 | modifier_bp [rwx]{1,3} |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 106 | |
| 107 | %% |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 108 | |
| 109 | %{ |
| 110 | { |
| 111 | int start_token; |
| 112 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 113 | start_token = parse_events_get_extra(yyscanner); |
| 114 | |
| 115 | if (start_token == PE_START_TERMS) |
| 116 | BEGIN(config); |
| 117 | else if (start_token == PE_START_EVENTS) |
| 118 | BEGIN(event); |
| 119 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 120 | if (start_token) { |
| 121 | parse_events_set_extra(NULL, yyscanner); |
| 122 | return start_token; |
| 123 | } |
| 124 | } |
| 125 | %} |
| 126 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 127 | <event>{ |
| 128 | |
| 129 | {group} { |
| 130 | BEGIN(INITIAL); yyless(0); |
| 131 | } |
| 132 | |
| 133 | {event_pmu} | |
| 134 | {event} { |
| 135 | str(yyscanner, PE_EVENT_NAME); |
| 136 | BEGIN(INITIAL); yyless(0); |
| 137 | return PE_EVENT_NAME; |
| 138 | } |
| 139 | |
| 140 | . | |
| 141 | <<EOF>> { |
| 142 | BEGIN(INITIAL); yyless(0); |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 147 | <config>{ |
| 148 | config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } |
| 149 | config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } |
| 150 | config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); } |
| 151 | name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); } |
| 152 | period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } |
| 153 | branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } |
| 154 | , { return ','; } |
| 155 | "/" { BEGIN(INITIAL); return '/'; } |
| 156 | {name_minus} { return str(yyscanner, PE_NAME); } |
| 157 | } |
| 158 | |
| 159 | <mem>{ |
| 160 | {modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); } |
| 161 | : { return ':'; } |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame^] | 162 | "/" { return '/'; } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 163 | {num_dec} { return value(yyscanner, 10); } |
| 164 | {num_hex} { return value(yyscanner, 16); } |
| 165 | /* |
| 166 | * We need to separate 'mem:' scanner part, in order to get specific |
| 167 | * modifier bits parsed out. Otherwise we would need to handle PE_NAME |
| 168 | * and we'd need to parse it manually. During the escape from <mem> |
| 169 | * state we need to put the escaping char back, so we dont miss it. |
| 170 | */ |
| 171 | . { unput(*yytext); BEGIN(INITIAL); } |
| 172 | /* |
| 173 | * We destroy the scanner after reaching EOF, |
| 174 | * but anyway just to be sure get back to INIT state. |
| 175 | */ |
| 176 | <<EOF>> { BEGIN(INITIAL); } |
| 177 | } |
| 178 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 179 | cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } |
| 180 | stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } |
| 181 | stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } |
| 182 | instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } |
| 183 | cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } |
| 184 | cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } |
| 185 | branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } |
| 186 | branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } |
| 187 | bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } |
| 188 | ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } |
| 189 | cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } |
| 190 | task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } |
| 191 | page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } |
| 192 | minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } |
| 193 | major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } |
| 194 | context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } |
| 195 | cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } |
| 196 | alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } |
| 197 | emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } |
Adrian Hunter | d22d1a2 | 2013-08-31 21:50:52 +0300 | [diff] [blame] | 198 | dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 199 | |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 200 | /* |
| 201 | * We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately. |
| 202 | * Because the prefix cycles is mixed up with cpu-cycles. |
| 203 | * loads and stores are mixed up with cache event |
| 204 | */ |
| 205 | cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); } |
| 206 | cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); } |
| 207 | mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); } |
| 208 | mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); } |
| 209 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 210 | L1-dcache|l1-d|l1d|L1-data | |
| 211 | L1-icache|l1-i|l1i|L1-instruction | |
| 212 | LLC|L2 | |
| 213 | dTLB|d-tlb|Data-TLB | |
| 214 | iTLB|i-tlb|Instruction-TLB | |
| 215 | branch|branches|bpu|btb|bpc | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 216 | node { return str(yyscanner, PE_NAME_CACHE_TYPE); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 217 | |
| 218 | load|loads|read | |
| 219 | store|stores|write | |
| 220 | prefetch|prefetches | |
| 221 | speculative-read|speculative-load | |
| 222 | refs|Reference|ops|access | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 223 | misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 224 | |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 225 | mem: { BEGIN(mem); return PE_PREFIX_MEM; } |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 226 | r{num_raw_hex} { return raw(yyscanner); } |
| 227 | {num_dec} { return value(yyscanner, 10); } |
| 228 | {num_hex} { return value(yyscanner, 16); } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 229 | |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 230 | {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } |
Kan Liang | ba32a45 | 2014-10-07 11:08:51 -0400 | [diff] [blame] | 231 | {name} { return pmu_str_check(yyscanner); } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 232 | "/" { BEGIN(config); return '/'; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 233 | - { return '-'; } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 234 | , { BEGIN(event); return ','; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 235 | : { return ':'; } |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 236 | "{" { BEGIN(event); return '{'; } |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 237 | "}" { return '}'; } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 238 | = { return '='; } |
Jiri Olsa | 8c5f0a8 | 2012-07-04 00:00:39 +0200 | [diff] [blame] | 239 | \n { } |
Jiri Olsa | 8200422 | 2013-09-27 18:29:58 +0200 | [diff] [blame] | 240 | . { } |
Jiri Olsa | 08d2f76 | 2012-05-21 09:12:52 +0200 | [diff] [blame] | 241 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 242 | %% |
| 243 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 244 | int parse_events_wrap(void *scanner __maybe_unused) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 245 | { |
| 246 | return 1; |
| 247 | } |