~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/util/parse-events.l

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/util/parse-events.l (Version linux-6.12-rc7) and /tools/perf/util/parse-events.l (Version linux-2.6.32.71)


  1                                                   
  2 %option reentrant                                 
  3 %option bison-bridge                              
  4 %option prefix="parse_events_"                    
  5 %option stack                                     
  6 %option bison-locations                           
  7 %option yylineno                                  
  8 %option reject                                    
  9                                                   
 10 %{                                                
 11 #include <errno.h>                                
 12 #include <sys/types.h>                            
 13 #include <sys/stat.h>                             
 14 #include <unistd.h>                               
 15 #include "parse-events.h"                         
 16 #include "parse-events-bison.h"                   
 17 #include "evsel.h"                                
 18                                                   
 19 char *parse_events_get_text(yyscan_t yyscanner    
 20 YYSTYPE *parse_events_get_lval(yyscan_t yyscan    
 21 int parse_events_get_column(yyscan_t yyscanner    
 22 int parse_events_get_leng(yyscan_t yyscanner);    
 23                                                   
 24 static int get_column(yyscan_t scanner)           
 25 {                                                 
 26         return parse_events_get_column(scanner    
 27 }                                                 
 28                                                   
 29 static int value(struct parse_events_state *pa    
 30 {                                                 
 31         YYSTYPE *yylval = parse_events_get_lva    
 32         char *text = parse_events_get_text(sca    
 33         u64 num;                                  
 34                                                   
 35         errno = 0;                                
 36         num = strtoull(text, NULL, base);         
 37         if (errno) {                              
 38                 struct parse_events_error *err    
 39                 char *help = NULL;                
 40                                                   
 41                 if (asprintf(&help, "Bad base     
 42                         parse_events_error__ha    
 43                                                   
 44                 return PE_ERROR;                  
 45         }                                         
 46                                                   
 47         yylval->num = num;                        
 48         return PE_VALUE;                          
 49 }                                                 
 50                                                   
 51 static int str(yyscan_t scanner, int token)       
 52 {                                                 
 53         YYSTYPE *yylval = parse_events_get_lva    
 54         char *text = parse_events_get_text(sca    
 55                                                   
 56         if (text[0] != '\'') {                    
 57                 yylval->str = strdup(text);       
 58         } else {                                  
 59                 /*                                
 60                  * If a text tag specified on     
 61                  * contains opening single qui    
 62                  * expected that the tag ends     
 63                  * as well, like this:            
 64                  *     name=\'CPU_CLK_UNHALTED    
 65                  * quotes need to be escaped t    
 66                  * processing.                    
 67                  */                               
 68                 yylval->str = strndup(&text[1]    
 69         }                                         
 70                                                   
 71         return token;                             
 72 }                                                 
 73                                                   
 74 static int lc_str(yyscan_t scanner, const stru    
 75 {                                                 
 76         return str(scanner, state->match_legac    
 77 }                                                 
 78                                                   
 79 /*                                                
 80  * This function is called when the parser get    
 81  *                                                
 82  *      @cfg1 or @cfg2=config                     
 83  *                                                
 84  * The leading '@' is stripped off before 'cfg    
 85  * bison.  In the latter case it is necessary     
 86  * the PMU kernel driver can determine what co    
 87  * 'config'.                                      
 88  */                                               
 89 static int drv_str(yyscan_t scanner, int token    
 90 {                                                 
 91         YYSTYPE *yylval = parse_events_get_lva    
 92         char *text = parse_events_get_text(sca    
 93                                                   
 94         /* Strip off the '@' */                   
 95         yylval->str = strdup(text + 1);           
 96         return token;                             
 97 }                                                 
 98                                                   
 99 /*                                                
100  * Use yyless to return all the characaters to    
101  * location debugging. If __alloc is non-zero     
102  * returned token's value.                        
103  */                                               
104 #define REWIND(__alloc)                           
105 do {                                              
106         YYSTYPE *__yylval = parse_events_get_l    
107         char *text = parse_events_get_text(yys    
108                                                   
109         if (__alloc)                              
110                 __yylval->str = strdup(text);     
111                                                   
112         yycolumn -= strlen(text);                 
113         yyless(0);                                
114 } while (0)                                       
115                                                   
116 static int sym(yyscan_t scanner, int type, int    
117 {                                                 
118         YYSTYPE *yylval = parse_events_get_lva    
119                                                   
120         yylval->num = (type << 16) + config;      
121         return type == PERF_TYPE_HARDWARE ? PE    
122 }                                                 
123                                                   
124 static int tool(yyscan_t scanner, enum perf_to    
125 {                                                 
126         YYSTYPE *yylval = parse_events_get_lva    
127                                                   
128         yylval->num = event;                      
129         return PE_VALUE_SYM_TOOL;                 
130 }                                                 
131                                                   
132 static int term(yyscan_t scanner, enum parse_e    
133 {                                                 
134         YYSTYPE *yylval = parse_events_get_lva    
135                                                   
136         yylval->term_type = type;                 
137         return PE_TERM;                           
138 }                                                 
139                                                   
140 static int hw_term(yyscan_t scanner, int confi    
141 {                                                 
142         YYSTYPE *yylval = parse_events_get_lva    
143         char *text = parse_events_get_text(sca    
144                                                   
145         yylval->hardware_term.str = strdup(tex    
146         yylval->hardware_term.num = PERF_TYPE_    
147         return PE_TERM_HW;                        
148 }                                                 
149                                                   
150 static void modifiers_error(struct parse_event    
151                             int pos, char mod_    
152 {                                                 
153         struct parse_events_error *error = par    
154         char *help = NULL;                        
155                                                   
156         if (asprintf(&help, "Duplicate modifie    
157                 parse_events_error__handle(err    
158 }                                                 
159                                                   
160 static int modifiers(struct parse_events_state    
161 {                                                 
162         YYSTYPE *yylval = parse_events_get_lva    
163         char *text = parse_events_get_text(sca    
164         struct parse_events_modifier mod = { .    
165                                                   
166         for (size_t i = 0, n = strlen(text); i    
167 #define CASE(c, field)                            
168                 case c:                           
169                         if (mod.field) {          
170                                 modifiers_erro    
171                                 return PE_ERRO    
172                         }                         
173                         mod.field = true;         
174                         break                     
175                                                   
176                 switch (text[i]) {                
177                 CASE('u', user);                  
178                 CASE('k', kernel);                
179                 CASE('h', hypervisor);            
180                 CASE('I', non_idle);              
181                 CASE('G', guest);                 
182                 CASE('H', host);                  
183                 case 'p':                         
184                         mod.precise++;            
185                         /*                        
186                          * precise ip:            
187                          *                        
188                          *  0 - SAMPLE_IP can     
189                          *  1 - SAMPLE_IP must    
190                          *  2 - SAMPLE_IP requ    
191                          *  3 - SAMPLE_IP must    
192                          *                        
193                          *  See also PERF_RECO    
194                          */                       
195                         if (mod.precise > 3) {    
196                                 struct parse_e    
197                                 char *help = s    
198                                                   
199                                 if (help) {       
200                                         parse_    
201                                                   
202                                 }                 
203                                 return PE_ERRO    
204                         }                         
205                         break;                    
206                 CASE('P', precise_max);           
207                 CASE('S', sample_read);           
208                 CASE('D', pinned);                
209                 CASE('W', weak);                  
210                 CASE('e', exclusive);             
211                 CASE('b', bpf);                   
212                 CASE('R', retire_lat);            
213                 default:                          
214                         return PE_ERROR;          
215                 }                                 
216 #undef CASE                                       
217         }                                         
218         yylval->mod = mod;                        
219         return PE_MODIFIER_EVENT;                 
220 }                                                 
221                                                   
222 #define YY_USER_ACTION                            
223 do {                                              
224         yylloc->last_column  = yylloc->first_c    
225         yylloc->first_column = yycolumn;          
226         yycolumn += yyleng;                       
227 } while (0);                                      
228                                                   
229 #define USER_REJECT             \                 
230         yycolumn -= yyleng;     \                 
231         REJECT                                    
232                                                   
233 %}                                                
234                                                   
235 %x mem                                            
236 %s config                                         
237 %x event                                          
238                                                   
239 group           [^,{}/]*[{][^}]*[}][^,{}/]*       
240 event_pmu       [^,{}/]+[/][^/]*[/][^,{}/]*       
241 event           [^,{}/]+                          
242                                                   
243 num_dec         [0-9]+                            
244 num_hex         0x[a-fA-F0-9]{1,16}               
245 num_raw_hex     [a-fA-F0-9]{1,16}                 
246 name            [a-zA-Z0-9_*?\[\]][a-zA-Z0-9_*    
247 name_tag        [\'][a-zA-Z0-9_*?\[\]][a-zA-Z0    
248 name_minus      [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*    
249 drv_cfg_term    [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?    
250 /*                                                
251  * If you add a modifier you need to update ch    
252  * Also, the letters in modifier_event must no    
253  */                                               
254 modifier_event  [ukhpPGHSDIWebR]{1,16}            
255 modifier_bp     [rwx]{1,3}                        
256 lc_type         (L1-dcache|l1-d|l1d|L1-data|L1    
257 lc_op_result    (load|loads|read|store|stores|    
258 digit           [0-9]                             
259 non_digit       [^0-9]                            
260                                                   
261 %%                                                
262                                                   
263 %{                                                
264         struct parse_events_state *_parse_stat    
265         {                                         
266                 int start_token = _parse_state    
267                                                   
268                 if (start_token == PE_START_TE    
269                         BEGIN(config);            
270                 else if (start_token == PE_STA    
271                         BEGIN(event);             
272                                                   
273                 if (start_token) {                
274                         _parse_state->stoken =    
275                         /*                        
276                          * The flex parser doe    
277                          * via the scan_string    
278                          * init in here.          
279                          */                       
280                         yycolumn = 0;             
281                         return start_token;       
282                 }                                 
283          }                                        
284 %}                                                
285                                                   
286 <event>{                                          
287                                                   
288 {group}         {                                 
289                         BEGIN(INITIAL);           
290                         REWIND(0);                
291                 }                                 
292                                                   
293 {event_pmu}     |                                 
294 {event}         {                                 
295                         BEGIN(INITIAL);           
296                         REWIND(1);                
297                         return PE_EVENT_NAME;     
298                 }                                 
299                                                   
300 <<EOF>>         {                                 
301                         BEGIN(INITIAL);           
302                         REWIND(0);                
303                 }                                 
304 ,               {                                 
305                         return ',';               
306                 }                                 
307 }                                                 
308                                                   
309 <config>{                                         
310         /*                                        
311          * Please update config_term_names whe    
312          */                                       
313 config                  { return term(yyscanne    
314 config1                 { return term(yyscanne    
315 config2                 { return term(yyscanne    
316 config3                 { return term(yyscanne    
317 name                    { return term(yyscanne    
318 period                  { return term(yyscanne    
319 freq                    { return term(yyscanne    
320 branch_type             { return term(yyscanne    
321 time                    { return term(yyscanne    
322 call-graph              { return term(yyscanne    
323 stack-size              { return term(yyscanne    
324 max-stack               { return term(yyscanne    
325 nr                      { return term(yyscanne    
326 inherit                 { return term(yyscanne    
327 no-inherit              { return term(yyscanne    
328 overwrite               { return term(yyscanne    
329 no-overwrite            { return term(yyscanne    
330 percore                 { return term(yyscanne    
331 aux-output              { return term(yyscanne    
332 aux-sample-size         { return term(yyscanne    
333 metric-id               { return term(yyscanne    
334 cpu-cycles|cycles                                 
335 stalled-cycles-frontend|idle-cycles-frontend      
336 stalled-cycles-backend|idle-cycles-backend        
337 instructions                                      
338 cache-references                                  
339 cache-misses                                      
340 branch-instructions|branches                      
341 branch-misses                                     
342 bus-cycles                                        
343 ref-cycles                                        
344 r{num_raw_hex}          { return str(yyscanner    
345 r0x{num_raw_hex}        { return str(yyscanner    
346 ,                       { return ','; }           
347 "/"                     { BEGIN(INITIAL); retu    
348 {lc_type}                       { return lc_st    
349 {lc_type}-{lc_op_result}        { return lc_st    
350 {lc_type}-{lc_op_result}-{lc_op_result} { retu    
351 {name_minus}            { return str(yyscanner    
352 @{drv_cfg_term}         { return drv_str(yysca    
353 }                                                 
354                                                   
355 <mem>{                                            
356 {modifier_bp}           { return str(yyscanner    
357         /*                                        
358          * The colon before memory access modi    
359          * colon before event modifiers. Fortu    
360          * are the same, so trailing context c    
361          * cases.                                 
362          */                                       
363 ":"/{modifier_bp}       { return PE_BP_COLON;     
364         /*                                        
365          * The slash before memory length can     
366          * config terms. Fortunately config te    
367          * digit, so trailing context can be u    
368          */                                       
369 "/"/{digit}             { return PE_BP_SLASH;     
370 "/"/{non_digit}         { BEGIN(config); retur    
371 {num_dec}               { return value(_parse_    
372 {num_hex}               { return value(_parse_    
373         /*                                        
374          * We need to separate 'mem:' scanner     
375          * modifier bits parsed out. Otherwise    
376          * and we'd need to parse it manually.    
377          * state we need to put the escaping c    
378          */                                       
379 .                       { unput(*yytext); BEGI    
380         /*                                        
381          * We destroy the scanner after reachi    
382          * but anyway just to be sure get back    
383          */                                       
384 <<EOF>>                 { BEGIN(INITIAL); }       
385 }                                                 
386                                                   
387 cpu-cycles|cycles                                 
388 stalled-cycles-frontend|idle-cycles-frontend      
389 stalled-cycles-backend|idle-cycles-backend        
390 instructions                                      
391 cache-references                                  
392 cache-misses                                      
393 branch-instructions|branches                      
394 branch-misses                                     
395 bus-cycles                                        
396 ref-cycles                                        
397 cpu-clock                                         
398 task-clock                                        
399 page-faults|faults                                
400 minor-faults                                      
401 major-faults                                      
402 context-switches|cs                               
403 cpu-migrations|migrations                         
404 alignment-faults                                  
405 emulation-faults                                  
406 dummy                                             
407 duration_time                                     
408 user_time                                         
409 system_time                                       
410 bpf-output                                        
411 cgroup-switches                                   
412                                                   
413 {lc_type}                       { return str(y    
414 {lc_type}-{lc_op_result}        { return str(y    
415 {lc_type}-{lc_op_result}-{lc_op_result} { retu    
416 mem:                    { BEGIN(mem); return P    
417 r{num_raw_hex}          { return str(yyscanner    
418 {num_dec}               { return value(_parse_    
419 {num_hex}               { return value(_parse_    
420                                                   
421 {modifier_event}        { return modifiers(_pa    
422 {name}                  { return str(yyscanner    
423 {name_tag}              { return str(yyscanner    
424 "/"                     { BEGIN(config); retur    
425 ,                       { BEGIN(event); return    
426 :                       { return ':'; }           
427 "{"                     { BEGIN(event); return    
428 "}"                     { return '}'; }           
429 =                       { return '='; }           
430 \n                      { }                       
431 .                       { }                       
432                                                   
433 %%                                                
434                                                   
435 int parse_events_wrap(void *scanner __maybe_un    
436 {                                                 
437         return 1;                                 
438 }                                                 
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php