Skip to contentSkip to conversation

perf tools: Add missing Intel CPU events to parser

PATCH Superseded Adrian Hunter 4 participants 13 messages Mar 24, 2020 – Apr 4, 2020 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH 1/1 perf tools: Add missing Intel CPU events to parser

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

---
 tools/perf/util/parse-events.l | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
tools/perf/util/parse-events.l +19 -5
index 7b1c8ee537cf..a4012613cdcf 100644
@@ -342,11 +342,25 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-start				|
+tx-commit				|
+tx-abort				|
+tx-capacity				|
+tx-conflict				|
+el-start				|
+el-commit				|
+el-abort				|
+el-capacity				|
+el-conflict				|
+tx-capacity-read			|
+tx-capacity-write			|
+el-capacity-read			|
+el-capacity-write			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
 
 L1-dcache|l1-d|l1d|L1-data		|
 L1-icache|l1-i|l1i|L1-instruction	|
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines · Adrian Hunter

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!
Quoted 6 lines

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

thanks,
jirka

#2 lore raw

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 25 lines · Adrian Hunter
Quoted 23 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!
Quoted 8 lines
Quoted 6 lines

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

So, I'm not being able to reproduce this, what an I missing?

[root@seventh ~]# grep -m1 'model name' /proc/cpuinfo
model name : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
[root@seventh ~]#

[root@seventh ~]# perf list | grep el-capacity
el-capacity OR cpu/el-capacity/ [Kernel PMU event]
[root@seventh ~]# perf test -v "Parse event" |& grep el-capacity el-capacity -> cpu/event=0x54,umask=0x2/
[root@seventh ~]# perf stat -e el-capacity:u,cpu/event=el-capacity/u ^C
Performance counter stats for 'system wide':

                 0      el-capacity:u
                 0      cpu/event=el-capacity/u

       2.315736828 seconds time elapsed

[root@seventh ~]#

[root@seventh ~]# perf test -v "Parse event" |& grep el-capacity -B5
running test 55 'cycles:k'
running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/' running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp' el-capacity -> cpu/event=0x54,umask=0x2/
[root@seventh ~]# perf test -v "Parse event" |& grep el-capacity -B5 -A5
running test 55 'cycles:k'
running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/' running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp' el-capacity -> cpu/event=0x54,umask=0x2/
el-conflict -> cpu/event=0x54,umask=0x1/
el-start -> cpu/event=0xc8,umask=0x1/
tx-abort -> cpu/event=0xc9,umask=0x4/
topdown-slots-issued -> cpu/event=0xe,umask=0x1/
tx-capacity -> cpu/event=0x54,umask=0x2/
[root@seventh ~]#

#3 lore raw
Quoted 29 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 27 lines · Adrian Hunter
Quoted 26 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

So, I'm not being able to reproduce this, what an I missing?

I think you need to be on some really recent intel which defines events which we did not covered yet like el-capacity-write in icelake

jirka

#4 lore raw

Em Wed, Mar 25, 2020 at 02:53:50PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 32 lines · Adrian Hunter
Quoted 30 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

So, I'm not being able to reproduce this, what an I missing?

I think you need to be on some really recent intel which defines events which we did not covered yet like el-capacity-write in icelake

That is why I tried with el-capacity, which is moved to the parser as well, I've replaced el-capacity-read, which I don't have in this Kaby Lake machine, with el-capacity, that is present:

[root@seventh ~]# perf list | grep el-capacity
el-capacity OR cpu/el-capacity/ [Kernel PMU event]
[root@seventh ~]#

- Arnaldo

author reviewer
#5 lore raw
Quoted 43 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 02:53:50PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 32 lines · Adrian Hunter
Quoted 30 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

So, I'm not being able to reproduce this, what an I missing?

I think you need to be on some really recent intel which defines events which we did not covered yet like el-capacity-write in icelake

Quoted 7 lines

That is why I tried with el-capacity, which is moved to the parser as well, I've replaced el-capacity-read, which I don't have in this Kaby Lake machine, with el-capacity, that is present:

[root@seventh ~]# perf list | grep el-capacity
el-capacity OR cpu/el-capacity/ [Kernel PMU event]
[root@seventh ~]#

I just checked that and it seems to be a "feature" of the parser that it gets confused between el-capacity and el-capacity-read.

Making them explicit in parse-events.l makes the problem go away, but I wonder now if the parser could be better in this regard.

Any ideas?

#6 lore raw
Quoted 52 lines · Adrian Hunter
Quoted 43 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 02:53:50PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 32 lines · Adrian Hunter
Quoted 30 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

So, I'm not being able to reproduce this, what an I missing?

I think you need to be on some really recent intel which defines events which we did not covered yet like el-capacity-write in icelake

Quoted 7 lines

That is why I tried with el-capacity, which is moved to the parser as well, I've replaced el-capacity-read, which I don't have in this Kaby Lake machine, with el-capacity, that is present:

