Ian Rogers
ded80bda8b
perf expr: Migrate expr ids table to a hashmap
...
Use a hashmap between a char* string and a double* value. While bpf's
hashmap entries are size_t in size, we can't guarantee sizeof(size_t) >=
sizeof(double). Avoid a memory allocation when gathering ids by making
0.0 a special value encoded as NULL.
Original map suggestion by Andi Kleen:
https://lore.kernel.org/lkml/[email protected] /
and seconded by Jiri Olsa:
https://lore.kernel.org/lkml/20200423112915.GH1136647@krava/
Committer notes:
There are fixes that need to land upstream before we can use libbpf's
headers, for now use our copy unconditionally, since the data structures
at this point are exactly the same, no problem.
When the fixes for libbpf's hashmap land upstream, we can fix this up.
Testing it:
Building with LIBBPF=1, i.e. the default:
$ perf -vv | grep -i bpf
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
$ nm ~/bin/perf | grep -i libbpf_ | wc -l
39
$ nm ~/bin/perf | grep -i hashmap_ | wc -l
17
$
Explicitely building without LIBBPF:
$ perf -vv | grep -i bpf
bpf: [ OFF ] # HAVE_LIBBPF_SUPPORT
$
$ nm ~/bin/perf | grep -i libbpf_ | wc -l
0
$ nm ~/bin/perf | grep -i hashmap_ | wc -l
9
$
Signed-off-by: Ian Rogers <[email protected] >
Tested-by: Arnaldo Carvalho de Melo <[email protected] >
Cc: Adrian Hunter <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: Alexei Starovoitov <[email protected] >
Cc: Andi Kleen <[email protected] >
Cc: Andrii Nakryiko <[email protected] >
Cc: Cong Wang <[email protected] >
Cc: Daniel Borkmann <[email protected] >
Cc: Jin Yao <[email protected] >
Cc: Jiri Olsa <[email protected] >
Cc: John Fastabend <[email protected] >
Cc: John Garry <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Kan Liang <[email protected] >
Cc: Kim Phillips <[email protected] >
Cc: Leo Yan <[email protected] >
Cc: Mark Rutland <[email protected] >
Cc: Martin KaFai Lau <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Song Liu <[email protected] >
Cc: Stephane Eranian <[email protected] >
Cc: Yonghong Song <[email protected] >
Cc: [email protected]
Cc: kp singh <[email protected] >
Cc: [email protected]
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-05-28 10:03:26 -03:00
Ian Rogers
6365757894
perf expr: Fix memory leaks in metric bison
...
Add a destructor for strings to reclaim memory in the event of errors.
Free the ID given for a lookup, it was previously strdup-ed in the lex
code.
Signed-off-by: Ian Rogers <[email protected] >
Reviewed-by: Andi Kleen <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: Mark Rutland <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Stephane Eranian <[email protected] >
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-05-28 10:03:26 -03:00
Ian Rogers
9be27a5d41
perf expr: Print a debug message for division by zero
...
If an expression yields 0 and is then divided-by/modulus-by then the
parsing aborts. Add a debug error message to better enable debugging
when this happens.
Signed-off-by: Ian Rogers <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Cc: Adrian Hunter <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: Andi Kleen <[email protected] >
Cc: Haiyan Song <[email protected] >
Cc: Jin Yao <[email protected] >
Cc: John Garry <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Kan Liang <[email protected] >
Cc: Leo Yan <[email protected] >
Cc: Mark Rutland <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Paul Clarke <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Cc: Song Liu <[email protected] >
Cc: Stephane Eranian <[email protected] >
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-05-28 10:03:25 -03:00
Ian Rogers
cb59fa793e
perf expr: Allow ',' to be an other token
...
Corrects parse errors in expr__find_other of expressions with min.
Signed-off-by: Ian Rogers <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Cc: Adrian Hunter <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: Andi Kleen <[email protected] >
Cc: Haiyan Song <[email protected] >
Cc: Jin Yao <[email protected] >
Cc: John Garry <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Kan Liang <[email protected] >
Cc: Leo Yan <[email protected] >
Cc: Mark Rutland <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Paul Clarke <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Cc: Song Liu <[email protected] >
Cc: Stephane Eranian <[email protected] >
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-05-28 10:03:25 -03:00
Jiri Olsa
aecce63e2b
perf expr: Add expr_ prefix for parse_ctx and parse_id
...
Adding expr_ prefix for parse_ctx and parse_id, to straighten out the
expr* namespace.
There's no functional change.
Signed-off-by: Jiri Olsa <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: Andi Kleen <[email protected] >
Cc: Anju T Sudhakar <[email protected] >
Cc: Benjamin Herrenschmidt <[email protected] >
Cc: Greg Kroah-Hartman <[email protected] >
Cc: Jin Yao <[email protected] >
Cc: Joe Mario <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Kan Liang <[email protected] >
Cc: Madhavan Srinivasan <[email protected] >
Cc: Mamatha Inamdar <[email protected] >
Cc: Mark Rutland <[email protected] >
Cc: Michael Ellerman <[email protected] >
Cc: Michael Petlan <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Paul Mackerras <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Cc: Sukadev Bhattiprolu <[email protected] >
Cc: Thomas Gleixner <[email protected] >
Cc: [email protected]
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-04-16 12:19:13 -03:00
Jiri Olsa
26226a9772
perf expr: Move expr lexer to flex
...
Adding expr flex code instead of the manual parser code. So it's easily
extensible in upcoming changes.
The new flex code is in flex.l object and gets compiled like all the
other flexers we use. It's defined as flex reentrant parser.
It's used by both expr__parse and expr__find_other interfaces by
separating the starting point.
There's no intended change of functionality ;-) the test expr is
passing.
Signed-off-by: Jiri Olsa <[email protected] >
Reviewed-by: Andi Kleen <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: John Garry <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Michael Petlan <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-03-09 21:43:24 -03:00
Jiri Olsa
576a65b697
perf expr: Add expr.c object
...
Add generic expr code into new expr.c object.
The expr.c object will be mainly used in following change that will get
rid of the manual flex code,
Signed-off-by: Jiri Olsa <[email protected] >
Reviewed-by: Andi Kleen <[email protected] >
Cc: Alexander Shishkin <[email protected] >
Cc: John Garry <[email protected] >
Cc: Kajol Jain <[email protected] >
Cc: Michael Petlan <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Peter Zijlstra <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-03-09 21:43:24 -03:00
Jiri Olsa
fc8c0a9922
perf tools: Use %define api.pure full instead of %pure-parser
...
bison deprecated the "%pure-parser" directive in favor of "%define
api.pure full".
The api.pure got introduced in bison 2.3 (Oct 2007), so it seems safe to
use it without any version check.
Signed-off-by: Jiri Olsa <[email protected] >
Cc: Adrian Hunter <[email protected] >
Cc: Clark Williams <[email protected] >
Cc: Jiri Olsa <[email protected] >
Cc: Namhyung Kim <[email protected] >
Cc: Ravi Bangoria <[email protected] >
Cc: Thomas Gleixner <[email protected] >
Link: http://lore.kernel.org/lkml/20200112192259.GA35080@krava
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2020-01-14 12:02:19 -03:00
Arnaldo Carvalho de Melo
8520a98dba
perf debug: Remove needless include directives from debug.h
...
All we need there is a forward declaration for 'union perf_event', so
remove it from there and add missing header directives in places using
things from this indirect include.
Cc: Adrian Hunter <[email protected] >
Cc: Jiri Olsa <[email protected] >
Cc: Namhyung Kim <[email protected] >
Link: https://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2019-08-31 19:10:19 -03:00
Andi Kleen
d66dccdb13
perf tools: Dedup events in expression parsing
...
Avoid adding redundant events while parsing an expression. When we add
an "other" event check first if it already exists.
v2: Fix perf test failure.
Signed-off-by: Andi Kleen <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2017-08-22 12:19:08 -03:00
Andi Kleen
d73bad0685
perf tools: Expression parser enhancements for metrics
...
Enhance the expression parser for more complex metric formulas.
- Support python style IF ELSE operators
- Add an #SMT_On magic variable for formulas that depend on the SMT
status.
Example: 4 *( CPU_CLK_UNHALTED.THREAD_ANY / 2 ) if #SMT_on else cycles
- Support MIN/MAX operations
Example: min(1 , IDQ.MITE_UOPS / ( UPI * 16 * ( ICACHE.HIT + ICACHE.MISSES ) / 4.0 ) )
This is useful to fix up problems caused by multiplexing.
- Support | & ^ operators
- Minor cleanups and fixes
- Support an \ escape for operators. This allows to specify event names
like c2-residency
- Support @ as an alternative for / to be able to specify pmus without
conflicts with operators (like msr/tsc/ as msr@tsc@)
Example: (cstate_core@c3\\-residency@ / msr@tsc@) * 100
Signed-off-by: Andi Kleen <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2017-08-22 12:15:53 -03:00
Andi Kleen
c295036b6a
perf tools: Add missing newline to expr parser error messages
...
Signed-off-by: Andi Kleen <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2017-08-11 10:42:53 -03:00
Andi Kleen
075167363f
perf tools: Add a simple expression parser for JSON
...
Add a simple expression parser good enough to parse JSON relation
expressions. The parser is implemented using bison.
This is just intended as an simple parser for internal usage in the
event lists, not the beginning of a "perf scripting language"
v2: Use expr__ prefix instead of expr_
Support multiple free variables for parser
Committer note:
The v2 patch had:
%define api.pure full
In expr.y, that is a feature introduced in bison 2.7, to have reentrant
parsers, not using global variables, which would make tools/perf stop
building with the bison version shipped in older distros, so Andi
realised that the other parsers (e.g. parse-events.y) were using:
%pure-parser
Which is present in older versions of bison and fits the bill.
I added:
CFLAGS_expr-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w
To finally make it build, copying what was there for pmu-bison.o,
another parser.
Signed-off-by: Andi Kleen <[email protected] >
Acked-by: Jiri Olsa <[email protected] >
Link: http://lkml.kernel.org/r/[email protected]
[ stdlib.h is needed in tests/expr.c for free() fixing build in systems such as ubuntu:16.04-x-s390 ]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected] >
2017-03-23 11:39:27 -03:00