Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf parse-events: Tidy name token matching

Prior to commit 70c90e4a6b2f ("perf parse-events: Avoid scanning PMUs
before parsing") names (generally event names) excluded hyphen (minus)
symbols as the formation of legacy names with hyphens was handled in
the yacc code. That commit allowed hyphens supposedly making
name_minus unnecessary. However, changing name_minus to name has
issues in the term config tokens as then name ends up having priority
over numbers and name allows matching numbers since commit
5ceb57990bf4 ("perf parse: Allow tracepoint names to start with digits
"). It is also permissable for a name to match with a colon (':') in
it when its in a config term list. To address this rename name_minus
to term_name, make the pattern match name's except for the colon, add
number matching into the config term region with a higher priority
than name matching. This addresses an inconsistency and allows greater
matching for names inside of term lists, for example, they may start
with a number.

Rename name_tag to quoted_name and update comments and helper
functions to avoid str detecting quoted strings which was already done
by the lexer.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250109175401.161340-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
7e05269b 4bac7fb5

+32 -19
+32 -19
tools/perf/util/parse-events.l
··· 53 53 YYSTYPE *yylval = parse_events_get_lval(scanner); 54 54 char *text = parse_events_get_text(scanner); 55 55 56 - if (text[0] != '\'') { 57 - yylval->str = strdup(text); 58 - } else { 59 - /* 60 - * If a text tag specified on the command line 61 - * contains opening single quite ' then it is 62 - * expected that the tag ends with single quote 63 - * as well, like this: 64 - * name=\'CPU_CLK_UNHALTED.THREAD:cmask=1\' 65 - * quotes need to be escaped to bypass shell 66 - * processing. 67 - */ 68 - yylval->str = strndup(&text[1], strlen(text) - 2); 69 - } 56 + yylval->str = strdup(text); 57 + return token; 58 + } 70 59 60 + static int quoted_str(yyscan_t scanner, int token) 61 + { 62 + YYSTYPE *yylval = parse_events_get_lval(scanner); 63 + char *text = parse_events_get_text(scanner); 64 + 65 + /* 66 + * If a text tag specified on the command line 67 + * contains opening single quite ' then it is 68 + * expected that the tag ends with single quote 69 + * as well, like this: 70 + * name=\'CPU_CLK_UNHALTED.THREAD:cmask=1\' 71 + * quotes need to be escaped to bypass shell 72 + * processing. 73 + */ 74 + yylval->str = strndup(&text[1], strlen(text) - 2); 71 75 return token; 72 76 } 73 77 ··· 239 235 num_dec [0-9]+ 240 236 num_hex 0x[a-fA-F0-9]{1,16} 241 237 num_raw_hex [a-fA-F0-9]{1,16} 242 - name [a-zA-Z0-9_*?\[\]][a-zA-Z0-9_*?.\[\]!\-]* 243 - name_tag [\'][a-zA-Z0-9_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=]*[\'] 244 - name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* 238 + /* Regular pattern to match the token PE_NAME. */ 239 + name_start [a-zA-Z0-9_*?\[\]] 240 + name {name_start}[a-zA-Z0-9_*?.\[\]!\-]* 241 + /* PE_NAME token when inside a config term list, allows ':'. */ 242 + term_name {name_start}[a-zA-Z0-9_*?.\[\]!\-:]* 243 + /* 244 + * PE_NAME token when quoted, allows ':,.='. 245 + * Matches the RHS of terms like: name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'. 246 + */ 247 + quoted_name [\']{name_start}[a-zA-Z0-9_*?.\[\]!\-:,\.=]*[\'] 245 248 drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? 246 249 /* 247 250 * If you add a modifier you need to update check_modifier(). ··· 352 341 {lc_type} { return lc_str(yyscanner, _parse_state); } 353 342 {lc_type}-{lc_op_result} { return lc_str(yyscanner, _parse_state); } 354 343 {lc_type}-{lc_op_result}-{lc_op_result} { return lc_str(yyscanner, _parse_state); } 355 - {name_minus} { return str(yyscanner, PE_NAME); } 344 + {num_dec} { return value(_parse_state, yyscanner, 10); } 345 + {num_hex} { return value(_parse_state, yyscanner, 16); } 346 + {term_name} { return str(yyscanner, PE_NAME); } 356 347 @{drv_cfg_term} { return drv_str(yyscanner, PE_DRV_CFG_TERM); } 357 348 } 358 349 ··· 423 410 424 411 {modifier_event} { return modifiers(_parse_state, yyscanner); } 425 412 {name} { return str(yyscanner, PE_NAME); } 426 - {name_tag} { return str(yyscanner, PE_NAME); } 413 + {quoted_name} { return quoted_str(yyscanner, PE_NAME); } 427 414 "/" { BEGIN(config); return '/'; } 428 415 , { BEGIN(event); return ','; } 429 416 : { return ':'; }