[root@seventh ~]# perf list | grep el-capacity
el-capacity OR cpu/el-capacity/ [Kernel PMU event]
[root@seventh ~]#

Quoted 5 lines

I just checked that and it seems to be a "feature" of the parser that it gets confused between el-capacity and el-capacity-read.

Making them explicit in parse-events.l makes the problem go away, but I wonder now if the parser could be better in this regard.

so we have that PRE/SUFFIX logic that allows us to specify any sysfs event term as standalone event

the lexer in this case below was used to handle special cases.. and IIUC think having more than one '-' is one of them

could you check if the patch below will fix that for you?

jirka

---

tools/perf/util/parse-events.l +9 -5
index 7b1c8ee537cf..347eb3e6794a 100644
@@ -342,11 +342,15 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-capacity-read			|
+tx-capacity-write			|
+el-capacity-read			|
+el-capacity-write			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
 
 L1-dcache|l1-d|l1d|L1-data		|
 L1-icache|l1-i|l1i|L1-instruction	|
author reviewer
#7 lore raw
Quoted 83 lines · Jiri Olsa
Quoted 52 lines · Adrian Hunter
Quoted 43 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 25, 2020 at 02:53:50PM +0100, Jiri Olsa escreveu:

Quoted 34 lines · Arnaldo Carvalho de Melo
Quoted 33 lines

Em Wed, Mar 25, 2020 at 11:33:45AM +0100, Jiri Olsa escreveu:

Quoted 32 lines · Adrian Hunter
Quoted 30 lines

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

Fix by adding missing Intel CPU events to the event parser. Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

So, I'm not being able to reproduce this, what an I missing?

I think you need to be on some really recent intel which defines events which we did not covered yet like el-capacity-write in icelake

Quoted 7 lines

That is why I tried with el-capacity, which is moved to the parser as well, I've replaced el-capacity-read, which I don't have in this Kaby Lake machine, with el-capacity, that is present:

[root@seventh ~]# perf list | grep el-capacity
el-capacity OR cpu/el-capacity/ [Kernel PMU event]
[root@seventh ~]#

Quoted 5 lines

I just checked that and it seems to be a "feature" of the parser that it gets confused between el-capacity and el-capacity-read.

Making them explicit in parse-events.l makes the problem go away, but I wonder now if the parser could be better in this regard.

so we have that PRE/SUFFIX logic that allows us to specify any sysfs event term as standalone event

the lexer in this case below was used to handle special cases.. and IIUC think having more than one '-' is one of them

could you check if the patch below will fix that for you?

jirka

---

tools/perf/util/parse-events.l +0 -4
index 7b1c8ee537cf..347eb3e6794a 100644
@@ -342,11 +342,15 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }

tools/perf/util/parse-events.l bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT · line 353

Quoted 10 lines
tools/perf/util/parse-events.l +9 -1
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-capacity-read			|
+tx-capacity-write			|
+el-capacity-read			|
+el-capacity-write			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }

Yes that works, as does

tx-capacity-[a-z-]+
el-capacity-[a-z-]+

Do we have an explanation for why we cannot make it accept 3-part names without handling them as special cases?

I just tried but it didn't work.

#8 lore raw

On Wed, Mar 25, 2020 at 07:10:44PM +0200, Adrian Hunter wrote:

SNIP

Quoted 26 lines
Quoted 13 lines

---

tools/perf/util/parse-events.l +0 -4
index 7b1c8ee537cf..347eb3e6794a 100644
@@ -342,11 +342,15 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }

tools/perf/util/parse-events.l bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT · line 353

Quoted 10 lines
tools/perf/util/parse-events.l +9 -1
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-capacity-read			|
+tx-capacity-write			|
+el-capacity-read			|
+el-capacity-write			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }

Yes that works, as does

Quoted 5 lines

tx-capacity-[a-z-]+
el-capacity-[a-z-]+

Do we have an explanation for why we cannot make it accept 3-part names without handling them as special cases?

check the pmu_str_check, I guess it could be more generic, but it gets complicated later on, so I'm not sure there's some other obstacle..

CC-ing Kan Liang, who wrote that

jirka

Quoted 3 lines

I just tried but it didn't work.

author reviewer
#9 lore raw

PATCH v2 1/1 perf tools: Add missing Intel CPU events to parser

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

This happens because the parser splits names by '-' in order to deal with cache events. For example 'L1-dcache' is a token in parse-events.l which is matched to 'L1-dcache-load-miss' by the following rule:

PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config

And so there is special handling for 2-part PMU names i.e.

PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc

but no handling for 3-part names, which are instead added as tokens e.g.

    topdown-[a-z-]+

While it would be possible to add a rule for 3-part names, that would not work if the first parts were also a valid PMU name e.g. 'el-capacity-read' would be matched to 'el-capacity' before the parser reached the 3rd part.

The parser would need significant change to rationalize all this, so instead fix for now by adding missing Intel CPU events with 3-part names to the event parser as tokens.

Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

---

Changes in V2:

