Skip to content

Commit 3613f6c

Browse files
captain5050acmel
authored andcommitted
perf expr: Add literal values starting with #
It is useful to have literal values for constants relating to topologies, SMT, etc. Make the parsing of literals shared code and add a lookup function. Move #smt_on to this function. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul A . Clarke <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Riccardo Mancini <[email protected]> Cc: Song Liu <[email protected]> Cc: Wan Jiabing <[email protected]> Cc: Yury Norov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0b6b84c commit 3613f6c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

tools/perf/util/expr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include "expr.h"
1010
#include "expr-bison.h"
1111
#include "expr-flex.h"
12+
#include "smt.h"
1213
#include <linux/kernel.h>
1314
#include <linux/zalloc.h>
1415
#include <ctype.h>
16+
#include <math.h>
1517

1618
#ifdef PARSER_DEBUG
1719
extern int expr_debug;
@@ -370,3 +372,12 @@ double expr_id_data__value(const struct expr_id_data *data)
370372
assert(data->kind == EXPR_ID_DATA__REF_VALUE);
371373
return data->ref.val;
372374
}
375+
376+
double expr__get_literal(const char *literal)
377+
{
378+
if (!strcmp("#smt_on", literal))
379+
return smt_on() > 0 ? 1.0 : 0.0;
380+
381+
pr_err("Unrecognized literal '%s'", literal);
382+
return NAN;
383+
}

tools/perf/util/expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ int expr__find_ids(const char *expr, const char *one,
5555
struct expr_parse_ctx *ids);
5656

5757
double expr_id_data__value(const struct expr_id_data *data);
58+
double expr__get_literal(const char *literal);
5859

5960
#endif

tools/perf/util/expr.l

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/compiler.h>
77
#include "expr.h"
88
#include "expr-bison.h"
9+
#include <math.h>
910

1011
char *expr_get_text(yyscan_t yyscanner);
1112
YYSTYPE *expr_get_lval(yyscan_t yyscanner);
@@ -77,6 +78,17 @@ static int str(yyscan_t scanner, int token, int runtime)
7778
yylval->str = normalize(yylval->str, runtime);
7879
return token;
7980
}
81+
82+
static int literal(yyscan_t scanner)
83+
{
84+
YYSTYPE *yylval = expr_get_lval(scanner);
85+
86+
yylval->num = expr__get_literal(expr_get_text(scanner));
87+
if (isnan(yylval->num))
88+
return EXPR_ERROR;
89+
90+
return LITERAL;
91+
}
8092
%}
8193

8294
number ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
@@ -85,6 +97,7 @@ sch [-,=]
8597
spec \\{sch}
8698
sym [0-9a-zA-Z_\.:@?]+
8799
symbol ({spec}|{sym})+
100+
literal #[0-9a-zA-Z_\.\-]+
88101

89102
%%
90103
struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
@@ -94,7 +107,7 @@ max { return MAX; }
94107
min { return MIN; }
95108
if { return IF; }
96109
else { return ELSE; }
97-
#smt_on { return SMT_ON; }
110+
{literal} { return literal(yyscanner); }
98111
{number} { return value(yyscanner); }
99112
{symbol} { return str(yyscanner, ID, sctx->runtime); }
100113
"|" { return '|'; }

tools/perf/util/expr.y

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <assert.h>
55
#include <math.h>
66
#include "util/debug.h"
7-
#include "smt.h"
87
#define IN_EXPR_Y 1
98
#include "expr.h"
109
%}
@@ -37,7 +36,7 @@
3736
} ids;
3837
}
3938

40-
%token ID NUMBER MIN MAX IF ELSE SMT_ON D_RATIO EXPR_ERROR
39+
%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO EXPR_ERROR
4140
%left MIN MAX IF
4241
%left '|'
4342
%left '^'
@@ -46,7 +45,7 @@
4645
%left '-' '+'
4746
%left '*' '/' '%'
4847
%left NEG NOT
49-
%type <num> NUMBER
48+
%type <num> NUMBER LITERAL
5049
%type <str> ID
5150
%destructor { free ($$); } <str>
5251
%type <ids> expr if_expr
@@ -280,9 +279,9 @@ expr: NUMBER
280279
$$ = union_expr($3, $5);
281280
}
282281
}
283-
| SMT_ON
282+
| LITERAL
284283
{
285-
$$.val = smt_on() > 0 ? 1.0 : 0.0;
284+
$$.val = $1;
286285
$$.ids = NULL;
287286
}
288287
;

0 commit comments

Comments
 (0)