Add only 3-part names
Clarify commit message

 tools/perf/util/parse-events.l | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/perf/util/parse-events.l +7 -5
index 7b1c8ee537cf..baa48f28d57d 100644
@@ -342,11 +342,13 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-capacity-[a-z-]+			|
+el-capacity-[a-z-]+			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
 
 L1-dcache|l1-d|l1d|L1-data		|
 L1-icache|l1-i|l1i|L1-instruction	|
Signature · 1 line
2.17.1
Acked-by on v2 1/1
#10 lore raw
Quoted 48 lines · Adrian Hunter

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

This happens because the parser splits names by '-' in order to deal with cache events. For example 'L1-dcache' is a token in parse-events.l which is matched to 'L1-dcache-load-miss' by the following rule:

PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config

And so there is special handling for 2-part PMU names i.e.

PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc

but no handling for 3-part names, which are instead added as tokens e.g.

    topdown-[a-z-]+

While it would be possible to add a rule for 3-part names, that would not work if the first parts were also a valid PMU name e.g. 'el-capacity-read' would be matched to 'el-capacity' before the parser reached the 3rd part.

The parser would need significant change to rationalize all this, so instead fix for now by adding missing Intel CPU events with 3-part names to the event parser as tokens.

Quoted 5 lines

Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

thanks,
jirka

#11 lore raw

Em Thu, Mar 26, 2020 at 10:25:45AM +0100, Jiri Olsa escreveu:

Quoted 5 lines · Adrian Hunter
Quoted 3 lines

The parser would need significant change to rationalize all this, so instead fix for now by adding missing Intel CPU events with 3-part names to the event parser as tokens.

Quoted 7 lines
Quoted 5 lines

Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

Thanks, applied.

- Arnaldo

merge bot Applied
#12 lore raw

[tip: perf/urgent] perf events parser: Add missing Intel CPU events to parser

In reply to Adrian Hunter
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     47327f56674d69a423f7167f8d4ea537cc1762cc
Gitweb:        https://git.kernel.org/tip/47327f56674d69a423f7167f8d4ea537cc1762cc
Author:        Adrian Hunter <[email protected]>
AuthorDate:    Thu, 26 Mar 2020 10:01:47 +02:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Fri, 03 Apr 2020 09:37:56 -03:00

perf events parser: Add missing Intel CPU events to parser

perf list expects CPU events to be parseable by name, e.g.

    # perf list | grep el-capacity-read
      el-capacity-read OR cpu/el-capacity-read/          [Kernel PMU event]

But the event parser does not recognize them that way, e.g.

    # perf test -v "Parse event"
    <SNIP>
    running test 54 'cycles//u'
    running test 55 'cycles:k'
    running test 0 'cpu/config=10,config1,config2=3,period=1000/u'
    running test 1 'cpu/config=1,name=krava/u,cpu/config=2/u'
    running test 2 'cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/'
    running test 3 'cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp'
    -> cpu/event=0,umask=0x11/
    -> cpu/event=0,umask=0x13/
    -> cpu/event=0x54,umask=0x1/
    failed to parse event 'el-capacity-read:u,cpu/event=el-capacity-read/u', err 1, str 'parser error'
    event syntax error: 'el-capacity-read:u,cpu/event=el-capacity-read/u'
                           \___ parser error test child finished with 1
    ---- end ----
    Parse event definition strings: FAILED!

This happens because the parser splits names by '-' in order to deal with cache events. For example 'L1-dcache' is a token in parse-events.l which is matched to 'L1-dcache-load-miss' by the following rule:

PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config

And so there is special handling for 2-part PMU names i.e.

PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc

but no handling for 3-part names, which are instead added as tokens e.g.

    topdown-[a-z-]+

While it would be possible to add a rule for 3-part names, that would not work if the first parts were also a valid PMU name e.g. 'el-capacity-read' would be matched to 'el-capacity' before the parser reached the 3rd part.

The parser would need significant change to rationalize all this, so instead fix for now by adding missing Intel CPU events with 3-part names to the event parser as tokens.

Missing events were found by using:

grep -r EVENT_ATTR_STR arch/x86/events/intel/core.c

---
 tools/perf/util/parse-events.l | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/perf/util/parse-events.l +7 -5
index 7b1c8ee..baa48f2 100644
@@ -342,11 +342,13 @@ bpf-output					{ return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUT
 	 * Because the prefix cycles is mixed up with cpu-cycles.
 	 * loads and stores are mixed up with cache event
 	 */
-cycles-ct					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-cycles-t					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-loads					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-mem-stores					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
-topdown-[a-z-]+					{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
+cycles-ct				|
+cycles-t				|
+mem-loads				|
+mem-stores				|
+topdown-[a-z-]+				|
+tx-capacity-[a-z-]+			|
+el-capacity-[a-z-]+			{ return str(yyscanner, PE_KERNEL_PMU_EVENT); }
 
 L1-dcache|l1-d|l1d|L1-data		|
 L1-icache|l1-i|l1i|L1-instruction	|