Skip to contentSkip to conversation

perf tool: Add new event group management

RFC Superseded Jiri Olsa 8 participants 91 messages Dec 15, 2011 – Feb 17, 2012

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover perf tool: Add new event group management

hi,
adding support for creating event groups based on the way they are specified on the command line.

As reading through some lkml postings like:
http://marc.info/?t=130105133700002&r=1&w=2
http://marc.info/?t=129065042800002&r=1&w=2

it seems decided to use bison/flex for event parsing first, and do the group management on the top of it.. and thats what I'm trying to do in this patchset.

Since this is quite hot code I expect some discussion/reposts ;), so sending it first as RFC..

attached patches:
1/3 perf, tool: Add parser generator for events parsing 2/3 perf, tool: Add new event group management 3/3 perf, tool: Add more automated tests for event parsing

thanks for comments,
jirka

---
 tools/perf/Makefile                  |   23 ++
 tools/perf/builtin-record.c          |    8 +-
 tools/perf/builtin-stat.c            |   10 +-
 tools/perf/builtin-test.c            |  245 ++++++++++++++++++-
 tools/perf/builtin-top.c             |    8 +-
 tools/perf/perf.h                    |    2 +-
 tools/perf/util/evsel.c              |   28 ++-
 tools/perf/util/evsel.h              |    9 +-
 tools/perf/util/group.c              |   23 ++
 tools/perf/util/group.h              |   25 ++
 tools/perf/util/parse-events-bison.y |  119 +++++++++
 tools/perf/util/parse-events-flex.l  |  111 ++++++++
 tools/perf/util/parse-events.c       |  465 ++++++++++++----------------------
 tools/perf/util/parse-events.h       |    9 +
 tools/perf/util/python.c             |    4 +
 tools/perf/util/top.h                |    2 +-
 16 files changed, 760 insertions(+), 331 deletions(-)
author
#1 lore raw

PATCH 1/3 perf, tool: Add parser generator for events parsing

Changing event parsing to use flex/bison parse generator. The event syntax stays as it is.

grammar description:

events: events ',' event | event

event: event_tracepoint |
event_raw |
event_numeric |
event_symbolic |
event_generic_hw |
event_breakpoint

event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
PE_NAME_SYM:            cpu-cycles|cycles                              |
                        stalled-cycles-frontend|idle-cycles-frontend   |
                        stalled-cycles-backend|idle-cycles-backend     |
                        instructions                                   |
                        cache-references                               |
                        cache-misses                                   |
                        branch-instructions|branches                   |
                        branch-misses                                  |
                        bus-cycles                                     |
                        cpu-clock                                      |
                        task-clock                                     |
                        page-faults|faults                             |
                        minor-faults                                   |
                        major-faults                                   |
                        context-switches|cs                            |
                        cpu-migrations|migrations                      |
                        alignment-faults                               |

emulation-faults

PE_NAME_CACHE_TYPE:     L1-dcache|l1-d|l1d|L1-data             |
                        L1-icache|l1-i|l1i|L1-instruction      |
                        LLC|L2                                 |
                        dTLB|d-tlb|Data-TLB                    |
                        iTLB|i-tlb|Instruction-TLB             |
                        branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT: load|loads|read                       |
                        store|stores|write                     |
                        prefetch|prefetches                    |
                        speculative-read|speculative-load      |
                        refs|Reference|ops|access              |

misses|miss

PE_SEP_RAW:             'r'
PE_SEP_BP:              'mem'
PE_MODIFIER_EVENT:      :[ukhp]{1,2}
PE_MODIFIER_BPTYPE:     :[rwx]{1,3}
PE_NAME_TP:             [a-zA-Z_*?]+
PE_VALUE:               number

Added flex/bison files for event grammar parsing. Added flex/bison Makefile rules plus few special dependencies.

---
 tools/perf/Makefile                  |   21 ++
 tools/perf/util/parse-events-bison.y |  119 +++++++++
 tools/perf/util/parse-events-flex.l  |  111 ++++++++
 tools/perf/util/parse-events.c       |  459 +++++++++++-----------------------
 tools/perf/util/parse-events.h       |    9 +
 5 files changed, 411 insertions(+), 308 deletions(-)
 create mode 100644 tools/perf/util/parse-events-bison.y
 create mode 100644 tools/perf/util/parse-events-flex.l
tools/perf/Makefile +21 -0
index ac86d67..ef6b621 100644
@@ -47,6 +47,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
+FLEX = $(CROSS_COMPILE)flex
+BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
@@ -341,6 +343,8 @@ LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
+LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -627,6 +631,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_FLEX     = @echo '   ' FLEX $@;
+	QUIET_BISON    = @echo '   ' BISON $@;
 endif
 endif
 
@@ -713,6 +719,10 @@ $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 $(OUTPUT)%.o: %.S
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+$(OUTPUT)%.c: %.l
+	$(QUIET_FLEX)$(FLEX) --header-file=$*.h -t $< > $@
+$(OUTPUT)%.c: %.y
+	$(QUIET_BISON)$(BISON) -v $< -d -o $@
 
 $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
@@ -739,6 +749,16 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+
+.SECONDARY: util/parse-events-flex.c util/parse-events-flex.h
+.SECONDARY: util/parse-events-bison.c util/parse-events-bison.h
+
+util/parse-events.o: util/parse-events-flex.c
+util/parse-events-flex.c: util/parse-events-bison.c
+
+$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -910,6 +930,7 @@ clean:
 	$(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS)
 	$(RM) $(ALL_PROGRAMS) perf
 	$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
+	$(RM) util/parse-events-flex.[ch] util/parse-events-bison.[cho]*
 	$(MAKE) -C Documentation/ clean
 	$(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS
 	$(python-clean)
tools/perf/util/parse-events-bison.y new file +119 -0

119 lines not on this page · raw message

tools/perf/util/parse-events-flex.l new file +111 -0

111 lines not on this page · raw message

tools/perf/util/parse-events.c +151 -308

649 lines not on this page · raw message

tools/perf/util/parse-events.h +9 -0
index 7e0cbe7..fa3ac7f 100644
@@ -33,6 +33,15 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 #define EVENTS_HELP_MAX (128*1024)
 
+int parse_events_add_tracepoint(char *sys, char *event, char *mod);
+int parse_events_add_raw(long code, char *mod);
+int parse_events_add_numeric(long type, long config, char *mod);
+int parse_events_add_symbolic(char *symbol, char *mod);
+int parse_events_add_generic_hw(char *type, char *op_result1, char *op_result2,
+				char *mod);
+int parse_events_add_breakpoint(void *ptr, char *type, char *mod);
+void parse_events_error(char const *msg);
+
 void print_events(const char *event_glob);
 void print_events_type(u8 type);
 void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
Signature · 1 line
1.7.4
#2 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 9 lines · Jiri Olsa

events: events ',' event | event

event: event_tracepoint |
event_raw |
event_numeric |
event_symbolic |
event_generic_hw |
event_breakpoint

Quoted 10 lines
event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty

This isn't complete, we need means of specifying perf_event_attr::config[12] when specifying a raw event.

Quoted 17 lines
PE_NAME_SYM:            cpu-cycles|cycles                              |
                        stalled-cycles-frontend|idle-cycles-frontend   |
                        stalled-cycles-backend|idle-cycles-backend     |
                        instructions                                   |
                        cache-references                               |
                        cache-misses                                   |
                        branch-instructions|branches                   |
                        branch-misses                                  |
                        bus-cycles                                     |
                        cpu-clock                                      |
                        task-clock                                     |
                        page-faults|faults                             |
                        minor-faults                                   |
                        major-faults                                   |
                        context-switches|cs                            |
                        cpu-migrations|migrations                      |
                        alignment-faults                               |
Quoted 1 line

emulation-faults

It might make sense to allow means of custom symbol -> raw mappings.

Quoted 13 lines
PE_NAME_CACHE_TYPE:     L1-dcache|l1-d|l1d|L1-data             |
                        L1-icache|l1-i|l1i|L1-instruction      |
                        LLC|L2                                 |
                        dTLB|d-tlb|Data-TLB                    |
                        iTLB|i-tlb|Instruction-TLB             |
                        branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT: load|loads|read                       |
                        store|stores|write                     |
                        prefetch|prefetches                    |
                        speculative-read|speculative-load      |
                        refs|Reference|ops|access              |
Quoted 5 lines

misses|miss

PE_SEP_RAW:             'r'
PE_SEP_BP:              'mem'
PE_MODIFIER_EVENT:      :[ukhp]{1,2}

You can actually have more than 2 modifiers, eg. "upp".

[u] | [k] | [h] | [p]{,3} would be more correct I think.

Quoted 6 lines
PE_MODIFIER_BPTYPE:     :[rwx]{1,3}
PE_NAME_TP:             [a-zA-Z_*?]+
PE_VALUE:               number

Added flex/bison files for event grammar parsing. Added flex/bison Makefile rules plus few special dependencies.

It might be good to include the .c output of flex/bison so that we can build perf without a hard dependency on them -- only people changing the parser will need them.

maintainer
#3 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 11 lines · Peter Zijlstra
Quoted 10 lines
event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
Quoted 2 lines

This isn't complete, we need means of specifying perf_event_attr::config[12] when specifying a raw event.

Also, it might make sense to think about how to specify sysfs events (which don't exist yet).

author
#4 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines
event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
Quoted 5 lines
Quoted 2 lines

This isn't complete, we need means of specifying perf_event_attr::config[12] when specifying a raw event.

Also, it might make sense to think about how to specify sysfs events (which don't exist yet).

any idea/details/specifics how they might look like? ;)

jirka

maintainer
#5 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 13 lines · Jiri Olsa
Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines
event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This isn't complete, we need means of specifying perf_event_attr::config[12] when specifying a raw event.

Also, it might make sense to think about how to specify sysfs events (which don't exist yet).

any idea/details/specifics how they might look like? ;)

The current idea is that they'd live in a place like:

/sys/bus/event_source/devices/$pmu/events/$event

and when you read them they contain a full event_raw style string so you could do things like:

perf record -e cat $sysfsfile or so

(or maybe without the 'r' prefix).

The idea was to have some $pmu:$event like syntax, but seeing that ':' is already used quite a lot, there's maybe a more suitable separator. Maybe '/' would do, yielding things like cpu/instructions.

Then again, it might make sense to restructure the syntax without considerations for the status quo and see if we can come up with something a little more consistent, the above event_* things are quite a hodge podge, syntax wise.

While I appreciate that they are the result of organic growth, it doesn't mean we shouldn't try and restructure stuff once in a while when it makes sense.

maintainer
#6 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 17 lines · Peter Zijlstra
Quoted 1 line

any idea/details/specifics how they might look like? ;)

The current idea is that they'd live in a place like:

/sys/bus/event_source/devices/$pmu/events/$event

and when you read them they contain a full event_raw style string so you could do things like:

perf record -e cat $sysfsfile or so

(or maybe without the 'r' prefix).

The idea was to have some $pmu:$event like syntax, but seeing that ':' is already used quite a lot, there's maybe a more suitable separator. Maybe '/' would do, yielding things like cpu/instructions.

Quoted 8 lines

Then again, it might make sense to restructure the syntax without considerations for the status quo and see if we can come up with something a little more consistent, the above event_* things are quite a hodge podge, syntax wise.

While I appreciate that they are the result of organic growth, it doesn't mean we shouldn't try and restructure stuff once in a while when it makes sense.

There's also the raw event format idea, where

/sys/bus/event_source/devices/$pmu/format

contains a syntax description on how to construct raw events, for intel (!p4) it would be something as simple as a bitfield definition:

event config-0:7
umask config-8:15
usr config-16
os config-17
edge config-18
any config-21
inv config-23
cmask config-24:31

nhm-dmnd_data_rd config1-0
nhm-dmnd_rfo config1-1
nhm-dmnd_ifetch config1-2
...

(the real syntax will likely be a little more complex in order to be able to express the various other architectures their raw input format).

This would allow us to write things like:

perf record -e cpu/event=0x34,umask=0x01,inv,cmask=2

or to give an offcore example:

perf record -e
cpu/offcore,nhm-dmnd_data_rd,nhm-non_dram,nhm-remote_dram,nhm-local_dram

Where cpu/events/offcore would contain: 0x01b7 to fill out config.

We should also extend this to allow per event setting of the period by adding a ,period=10000 or so.

perf record -e cpu/cycles,period=100000

should then give us a cycle counter with a fixed period of .1M cycles.

I think there's currently means to provide this period, but I don't actually know the syntax for it.

But note, the above again uses ',' as separator, which will be much confused with the group idea you already proposed. So we need some consideration on how we all want to express this.

maintainer
#7 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 9 lines · Peter Zijlstra
event   config-0:7
umask   config-8:15
usr     config-16
os      config-17
edge    config-18
any     config-21
inv     config-23
cmask   config-24:31
Quoted 7 lines
nhm-dmnd_data_rd        config1-0
nhm-dmnd_rfo            config1-1
nhm-dmnd_ifetch         config1-2

...

(the real syntax will likely be a little more complex in order to be able to express the various other architectures their raw input format).

for instance AMD would need:

event config-0:7,32-35
guest config-40
host config-41

(assuming you read that as a mask from LSB to MSB)

And I still haven't actually read how the P4 works so I can't help out there.

author
#8 lore raw

new syntax for perf event

Quoted 20 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
event   config-0:7
umask   config-8:15
usr     config-16
os      config-17
edge    config-18
any     config-21
inv     config-23
cmask   config-24:31
Quoted 7 lines
nhm-dmnd_data_rd        config1-0
nhm-dmnd_rfo            config1-1
nhm-dmnd_ifetch         config1-2

...

(the real syntax will likely be a little more complex in order to be able to express the various other architectures their raw input format).

for instance AMD would need:

Quoted 8 lines

event config-0:7,32-35
guest config-40
host config-41

(assuming you read that as a mask from LSB to MSB)

And I still haven't actually read how the P4 works so I can't help out there.

ok first try ;) description + grammar attached

- event has a general format:

        pmu/event_def[:modifier] [ ',' pmu/event_def[:modifier] ] ...

where event_def depends on the chosen pmu:
'cpu' 'tracepoint' 'breakpoint'

- to keep some of the old interface, symbolic and cache events stays, since they are recognizable by keywords (event_symbol, event_cache)

- raw events are defined with the help of event keywords like:

        cpu/raw,config=1,config1=0,config2=0
        cpu/hw,config=1,config1=0

* first symbol after '/' defines the type: raw/hw/cache which match PERF_TYPE_RAW/PERF_TYPE_HARDWARE/PERF_TYPE_HW_CACHE

* the rest consists assignments for 'config/config1/config1' keywords that match with the perf_event_attr:config/config1/config values (possibly extended once we have sysfs events representation)

- tracepoint events are defined like:
tracepoint/system:tracepoint

where tracepoint could contain '*?'

- breakpoint events are defined like:
breakpoint/addr:type

- each event could be followed by modifier definition

- I think pmu names should match registered pmu names,
but we could make some shortcuts so we dont need to type 'tracepoint/', but just 'tp/' or smth..

- as for tracepoints it looks like the old format does not clash with the new one and we could add shortcut (omit the 'tracepoint/') like:
event: event_tracepoint

- not sure I should include 'software' pmu, as it seems to covered by event_symbol events

thanks for comments,
jirka

grammar
-------
events:
event_mod ',' event_mod | event_mod

event_mod:
event | event ':' modifier

event:
event_symbol |
event_cache |
'cpu' '/' event_cpu |
'tracepoint' '/' event_tracepoint
'breakpoint' '/' event_breakpoint

event_symbol:
cpu-cycles|cycles stalled-cycles-frontend|idle-cycles-frontend stalled-cycles-backend|idle-cycles-backend instructions
cache-references
cache-misses branch-instructions|branches branch-misses
bus-cycles
cpu-clock
task-clock
page-faults|faults
minor-faults
major-faults
context-switches|cs cpu-migrations|migrations alignment-faults
emulation-faults

event_cache:
cache_type
cache_type '-' cache_result_op cache_type '-' cache_result_op '-' cache_result_op

cache_type:

                L1-dcache|l1-d|l1d|L1-data
                L1-icache|l1-i|l1i|L1-instruction
                LLC|L2
                dTLB|d-tlb|Data-TLB
                iTLB|i-tlb|Instruction-TLB
                branch|branches|bpu|btb|bpc
                node

cache_result_op:
load|loads|read
store|stores|write
prefetch|prefetches
speculative-read|speculative-load
refs|Reference|ops|access
misses|miss

event_cpu:

                'raw'    ',' event_cpu_def
                'hw'     ',' event_cpu_def
                'cache'  ',' event_cpu_def

event_cpu_def:
event_cpu_ass ',' event_cpu_ass |
event_cpu_ass

event_cpu_ass:
event_cpu_elem '=' value

event_cpu_elem:

                'config' | 'config1' | 'config2'

event_tracepoint:
system ':' tracepoint

event_breakpoint:
addr ':' type

modifier:

                [ukhp]{1,4}
author
#9 lore raw

Re: new syntax for perf event

hi, any feedback?

thanks,
jirka

Quoted 168 lines · Jiri Olsa
Quoted 20 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
event   config-0:7
umask   config-8:15
usr     config-16
os      config-17
edge    config-18
any     config-21
inv     config-23
cmask   config-24:31
Quoted 7 lines
nhm-dmnd_data_rd        config1-0
nhm-dmnd_rfo            config1-1
nhm-dmnd_ifetch         config1-2

...

(the real syntax will likely be a little more complex in order to be able to express the various other architectures their raw input format).

for instance AMD would need:

Quoted 8 lines

event config-0:7,32-35
guest config-40
host config-41

(assuming you read that as a mask from LSB to MSB)

And I still haven't actually read how the P4 works so I can't help out there.

ok first try ;) description + grammar attached

- event has a general format:

        pmu/event_def[:modifier] [ ',' pmu/event_def[:modifier] ] ...

where event_def depends on the chosen pmu:
'cpu' 'tracepoint' 'breakpoint'

- to keep some of the old interface, symbolic and cache events stays, since they are recognizable by keywords (event_symbol, event_cache)

- raw events are defined with the help of event keywords like:

        cpu/raw,config=1,config1=0,config2=0
        cpu/hw,config=1,config1=0

* first symbol after '/' defines the type: raw/hw/cache which match PERF_TYPE_RAW/PERF_TYPE_HARDWARE/PERF_TYPE_HW_CACHE

* the rest consists assignments for 'config/config1/config1' keywords that match with the perf_event_attr:config/config1/config values (possibly extended once we have sysfs events representation)

- tracepoint events are defined like:
tracepoint/system:tracepoint

where tracepoint could contain '*?'

- breakpoint events are defined like:
breakpoint/addr:type

- each event could be followed by modifier definition

- I think pmu names should match registered pmu names,
but we could make some shortcuts so we dont need to type 'tracepoint/', but just 'tp/' or smth..

- as for tracepoints it looks like the old format does not clash with the new one and we could add shortcut (omit the 'tracepoint/') like:
event: event_tracepoint

- not sure I should include 'software' pmu, as it seems to covered by event_symbol events

thanks for comments,
jirka

grammar
-------
events:
event_mod ',' event_mod | event_mod

event_mod:
event | event ':' modifier

event:
event_symbol |
event_cache |
'cpu' '/' event_cpu |
'tracepoint' '/' event_tracepoint
'breakpoint' '/' event_breakpoint

event_symbol:
cpu-cycles|cycles stalled-cycles-frontend|idle-cycles-frontend stalled-cycles-backend|idle-cycles-backend instructions
cache-references
cache-misses branch-instructions|branches branch-misses
bus-cycles
cpu-clock
task-clock
page-faults|faults
minor-faults
major-faults
context-switches|cs cpu-migrations|migrations alignment-faults
emulation-faults

event_cache:
cache_type
cache_type '-' cache_result_op cache_type '-' cache_result_op '-' cache_result_op

cache_type:

                L1-dcache|l1-d|l1d|L1-data
                L1-icache|l1-i|l1i|L1-instruction
                LLC|L2
                dTLB|d-tlb|Data-TLB
                iTLB|i-tlb|Instruction-TLB
                branch|branches|bpu|btb|bpc
                node

cache_result_op:
load|loads|read
store|stores|write
prefetch|prefetches
speculative-read|speculative-load
refs|Reference|ops|access
misses|miss

event_cpu:

                'raw'    ',' event_cpu_def
                'hw'     ',' event_cpu_def
                'cache'  ',' event_cpu_def

event_cpu_def:
event_cpu_ass ',' event_cpu_ass |
event_cpu_ass

event_cpu_ass:
event_cpu_elem '=' value

event_cpu_elem:

                'config' | 'config1' | 'config2'

event_tracepoint:
system ':' tracepoint

event_breakpoint:
addr ':' type

modifier:

                [ukhp]{1,4}
maintainer
#10 lore raw

Re: new syntax for perf event

In reply to Jiri Olsa
Quoted 1 line · Jiri Olsa

grammar

yacc/bison notation it seems.. lemme get the rules for that.

Quoted 3 lines

-------
events:
event_mod ',' event_mod | event_mod

events = event_mod, {',' , event_mod};

would be the EBNF variant for allowing inf repetition, not sure how to express that, it seems to want a recursive rule which I'm not sure I see. The way I read your thing it only allows 1 or 2 events.

Quoted 3 lines

event_mod:
event | event ':' modifier

event_mod = event, [':' , modifier];

Would be the EBNF thing, and I think your rule does indeed match that.

Quoted 6 lines

event:
event_symbol |
event_cache |
'cpu' '/' event_cpu |
'tracepoint' '/' event_tracepoint
'breakpoint' '/' event_breakpoint

I think I'd like to see something like:

event = pmu, '/', event_config

	| event_symbol | event_cache;

pmu = ? ls /sys/bus/event_source/devices ?;
(* maybe add some aliasses like you suggest *)

event_config = (event_predef | event_term), {',', event_term};

event_predef = ? special name -> raw mapping read from somewhere ?;

event_term = event_sym, '=', value;

event_sym = "config" | "config1" | "config2"

	  | ? contents of /sys/bus/event_source/devices/$pmu/format ?;

value = integer | hexint;

Quoted 20 lines

event_symbol:
cpu-cycles|cycles stalled-cycles-frontend|idle-cycles-frontend stalled-cycles-backend|idle-cycles-backend instructions
cache-references
cache-misses branch-instructions|branches branch-misses
bus-cycles
cpu-clock
task-clock
page-faults|faults
minor-faults
major-faults
context-switches|cs cpu-migrations|migrations alignment-faults
emulation-faults

Quoted 4 lines

event_cache:
cache_type
cache_type '-' cache_result_op cache_type '-' cache_result_op '-' cache_result_op

I'd write that as:

event_cache = cache_type, '-', cache_mod, ['-', cache_xs];

cache_type = cache_l1d | cache_l1i | cache_llc

	   | cache_dtlb | cache_itlb
	   | cache_branch | cache_node;

cache_mod = cache_load | cache_store | cache_prefetch;

cache_xs = cache_accesses | cache_misses;

cache_l1d = "L1-dcache" | ... ;

etc..

Quoted 4 lines

event_cpu:

                'raw'    ',' event_cpu_def
                'hw'     ',' event_cpu_def
                'cache'  ',' event_cpu_def

I think these are superfluous and we could deduce them from the actual event_term's used. Something using "config" will be a raw event etc..

Quoted 7 lines

event_cpu_def:
event_cpu_ass ',' event_cpu_ass |
event_cpu_ass

event_cpu_ass:
event_cpu_elem '=' value

Hehehe, you said 'ass', hehe.

Quoted 5 lines

event_tracepoint:
system ':' tracepoint

event_breakpoint:
addr ':' type

Right, something like that.

Quoted 3 lines

modifier:

                [ukhp]{1,4} 

I think you need at least 5, or you can write it like:

modifier = ['u'], ['k'], ['h'], [3*'p'];

Also, I think we grew a few more modifiers with some of the perf kvm guest muck.

author
#11 lore raw

Re: new syntax for perf event

Quoted 9 lines · Peter Zijlstra
Quoted 1 line · Jiri Olsa

grammar

yacc/bison notation it seems.. lemme get the rules for that.

Quoted 3 lines

-------
events:
event_mod ',' event_mod | event_mod

Quoted 5 lines

events = event_mod, {',' , event_mod};

would be the EBNF variant for allowing inf repetition, not sure how to express that, it seems to want a recursive rule which I'm not sure I see. The way I read your thing it only allows 1 or 2 events.

aargh, sure we want more than 2 events ;)
should have been something like:

events: events ',' event_mod | event_mod

Quoted 17 lines
Quoted 4 lines

event_mod:
event | event ':' modifier

event_mod = event, [':' , modifier];

Would be the EBNF thing, and I think your rule does indeed match that.

Quoted 6 lines

event:
event_symbol |
event_cache |
'cpu' '/' event_cpu |
'tracepoint' '/' event_tracepoint
'breakpoint' '/' event_breakpoint

Quoted 6 lines

I think I'd like to see something like:

event = pmu, '/', event_config

	| event_symbol | event_cache;

pmu = ? ls /sys/bus/event_source/devices ?;

ok

Quoted 10 lines

(* maybe add some aliasses like you suggest *)

event_config = (event_predef | event_term), {',', event_term};

event_predef = ? special name -> raw mapping read from somewhere ?;

event_term = event_sym, '=', value;

event_sym = "config" | "config1" | "config2"

	  | ? contents of /sys/bus/event_source/devices/$pmu/format ?;

anyone working on the 'format' stuff? ;) I guess thats the place, where we can stay with hardcoded config[12] so far.. right?

Quoted 34 lines

value = integer | hexint;

Quoted 20 lines

event_symbol:
cpu-cycles|cycles stalled-cycles-frontend|idle-cycles-frontend stalled-cycles-backend|idle-cycles-backend instructions
cache-references
cache-misses branch-instructions|branches branch-misses
bus-cycles
cpu-clock
task-clock
page-faults|faults
minor-faults
major-faults
context-switches|cs cpu-migrations|migrations alignment-faults
emulation-faults

Quoted 4 lines

event_cache:
cache_type
cache_type '-' cache_result_op cache_type '-' cache_result_op '-' cache_result_op

I'd write that as:

event_cache = cache_type, '-', cache_mod, ['-', cache_xs];

cache_type = cache_l1d | cache_l1i | cache_llc

Quoted 8 lines
	   | cache_dtlb | cache_itlb
	   | cache_branch | cache_node;

cache_mod = cache_load | cache_store | cache_prefetch;

cache_xs = cache_accesses | cache_misses;

cache_l1d = "L1-dcache" | ... ;

ok

Quoted 11 lines

etc..

Quoted 4 lines

event_cpu:

                'raw'    ',' event_cpu_def
                'hw'     ',' event_cpu_def
                'cache'  ',' event_cpu_def

I think these are superfluous and we could deduce them from the actual event_term's used. Something using "config" will be a raw event etc..

ok

Quoted 10 lines
Quoted 8 lines

event_cpu_def:
event_cpu_ass ',' event_cpu_ass |
event_cpu_ass

event_cpu_ass:
event_cpu_elem '=' value

Hehehe, you said 'ass', hehe.

eh.. you're seeing things ;) just best fitting abbrev..

Quoted 14 lines
Quoted 7 lines

event_tracepoint:
system ':' tracepoint

event_breakpoint:
addr ':' type

Right, something like that.

Quoted 3 lines

modifier:

                [ukhp]{1,4} 
Quoted 6 lines

I think you need at least 5, or you can write it like:

modifier = ['u'], ['k'], ['h'], [3*'p'];

Also, I think we grew a few more modifiers with some of the perf kvm guest muck.

yep, I'll update it..
I'll prepare another patch version including above changes

thanks,
jirka

maintainer
#12 lore raw

Re: new syntax for perf event

Quoted 2 lines · Jiri Olsa

anyone working on the 'format' stuff? ;) I guess thats the place, where we can stay with hardcoded config[12] so far.. right?

Nobody afaik. Its just one of those things that would be nice to have and are on the todo list someplace. So yeah, you can keep the hardcoded config things for now.

author
#13 lore raw

v3 cover perf tool: parser generator for events parsing

In reply to Jiri Olsa

hi,
I'd never imagine how much code I need to introduce before I could push through the event grouping patch.. ;)

Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format file sysfs attribute
for pmu device
- adding new syntax to specify raw events based on the sysfs pmu's format attribute
eg. "cpu/config=1,config1=2,config2=3/u"

There are helping patches 1-4, which I did not want to mangle with the actual change. Patches 5-9 implement the feature itself.

I consider this patchset as RFC. Everything seems to work, but I did not want to spend much time over it before any fundamental design comments.. ;)

Attached patches:
1/9 perf, tool: Make perf_evlist__splice_list_tail global 2/9 perf, tool: Remove unused functions from debugfs object 3/9 perf, tool: Add sysfs mountpoint interface
4/9 perf, tool: Add bitmap_or function into bitmap object 5/9 perf: Add sysfs format attribute for pmu device 6/9 perf, tool: Add parser generator for events parsing 7/9 perf, tool: Add config options support for event parsing 8/9 perf, tool: Add perf pmu object to access pmu format 9/9 perf, tool: Add support to specify pmu style event

thanks for comments,
jirka

---
 include/linux/perf_event.h             |    6 +
 kernel/events/core.c                   |   23 +
 tools/perf/Makefile                    |   32 +
 tools/perf/builtin-test.c              |   46 +
 tools/perf/util/bitmap.c               |   10 +
 tools/perf/util/debugfs.c              |  141 --
 tools/perf/util/debugfs.h              |    6 -
 tools/perf/util/evlist.c               |    6 +-
 tools/perf/util/evlist.h               |    5 +
 tools/perf/util/include/linux/bitmap.h |   11 +
 tools/perf/util/parse-events-bison.c   | 1813 ++++++++++++++++++++++++++
 tools/perf/util/parse-events-bison.h   |   81 ++
 tools/perf/util/parse-events-flex.c    | 2232 ++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events-flex.h    |  316 +++++
 tools/perf/util/parse-events.c         |  552 ++++-----
 tools/perf/util/parse-events.h         |   37 +
 tools/perf/util/parse-events.l         |  107 ++
 tools/perf/util/parse-events.y         |  191 +++
 tools/perf/util/pmu-bison.c            | 1623 +++++++++++++++++++++++
 tools/perf/util/pmu-bison.h            |   72 +
 tools/perf/util/pmu-flex.c             | 1821 ++++++++++++++++++++++++++
 tools/perf/util/pmu-flex.h             |  316 +++++
 tools/perf/util/pmu.c                  |  409 ++++++
 tools/perf/util/pmu.h                  |   42 +
 tools/perf/util/pmu.l                  |   50 +
 tools/perf/util/pmu.y                  |   76 ++
 tools/perf/util/sysfs.c                |   60 +
 tools/perf/util/sysfs.h                |    6 +
 28 files changed, 9613 insertions(+), 477 deletions(-)
author
#14 lore raw

PATCH v3 1/9 perf, tool: Make perf_evlist__splice_list_tail global

Making perf_evlist__splice_list_tail globaly accessible. It is used in the upcomming paches.

---
 tools/perf/util/evlist.c |    6 +++---
 tools/perf/util/evlist.h |    5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +3 -3
index 3f16e08..b918e30 100644
@@ -97,9 +97,9 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
 	++evlist->nr_entries;
 }
 
-static void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
-					  struct list_head *list,
-					  int nr_entries)
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries)
 {
 	list_splice_tail(list, &evlist->entries);
 	evlist->nr_entries += nr_entries;
tools/perf/util/evlist.h +5 -0
index 8922aee..6ec2f6e 100644
@@ -117,4 +117,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
 
 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
+
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries);
+
 #endif /* __PERF_EVLIST_H */
Signature · 1 line
1.7.6.5
author
#15 lore raw

PATCH v3 2/9 perf, tool: Remove unused functions from debugfs object

In reply to Jiri Olsa

Following debugfs object functions are not referenced within the code:

  int debugfs_valid_entry(const char *path);
  int debugfs_umount(void);
  int debugfs_write(const char *entry, const char *value);
  int debugfs_read(const char *entry, char *buffer, size_t size);
  void debugfs_force_cleanup(void);
  int debugfs_make_path(const char *element, char *buffer, int size);

Removing them.

---
 tools/perf/util/debugfs.c |  141 ---------------------------------------------
 tools/perf/util/debugfs.h |    6 --
 2 files changed, 0 insertions(+), 147 deletions(-)
tools/perf/util/debugfs.c +0 -141
index ffc35e7..dd8b193 100644
@@ -15,32 +15,6 @@ static const char *debugfs_known_mountpoints[] = {
 	0,
 };
 
-/* use this to force a umount */
-void debugfs_force_cleanup(void)
-{
-	debugfs_find_mountpoint();
-	debugfs_premounted = 0;
-	debugfs_umount();
-}
-
-/* construct a full path to a debugfs element */
-int debugfs_make_path(const char *element, char *buffer, int size)
-{
-	int len;
-
-	if (strlen(debugfs_mountpoint) == 0) {
-		buffer[0] = '\0';
-		return -1;
-	}
-
-	len = strlen(debugfs_mountpoint) + strlen(element) + 1;
-	if (len >= size)
-		return len+1;
-
-	snprintf(buffer, size-1, "%s/%s", debugfs_mountpoint, element);
-	return 0;
-}
-
 static int debugfs_found;
 
 /* find the path to the mounted debugfs */
@@ -97,17 +71,6 @@ int debugfs_valid_mountpoint(const char *debugfs)
 	return 0;
 }
 
-
-int debugfs_valid_entry(const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st))
-		return -errno;
-
-	return 0;
-}
-
 static void debugfs_set_tracing_events_path(const char *mountpoint)
 {
 	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
@@ -149,107 +112,3 @@ void debugfs_set_path(const char *mountpoint)
 	snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
 	debugfs_set_tracing_events_path(mountpoint);
 }
-
-/* umount the debugfs */
-
-int debugfs_umount(void)
-{
-	char umountcmd[128];
-	int ret;
-
-	/* if it was already mounted, leave it */
-	if (debugfs_premounted)
-		return 0;
-
-	/* make sure it's a valid mount point */
-	ret = debugfs_valid_mountpoint(debugfs_mountpoint);
-	if (ret)
-		return ret;
-
-	snprintf(umountcmd, sizeof(umountcmd),
-		 "/bin/umount %s", debugfs_mountpoint);
-	return system(umountcmd);
-}
-
-int debugfs_write(const char *entry, const char *value)
-{
-	char path[PATH_MAX + 1];
-	int ret, count;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* get how many chars we're going to write */
-	count = strlen(value);
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDWR);
-	if (fd < 0)
-		return -errno;
-
-	while (count > 0) {
-		/* write it */
-		ret = write(fd, value, count);
-		if (ret <= 0) {
-			if (ret == EAGAIN)
-				continue;
-			close(fd);
-			return -errno;
-		}
-		count -= ret;
-	}
-
-	/* close it */
-	close(fd);
-
-	/* return success */
-	return 0;
-}
-
-/*
- * read a debugfs entry
- * returns the number of chars read or a negative errno
- */
-int debugfs_read(const char *entry, char *buffer, size_t size)
-{
-	char path[PATH_MAX + 1];
-	int ret;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		return -errno;
-
-	do {
-		/* read it */
-		ret = read(fd, buffer, size);
-		if (ret == 0) {
-			close(fd);
-			return EOF;
-		}
-	} while (ret < 0 && errno == EAGAIN);
-
-	/* close it */
-	close(fd);
-
-	/* make *sure* there's a null character at the end */
-	buffer[ret] = '\0';
-
-	/* return the number of chars read */
-	return ret;
-}
tools/perf/util/debugfs.h +0 -6
index 4a878f7..68f3e87 100644
@@ -3,14 +3,8 @@
 
 const char *debugfs_find_mountpoint(void);
 int debugfs_valid_mountpoint(const char *debugfs);
-int debugfs_valid_entry(const char *path);
 char *debugfs_mount(const char *mountpoint);
-int debugfs_umount(void);
 void debugfs_set_path(const char *mountpoint);
-int debugfs_write(const char *entry, const char *value);
-int debugfs_read(const char *entry, char *buffer, size_t size);
-void debugfs_force_cleanup(void);
-int debugfs_make_path(const char *element, char *buffer, int size);
 
 extern char debugfs_mountpoint[];
 extern char tracing_events_path[];
Signature · 1 line
1.7.6.5
author
#16 lore raw

PATCH v3 3/9 perf, tool: Add sysfs mountpoint interface

In reply to Jiri Olsa

Adding sysfs object to provide sysfs mount information in the same way as debugfs object does.

The object provides following function:
sysfs_find_mountpoint

which returns the sysfs mount point.

---
 tools/perf/Makefile     |    2 +
 tools/perf/util/sysfs.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/sysfs.h |    6 ++++
 3 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/util/sysfs.c
 create mode 100644 tools/perf/util/sysfs.h
tools/perf/Makefile +2 -0
index ac86d67..41daa92 100644
@@ -259,6 +259,7 @@ LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/debugfs.h
+LIB_H += util/sysfs.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
@@ -305,6 +306,7 @@ LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/debugfs.o
+LIB_OBJS += $(OUTPUT)util/sysfs.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
tools/perf/util/sysfs.c new file +60 -0

60 lines not on this page · raw message

tools/perf/util/sysfs.h new file +6 -0
new file mode 100644
index 0000000..a813b72
@@ -0,0 +1,6 @@
+#ifndef __SYSFS_H__
+#define __SYSFS_H__
+
+const char *sysfs_find_mountpoint(void);
+
+#endif /* __DEBUGFS_H__ */
Signature · 1 line
1.7.6.5
author
#17 lore raw

PATCH v3 4/9 perf, tool: Add bitmap_or function into bitmap object

In reply to Jiri Olsa

Adding implementation os bitmap_or function to the bitmap object. It is stolen from the kernel lib/bitmap.o object.

It is used in upcomming patches.

---
 tools/perf/util/bitmap.c               |   10 ++++++++++
 tools/perf/util/include/linux/bitmap.h |   11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
tools/perf/util/bitmap.c +10 -0
index 5e230ac..0a1adc1 100644
@@ -19,3 +19,13 @@ int __bitmap_weight(const unsigned long *bitmap, int bits)
 
 	return w;
 }
+
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits)
+{
+	int k;
+	int nr = BITS_TO_LONGS(bits);
+
+	for (k = 0; k < nr; k++)
+		dst[k] = bitmap1[k] | bitmap2[k];
+}
tools/perf/util/include/linux/bitmap.h +11 -0
index eda4416..bb162e4 100644
@@ -5,6 +5,8 @@
 #include <linux/bitops.h>
 
 int __bitmap_weight(const unsigned long *bitmap, int bits);
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits);
 
 #define BITMAP_LAST_WORD_MASK(nbits)					\
 (									\
@@ -32,4 +34,13 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)
 	return __bitmap_weight(src, nbits);
 }
 
+static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
+			     const unsigned long *src2, int nbits)
+{
+	if (small_const_nbits(nbits))
+		*dst = *src1 | *src2;
+	else
+		__bitmap_or(dst, src1, src2, nbits);
+}
+
 #endif /* _PERF_BITOPS_H */
Signature · 1 line
1.7.6.5
author
#18 lore raw

PATCH v3 5/9 perf: Add sysfs format attribute for pmu device

In reply to Jiri Olsa

Adding 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each line of the format file describes mapping of name and bitfield definition within one of abve attributes.

eg:

  event   config:0-7
  umask   config:8-15
  usr     config:16
  os      config:17
  edge    config:18
  any     config:21
  inv     config:23
  cmask   config:24-31

Line syntax:

  line:      NAME config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding event_format callback to the struct pmu, which provides the format information. The pmu shall override this function and provide its own specific format information.

If not overloaded the default format information is used:

config config:0-63
config1 config1:0-63
config2 config2:0-63

---
 include/linux/perf_event.h |    6 ++++++
 kernel/events/core.c       |   23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
include/linux/perf_event.h +6 -0
index 0b91db2..bf17d15 100644
@@ -638,6 +638,12 @@ struct pmu {
 	 */
 	int (*event_init)		(struct perf_event *event);
 
+	/*
+	 * Provide event raw format information for sysfs
+	 * 'format' attribute.
+	 */
+	ssize_t (*event_format)		(struct pmu *pmu, char *page);
+
 #define PERF_EF_START	0x01		/* start the counter when adding    */
 #define PERF_EF_RELOAD	0x02		/* reload the counter when starting */
 #define PERF_EF_UPDATE	0x04		/* update the counter when stopping */
kernel/events/core.c +23 -0
index 91fb68a..3bec8ca 100644
@@ -5492,8 +5492,31 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
 }
 
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");
+
+	return ret;
+}
+
+static ssize_t
+format_show(struct device *dev, struct device_attribute *attr, char *page)
+{
+	struct pmu *pmu = dev_get_drvdata(dev);
+
+	if (pmu->event_format)
+		pmu->event_format(pmu, page);
+
+	return perf_default_event_format(pmu, page);
+}
+
 static struct device_attribute pmu_dev_attrs[] = {
        __ATTR_RO(type),
+       __ATTR_RO(format),
        __ATTR_NULL,
 };
 
Signature · 1 line
1.7.6.5
#19 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 42 lines · Jiri Olsa

Adding 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each line of the format file describes mapping of name and bitfield definition within one of abve attributes.

eg:

  event   config:0-7
  umask   config:8-15
  usr     config:16
  os      config:17
  edge    config:18
  any     config:21
  inv     config:23
  cmask   config:24-31

Line syntax:

  line:      NAME config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding event_format callback to the struct pmu, which provides the format information. The pmu shall override this function and provide its own specific format information.

If not overloaded the default format information is used:

config config:0-63
config1 config1:0-63
config2 config2:0-63

kernel/events/core.c type_show(struct device *dev, struct device_attribute *attr, char *page) · line 5501

Quoted 10 lines
kernel/events/core.c +7 -0
@@ -5492,8 +5492,31 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
 }
 
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");

This looks like abuse of sysfs. The rule is one value per file. When you start adding newlines I can't see how this format attribute can be considered one value.

Eric

author
#20 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 47 lines · Eric W. Biederman
Quoted 45 lines · Jiri Olsa

Adding 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each line of the format file describes mapping of name and bitfield definition within one of abve attributes.

eg:

  event   config:0-7
  umask   config:8-15
  usr     config:16
  os      config:17
  edge    config:18
  any     config:21
  inv     config:23
  cmask   config:24-31

Line syntax:

  line:      NAME config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding event_format callback to the struct pmu, which provides the format information. The pmu shall override this function and provide its own specific format information.

If not overloaded the default format information is used:

config config:0-63
config1 config1:0-63
config2 config2:0-63

kernel/events/core.c +0 -0
@@ -5492,8 +5492,31 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
 }
 
Quoted 11 lines

kernel/events/core.c type_show(struct device *dev, struct device_attribute *attr, char *page) · line 5501

Quoted 7 lines
kernel/events/core.c +7 -0
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");

This looks like abuse of sysfs. The rule is one value per file. When you start adding newlines I can't see how this format attribute can be considered one value.

ops, missed that rule.. I think we can carry the syntax files within perf, or have it builtin somehow.. or procfs? :) PeterZ?

thanks,
jirka

#21 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 13 lines · Jiri Olsa
Quoted 12 lines

kernel/events/core.c type_show(struct device *dev, struct device_attribute *attr, char *page) · line 5501

Quoted 8 lines
kernel/events/core.c +7 -0
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");

This looks like abuse of sysfs. The rule is one value per file. When you start adding newlines I can't see how this format attribute can be considered one value.

Quoted 2 lines

ops, missed that rule.. I think we can carry the syntax files within perf, or have it builtin somehow.. or procfs? :) PeterZ?

There's plenty of exceptions to this rule though and touching procfs is even less appreciated.

#22 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 14 lines · Peter Zijlstra
Quoted 13 lines · Jiri Olsa
Quoted 12 lines

kernel/events/core.c type_show(struct device *dev, struct device_attribute *attr, char *page) · line 5501

Quoted 8 lines
kernel/events/core.c +7 -0
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");

This looks like abuse of sysfs. The rule is one value per file. When you start adding newlines I can't see how this format attribute can be considered one value.

Quoted 5 lines
Quoted 2 lines

ops, missed that rule.. I think we can carry the syntax files within perf, or have it builtin somehow.. or procfs? :) PeterZ?

There's plenty of exceptions to this rule though and touching procfs is even less appreciated.

There may be exceptions but certainly not plenty of exceptions.

There is also a practical scaling problem. You have to be careful with how big you make that value before you have problems.

Perhaps what you want is a directory with a bunch of sysfs attributes?

All I know is I see buffer overflows waiting to happen whenever I look at the code snippet above.

Eric

author
#23 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 22 lines · Eric W. Biederman
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines · Jiri Olsa
Quoted 12 lines

kernel/events/core.c type_show(struct device *dev, struct device_attribute *attr, char *page) · line 5501

Quoted 8 lines
kernel/events/core.c +7 -0
+static ssize_t perf_default_event_format(struct pmu *pmu, char *page)
+{
+	ssize_t ret;
+
+	ret  = sprintf(page,       "config  config:0-63\n");
+	ret += sprintf(page + ret, "config1 config1:0-63\n");
+	ret += sprintf(page + ret, "config2 config2:0-63\n");

This looks like abuse of sysfs. The rule is one value per file. When you start adding newlines I can't see how this format attribute can be considered one value.

Quoted 5 lines
Quoted 2 lines

ops, missed that rule.. I think we can carry the syntax files within perf, or have it builtin somehow.. or procfs? :) PeterZ?

There's plenty of exceptions to this rule though and touching procfs is even less appreciated.

Quoted 7 lines

There may be exceptions but certainly not plenty of exceptions.

There is also a practical scaling problem. You have to be careful with how big you make that value before you have problems.

Perhaps what you want is a directory with a bunch of sysfs attributes?

yep, Peter outlined this possibility in here
https://lkml.org/lkml/2012/1/24/206

Quoted 2 lines

All I know is I see buffer overflows waiting to happen whenever I look at the code snippet above.

from this point of view, the above data should always be static/hardcoded for given pmu.. so we will be fine with the page size buffer, it could be valifated with some sort of BUILD_BUG_ON(data_size < pagesize)

jirka

#24 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

In reply to Jiri Olsa
Quoted 33 lines · Jiri Olsa

Adding 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each line of the format file describes mapping of name and bitfield definition within one of abve attributes.

eg:

  event   config:0-7
  umask   config:8-15
  usr     config:16
  os      config:17
  edge    config:18
  any     config:21
  inv     config:23
  cmask   config:24-31

Line syntax:

  line:      NAME config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding event_format callback to the struct pmu, which provides the format information. The pmu shall override this function and provide its own specific format information.

Quoted 5 lines

If not overloaded the default format information is used:

config config:0-63
config1 config1:0-63
config2 config2:0-63

Shouldn't config[012] be hard-coded like period? They are struct perf_event_attr members after all and it doesn't really make sense to have them dynamic if we're going to have to add them to all pmu/format things.

author
#25 lore raw

Re: [PATCH 5/9] perf: Add sysfs format attribute for pmu device

Quoted 36 lines · Peter Zijlstra
Quoted 35 lines · Jiri Olsa

Adding 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each line of the format file describes mapping of name and bitfield definition within one of abve attributes.

eg:

  event   config:0-7
  umask   config:8-15
  usr     config:16
  os      config:17
  edge    config:18
  any     config:21
  inv     config:23
  cmask   config:24-31

Line syntax:

  line:      NAME config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding event_format callback to the struct pmu, which provides the format information. The pmu shall override this function and provide its own specific format information.

If not overloaded the default format information is used:

Quoted 8 lines
Quoted 3 lines

config config:0-63
config1 config1:0-63
config2 config2:0-63

Shouldn't config[012] be hard-coded like period? They are struct perf_event_attr members after all and it doesn't really make sense to have them dynamic if we're going to have to add them to all pmu/format things.

Well, let me clarify that config[12] and 'period' are different stuff. Also I remember you asked me about the config terms namespace in some other email and I forgot to answer :)

So, while period is event term that user can specify in the event config section like:

      cycles/period=100000/

the config[12] are values that are specified in the format definitions as values that are changed by event terms.. like:

	config1:1,6-10,44

Now for event terms.. whatever term name is specified in the pmu format definition, it is considered as valid term, when the 'pmu' event is configured.. eg events like:

	cpu/krava=1/u

Apart from that we recognize the term 'period', which could be specified only for symbolic events so far:

      cycles/period=100000/

So there can't be name clash between 'period' term and the rest so far. Once we would like to have say 'period' term inside 'pmu' events like:

	cpu/krava=1,period=1000/u

we would need to consider some namespace rules or smth.

Now for config[12] formats.. they are parsed as simple strings and 'hardcoded' in function format_value. I think what you suggest is to 'hardcode' them into the grammar... right?

So instead of using rule:
format_term: PP_NAME ':' bits

there'll be 3 rules like:

format_term: 'config':' bits
format_term: 'config1' ':' bits
format_term: 'config2' ':' bits

I dont have strong feelings one way or the other... but since we already have the parser in place we could use it.. ehm :)

thanks,
jirka

author
#26 lore raw

PATCH v3 6/9 perf, tool: Add parser generator for events parsing

In reply to Jiri Olsa

Changing event parsing to use flex/bison parse generator. The event syntax stays as it was.

grammar description:

events: events ',' event | event

event: event_def PE_MODIFIER_EVENT | event_def

event_def: event_legacy_symbol sep_dc     |
           event_legacy_cache sep_dc      |
           event_legacy_breakpoint sep_dc |
           event_legacy_tracepoint sep_dc |
           event_legacy_numeric sep_dc    |

event_legacy_raw sep_dc

event_legacy_symbol: PE_NAME_SYM

event_legacy_cache: PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT |
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | PE_NAME_CACHE_TYPE

event_legacy_raw: PE_SEP_RAW PE_VALUE

event_legacy_numeric: PE_VALUE ':' PE_VALUE

event_legacy_breakpoint: PE_SEP_BP ':' PE_VALUE ':' PE_MODIFIER_BP

event_breakpoint_type: PE_MODIFIER_BPTYPE | empty

PE_NAME_SYM:              cpu-cycles|cycles                              |
                          stalled-cycles-frontend|idle-cycles-frontend   |
                          stalled-cycles-backend|idle-cycles-backend     |
                          instructions                                   |
                          cache-references                               |
                          cache-misses                                   |
                          branch-instructions|branches                   |
                          branch-misses                                  |
                          bus-cycles                                     |
                          cpu-clock                                      |
                          task-clock                                     |
                          page-faults|faults                             |
                          minor-faults                                   |
                          major-faults                                   |
                          context-switches|cs                            |
                          cpu-migrations|migrations                      |
                          alignment-faults                               |

emulation-faults

PE_NAME_CACHE_TYPE:       L1-dcache|l1-d|l1d|L1-data             |
                          L1-icache|l1-i|l1i|L1-instruction      |
                          LLC|L2                                 |
                          dTLB|d-tlb|Data-TLB                    |
                          iTLB|i-tlb|Instruction-TLB             |
                          branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT:  load|loads|read                        |
                          store|stores|write                     |
                          prefetch|prefetches                    |
                          speculative-read|speculative-load      |
                          refs|Reference|ops|access              |

misses|miss

PE_MODIFIER_EVENT: [ukhp]{0,5}

PE_MODIFIER_BP: [rwx]

PE_SEP_BP: 'mem'

PE_SEP_RAW: 'r'

sep_dc: ':' |

Added flex/bison files for event grammar parsing. The generated parser is part of the patch. Added makefile rule 'event-parser' to generate the parser code out of the bison/flex sources.

---
 tools/perf/Makefile                  |   18 +
 tools/perf/util/parse-events-bison.c | 1715 ++++++++++++++++++++++++++
 tools/perf/util/parse-events-bison.h |   79 ++
 tools/perf/util/parse-events-flex.c  | 2232 ++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events-flex.h  |  316 +++++
 tools/perf/util/parse-events.c       |  486 +++-----
 tools/perf/util/parse-events.h       |   15 +
 tools/perf/util/parse-events.l       |  107 ++
 tools/perf/util/parse-events.y       |  127 ++
 9 files changed, 4757 insertions(+), 338 deletions(-)
 create mode 100644 tools/perf/util/parse-events-bison.c
 create mode 100644 tools/perf/util/parse-events-bison.h
 create mode 100644 tools/perf/util/parse-events-flex.c
 create mode 100644 tools/perf/util/parse-events-flex.h
 create mode 100644 tools/perf/util/parse-events.l
 create mode 100644 tools/perf/util/parse-events.y
tools/perf/Makefile +18 -0
index 41daa92..7143dc3 100644
@@ -47,6 +47,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
+FLEX = $(CROSS_COMPILE)flex
+BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
@@ -343,6 +345,8 @@ LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
+LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -629,6 +633,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_FLEX     = @echo '   ' FLEX $@;
+	QUIET_BISON    = @echo '   ' BISON $@;
 endif
 endif
 
@@ -709,6 +715,9 @@ $(OUTPUT)perf.o perf.spec \
 	$(SCRIPTS) \
 	: $(OUTPUT)PERF-VERSION-FILE
 
+.SUFFIXES:
+.SUFFIXES: .o .c .S .s
+
 $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
@@ -741,6 +750,10 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+
+$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -777,6 +790,7 @@ help:
 	@echo '  html		- make html documentation'
 	@echo '  info		- make GNU info documentation (access with info <foo>)'
 	@echo '  pdf		- make pdf documentation'
+	@echo '  event-parser	- make event parser code'
 	@echo '  TAGS		- use etags to make tag information for source browsing'
 	@echo '  tags		- use ctags to make tag information for source browsing'
 	@echo '  cscope	- use cscope to make interactive browsing database'
@@ -827,6 +841,10 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+event-parser:
+	$(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c
+	$(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/util/parse-events-bison.c new file +1715 -0

1,715 lines not on this page · raw message

tools/perf/util/parse-events-bison.h new file +79 -0

79 lines not on this page · raw message

tools/perf/util/parse-events-flex.c new file +2232 -0

1,146 lines not on this page · raw message

tools/perf/util/parse-events-flex.h new file +316 -0

316 lines not on this page · raw message

tools/perf/util/parse-events.c +148 -338

486 lines not on this page · raw message

tools/perf/util/parse-events.h +15 -0
index 7e0cbe7..84d3771 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/parse-events.l new file +107 -0

107 lines not on this page · raw message

tools/perf/util/parse-events.y new file +127 -0

127 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.6.5

Part of the diff is not shown here. View the raw message.

#27 lore raw

Re: [PATCH 6/9] perf, tool: Add parser generator for events parsing

tools/perf/util/parse-events.l line 89

Quoted 2 lines · Jiri Olsa
tools/perf/util/parse-events.l new file +2 -0
+r{num_dec}             { return raw(10); }
+r{num_hex}             { return raw(16); } 

Not sure that's compatible with the current stuff (not that I greatly mind though), iirc rXXX is always hex.

author
#28 lore raw

Re: [PATCH 6/9] perf, tool: Add parser generator for events parsing

Quoted 6 lines · Peter Zijlstra

tools/perf/util/parse-events.l line 89

Quoted 2 lines · Jiri Olsa
tools/perf/util/parse-events.l new file +2 -0
+r{num_dec}             { return raw(10); }
+r{num_hex}             { return raw(16); } 

Not sure that's compatible with the current stuff (not that I greatly mind though), iirc rXXX is always hex.

right, I'll fix it
thanks

author
#29 lore raw

PATCH v3 7/9 perf, tool: Add config options support for event parsing

In reply to Jiri Olsa

Adding a new rule to the event grammar to be able to specify values of additional attributes of symbolic event.

The new syntax for event symbolic definition is:

event_legacy_symbol: PE_NAME_SYM '/' event_config '/' |
PE_NAME_SYM sep_slash_dc

event_config: event_config ',' event_term | event_term

event_term: PE_NAME '=' PE_NAME |
PE_NAME '=' PE_VALUE

sep_slash_dc: '/' | ':' |

At the moment the code is recognizing only 'period' config option, which modifies value sample_period event attribute.

Use is now allowed to specify events like:
cycles/period=100000/

---
 tools/perf/builtin-test.c            |   18 +++
 tools/perf/util/parse-events-bison.c |  245 +++++++++++++++++++++++-----------
 tools/perf/util/parse-events-bison.h |    6 +-
 tools/perf/util/parse-events.c       |   75 ++++++++++-
 tools/perf/util/parse-events.h       |   22 +++-
 tools/perf/util/parse-events.y       |   66 +++++++++-
 6 files changed, 340 insertions(+), 92 deletions(-)
tools/perf/builtin-test.c +18 -0
index 1fbba0a..081cad7 100644
@@ -677,6 +677,20 @@ static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong period",
+			100000 == evsel->attr.sample_period);
+	return 0;
+}
+
 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
 {
 	struct perf_evsel *evsel = list_entry(evlist->entries.next,
@@ -884,6 +898,10 @@ static struct test__event_st {
 		.check = test__checkevent_symbolic_name,
 	},
 	{
+		.name  = "cycles/period=100000/",
+		.check = test__checkevent_symbolic_name_config,
+	},
+	{
 		.name  = "faults",
 		.check = test__checkevent_symbolic_alias,
 	},
tools/perf/util/parse-events-bison.c +164 -81

442 lines not on this page · raw message

tools/perf/util/parse-events-bison.h +4 -2
index 097a632..b73c4bd 100644
@@ -59,15 +59,17 @@ typedef union YYSTYPE
 {
 
 /* Line 1685 of yacc.c  */
-#line 42 "util/parse-events.y"
+#line 44 "util/parse-events.y"
 
 	char *str;
 	unsigned long num;
+	struct list_head *head;
+	struct parse_events__term *term;
 
 
 
 /* Line 1685 of yacc.c  */
-#line 71 "util/parse-events-bison.h"
+#line 73 "util/parse-events-bison.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
tools/perf/util/parse-events.c +72 -3

90 lines not on this page · raw message

tools/perf/util/parse-events.h +21 -1
index 84d3771..2737f1e 100644
@@ -33,6 +33,25 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 #define EVENTS_HELP_MAX (128*1024)
 
+enum {
+	PARSE_EVENTS__TERM_TYPE_NUM,
+	PARSE_EVENTS__TERM_TYPE_STR,
+};
+
+struct parse_events__term {
+	char *config;
+	union {
+		char *str;
+		long  num;
+	} val;
+	int type;
+
+	struct list_head list;
+};
+
+int parse_events__new_term(struct parse_events__term **term, int type,
+			   char *config, char *str, long num);
+void parse_events__free_terms(struct list_head *terms);
 int parse_events_modifier(struct list_head *list __used, char *str __used);
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event);
@@ -40,7 +59,8 @@ int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config,
 			 unsigned long config1, unsigned long config2,
 			 char *mod);
 int parse_events_add_numeric(struct list_head *list, int *idx,
-			     unsigned long type, unsigned long config);
+			     unsigned long type, unsigned long config,
+			     struct list_head *head_config);
 int parse_events_add_cache(struct list_head *list, int *idx,
 			   char *type, char *op_result1, char *op_result2);
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
tools/perf/util/parse-events.y +61 -5

108 lines not on this page · raw message

Signature · 1 line
1.7.6.5
author
#30 lore raw

PATCH v3 8/9 perf, tool: Add perf pmu object to access pmu format definition

In reply to Jiri Olsa

Adding pmu object which provides interface to pmu's sysfs event format definition located at:
${sysfs_mount}/bus/event_source/devices/${pmu}/format

Following interface is exported:
struct perf_pmu* perf_pmu__find(char *name);
- this function returns pmu object, which is then passed as a handle to other interface functions

int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,

                       struct list_head *head_terms);

- this function configures perf_event_attr struct based on pmu's format definitions and config terms data, containined in head_terms list.

Parser generator is used to retrive the pmu's format definition. The generated parser is part of the patch. Added makefile rule 'pmu-parser' to generate the parser code out of the bison/flex sources.

---
 tools/perf/Makefile         |   12 +
 tools/perf/builtin-test.c   |   10 +
 tools/perf/util/pmu-bison.c | 1623 ++++++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu-bison.h |   72 ++
 tools/perf/util/pmu-flex.c  | 1821 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu-flex.h  |  316 ++++++++
 tools/perf/util/pmu.c       |  409 ++++++++++
 tools/perf/util/pmu.h       |   42 +
 tools/perf/util/pmu.l       |   50 ++
 tools/perf/util/pmu.y       |   76 ++
 10 files changed, 4431 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/util/pmu-bison.c
 create mode 100644 tools/perf/util/pmu-bison.h
 create mode 100644 tools/perf/util/pmu-flex.c
 create mode 100644 tools/perf/util/pmu-flex.h
 create mode 100644 tools/perf/util/pmu.c
 create mode 100644 tools/perf/util/pmu.h
 create mode 100644 tools/perf/util/pmu.l
 create mode 100644 tools/perf/util/pmu.y
tools/perf/Makefile +12 -0
index 7143dc3..27b836b 100644
@@ -262,6 +262,7 @@ LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/debugfs.h
 LIB_H += util/sysfs.h
+LIB_H += util/pmu.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
@@ -309,6 +310,7 @@ LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/debugfs.o
 LIB_OBJS += $(OUTPUT)util/sysfs.o
+LIB_OBJS += $(OUTPUT)util/pmu.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
@@ -347,6 +349,8 @@ LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
 LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
 LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
+LIB_OBJS += $(OUTPUT)util/pmu-flex.o
+LIB_OBJS += $(OUTPUT)util/pmu-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -754,6 +758,9 @@ $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
 
+$(OUTPUT)util/pmu-flex.o: util/pmu-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -791,6 +798,7 @@ help:
 	@echo '  info		- make GNU info documentation (access with info <foo>)'
 	@echo '  pdf		- make pdf documentation'
 	@echo '  event-parser	- make event parser code'
+	@echo '  pmu-parser	- make pmu format parser code'
 	@echo '  TAGS		- use etags to make tag information for source browsing'
 	@echo '  tags		- use ctags to make tag information for source browsing'
 	@echo '  cscope	- use cscope to make interactive browsing database'
@@ -845,6 +853,10 @@ event-parser:
 	$(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c
 	$(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c
 
+pmu-parser:
+	$(QUIET_BISON)$(BISON) -v util/pmu.y -d -o util/pmu-bison.c
+	$(QUIET_FLEX)$(FLEX) --header-file=util/pmu-flex.h -t util/pmu.l > util/pmu-flex.c
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/builtin-test.c +10 -0
index 081cad7..c5d7494 100644
@@ -13,6 +13,7 @@
 #include "util/parse-events.h"
 #include "util/symbol.h"
 #include "util/thread_map.h"
+#include "util/pmu.h"
 #include "../../include/linux/hw_breakpoint.h"
 
 #include <sys/mman.h>
@@ -1483,6 +1484,11 @@ static int test__rdpmc(void)
 
 #endif
 
+static int test__perf_pmu(void)
+{
+	return perf_pmu__test();
+}
+
 static struct test {
 	const char *desc;
 	int (*func)(void);
@@ -1518,6 +1524,10 @@ static struct test {
 		.func = test__PERF_RECORD,
 	},
 	{
+		.desc = "Test perf pmu format parsing",
+		.func = test__perf_pmu,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/util/pmu-bison.c new file +1623 -0

1,623 lines not on this page · raw message

tools/perf/util/pmu-bison.h new file +72 -0

72 lines not on this page · raw message

tools/perf/util/pmu-flex.c new file +1821 -0

1,229 lines not on this page · raw message

tools/perf/util/pmu-flex.h new file +316 -0

316 lines not on this page · raw message

tools/perf/util/pmu.c new file +409 -0

409 lines not on this page · raw message

tools/perf/util/pmu.h new file +42 -0

42 lines not on this page · raw message

tools/perf/util/pmu.l new file +50 -0

50 lines not on this page · raw message

tools/perf/util/pmu.y new file +76 -0

76 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.6.5

Part of the diff is not shown here. View the raw message.

author
#31 lore raw

PATCH v3 9/9 perf, tool: Add support to specify pmu style event

In reply to Jiri Olsa

Added new event rule to the event definition grammar:

event_def: event_pmu |

	   ...

event_pmu: PE_NAME '/' event_config '/'

Using this rule, event could be now specified like:
cpu/config=1,config1=2,config2=3/u

where pmu name 'cpu' is looked up via following path:
${sysfs_mount}/bus/event_source/devices/${pmu}

and config options are bound to the pmu's format definiton:
${sysfs_mount}/bus/event_source/devices/${pmu}/format

---
 tools/perf/builtin-test.c            |   18 ++++
 tools/perf/util/parse-events-bison.c |  187 ++++++++++++++++++----------------
 tools/perf/util/parse-events.c       |   19 ++++
 tools/perf/util/parse-events.h       |    2 +
 tools/perf/util/parse-events.y       |   10 ++-
 5 files changed, 149 insertions(+), 87 deletions(-)
tools/perf/builtin-test.c +18 -0
index c5d7494..f41569c 100644
@@ -873,6 +873,20 @@ static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
 	return test__checkevent_genhw(evlist);
 }
 
+static int test__checkevent_pmu(struct perf_evlist *evlist)
+{
+
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config2);
+	return 0;
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -954,6 +968,10 @@ static struct test__event_st {
 		.name  = "L1-dcache-load-miss:kp",
 		.check = test__checkevent_genhw_modifier,
 	},
+	{
+		.name  = "cpu/config=1,config1=2,config2=3/u",
+		.check = test__checkevent_pmu,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
tools/perf/util/parse-events-bison.c +101 -86

389 lines not on this page · raw message

tools/perf/util/parse-events.c +19 -0
index 7423049..c791715 100644
@@ -12,6 +12,7 @@
 #include "header.h"
 #include "debugfs.h"
 #include "parse-events-flex.h"
+#include "pmu.h"
 
 #define MAX_NAME_LEN 100
 
@@ -632,6 +633,24 @@ int parse_events_add_numeric(struct list_head *list, int *idx,
 			 (char *) __event_name(type, config));
 }
 
+int parse_events_add_pmu(struct list_head *list, int *idx,
+			 char *name, struct list_head *head_config)
+{
+	struct perf_event_attr attr;
+	struct perf_pmu *pmu;
+
+	pmu = perf_pmu__find(name);
+	if (!pmu)
+		return -EINVAL;
+
+	memset(&attr, 0, sizeof(attr));
+
+	if (perf_pmu__config(pmu, &attr, head_config))
+		return -EINVAL;
+
+	return add_event(list, idx, &attr, (char*) "pmu");
+}
+
 int parse_events_modifier(struct list_head *list, char *str)
 {
 	struct perf_evsel *evsel;
tools/perf/util/parse-events.h +2 -0
index 2737f1e..0ebc68c 100644
@@ -65,6 +65,8 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 			   char *type, char *op_result1, char *op_result2);
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
 				void *ptr, char *type);
+int parse_events_add_pmu(struct list_head *list, int *idx,
+			 char *pmu , struct list_head *head_config);
 void parse_events_error(struct list_head *list, int *idx,
 			char const *msg);
 
tools/perf/util/parse-events.y +9 -1
index 0be12dc..588f115 100644
@@ -60,13 +60,21 @@ event_def PE_MODIFIER_EVENT
 |
 event_def
 
-event_def: event_legacy_symbol |
+event_def: event_pmu |
+	   event_legacy_symbol |
 	   event_legacy_cache sep_dc |
 	   event_legacy_mem |
 	   event_legacy_tracepoint sep_dc |
 	   event_legacy_numeric sep_dc |
 	   event_legacy_raw sep_dc
 
+event_pmu:
+PE_NAME '/' event_config '/'
+{
+	ABORT_ON(parse_events_add_pmu(list, idx, $1, $3));
+	parse_events__free_terms($3);
+}
+
 event_legacy_symbol:
 PE_VALUE_SYM '/' event_config '/'
 {
Signature · 1 line
1.7.6.5
#32 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

In reply to Jiri Olsa
Quoted 2 lines · Jiri Olsa

I'd never imagine how much code I need to introduce before I could push through the event grouping patch..

haha, I think you're going well beyond what's required, but let me have a peek at all this new stuff ;-)

#33 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

In reply to Jiri Olsa
Quoted 5 lines · Jiri Olsa

Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format file sysfs attribute
for pmu device

Added Greg to CC, please also see: https://lkml.org/lkml/2012/1/16/148

Right, lets hope we can convince the sysfs people that a few lines are ok.. if not we need to find another way to represent all this muck, one alternative is exploding the whole thing into a sysfs hierarchy like:

format/event: config:0-7
...

format/config: config:0-63
format/config1: config1:0-63
format/config2: config2:0-63

that will of course consume loads more resources but if that's what it takes :-(

Quoted 3 lines

- adding new syntax to specify raw events based
on the sysfs pmu's format attribute
eg. "cpu/config=1,config1=2,config2=3/u"

fair enough, so we have the attributes from the $FORMAT thingy and (for now) one hardcoded 'period' thing.

Should we worry about namespace collisions for the built-in vs format provided names?

I suppose that once we get all this in (and it looks good from my pov), we can start thinking about doing things like:

events/cycles: event=0x3c

Which together with:

format/event: config:0-7

would allow us to write something like:

cpu/event=cycles/u

#34 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

Quoted 17 lines · Peter Zijlstra
Quoted 5 lines · Jiri Olsa

Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format file sysfs attribute
for pmu device

Added Greg to CC, please also see: https://lkml.org/lkml/2012/1/16/148

Right, lets hope we can convince the sysfs people that a few lines are ok.. if not we need to find another way to represent all this muck, one alternative is exploding the whole thing into a sysfs hierarchy like:

format/event: config:0-7
...

Quoted 6 lines

format/config: config:0-63
format/config1: config1:0-63
format/config2: config2:0-63

that will of course consume loads more resources but if that's what it takes :-(

Well, what's to keep someone from exploding one of those files to go over the buffer size without knowing it?

Even after reading the above link, I can't really understand what this is being used for. As it's sysfs files, why aren't Documentation/ABI/ files also being created with the patch explaining it all?

Again, if at all possible, sysfs should be one value per file. Please NEVER create a sysfs file that requires a parser to determine what is going on in it. It should be a simple 'read the value' type thing.

So yes, multiple sysfs files do make sense, the resource load should be almost non-existant for new ones.

thanks,

greg k-h

#35 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

Quoted 2 lines · Greg KH

Well, what's to keep someone from exploding one of those files to go over the buffer size without knowing it?

The content is known at compile time, we could put checks in. But yeah 4k isn't that much text..

Quoted 3 lines

Even after reading the above link, I can't really understand what this is being used for. As it's sysfs files, why aren't Documentation/ABI/ files also being created with the patch explaining it all?

Ah, yeah, documentation, wasn't that written in C :-)

But fair enough... Anyway, the purpose is to describe the magic bits that go into perf_event_attr::config[012] for a particular pmu.

Basically they're the 'hardware' bitmasks we want to export, so that userspace can deal with sane name/value pairs.

Quoted 3 lines

Again, if at all possible, sysfs should be one value per file. Please NEVER create a sysfs file that requires a parser to determine what is going on in it. It should be a simple 'read the value' type thing.

The whole purpose was to drive a parser :-) Anyway, is:
"config:0-7,32-35" acceptable for a single file?

This means, the 'config' member of struct perf_event_attr bits 0-7,32-35 form a bitfield whose name is then given by the filename that has this content.

Quoted 2 lines

So yes, multiple sysfs files do make sense, the resource load should be almost non-existant for new ones.

Surely all these attribute objects take more space than a few lines of text, but ok, I guess multiple files it is.

author
#36 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

Quoted 31 lines · Peter Zijlstra
Quoted 2 lines · Greg KH

Well, what's to keep someone from exploding one of those files to go over the buffer size without knowing it?

The content is known at compile time, we could put checks in. But yeah 4k isn't that much text..

Quoted 3 lines

Even after reading the above link, I can't really understand what this is being used for. As it's sysfs files, why aren't Documentation/ABI/ files also being created with the patch explaining it all?

Ah, yeah, documentation, wasn't that written in C :-)

But fair enough... Anyway, the purpose is to describe the magic bits that go into perf_event_attr::config[012] for a particular pmu.

Basically they're the 'hardware' bitmasks we want to export, so that userspace can deal with sane name/value pairs.

Quoted 3 lines

Again, if at all possible, sysfs should be one value per file. Please NEVER create a sysfs file that requires a parser to determine what is going on in it. It should be a simple 'read the value' type thing.

The whole purpose was to drive a parser :-) Anyway, is:
"config:0-7,32-35" acceptable for a single file?

This means, the 'config' member of struct perf_event_attr bits 0-7,32-35 form a bitfield whose name is then given by the filename that has this content.

Quoted 6 lines
Quoted 2 lines

So yes, multiple sysfs files do make sense, the resource load should be almost non-existant for new ones.

Surely all these attribute objects take more space than a few lines of text, but ok, I guess multiple files it is.

please check attached patch, would something like this be ok?

jirka

---
 .../testing/sysfs-bus-event_source-devices-format  |   14 ++++++++++++
 include/linux/perf_event.h                         |   22 ++++++++++++++++++++
 kernel/events/core.c                               |   22 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-format
Documentation/ABI/testing/sysfs-bus-event_source-devices-format new file +14 -0
new file mode 100644
index 0000000..5a15221
@@ -0,0 +1,14 @@
+Where:		/sys/bus/event_source/devices/<dev>/format
+Date:		January 2012
+Kernel Version: 3.3
+Contact:	Jiri Olsa <[email protected]>
+Description:
+		Attribute group for to describe the magic bits that go into
+		perf_event_attr::config[012] for a particular pmu.
+		Each attribute of this group defines the 'hardware' bitmask
+		we want to export, so that userspace can deal with sane
+		name/value pairs.
+
+		Example: 'config1:1,6-10,44'
+		Defines contents of attribute that occupies bits 1,6-10,44 of
+		perf_event_attr::config1.
include/linux/perf_event.h +22 -0
index 0b91db2..e2bf1c7 100644
@@ -516,6 +516,7 @@ struct perf_guest_info_callbacks {
 #include <linux/irq_work.h>
 #include <linux/jump_label.h>
 #include <linux/atomic.h>
+#include <linux/sysfs.h>
 #include <asm/local.h>
 
 #define PERF_MAX_STACK_DEPTH		255
@@ -626,6 +627,12 @@ struct pmu {
 	int				task_ctx_nr;
 
 	/*
+	 * True if the pmu defines its own set of format attributes within
+	 * attr_groups. If false, default format attributes are used.
+	 */
+	bool				format_defined;
+
+	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
 	 * as well as for lazy/batch writing of the MSRs.
 	 */
@@ -1215,5 +1222,20 @@ do {									\
 	register_cpu_notifier(&fn##_nb);				\
 } while (0)
 
+
+#define PMU_FORMAT_ATTR(_name, _format)				\
+static ssize_t							\
+pmu_format_attr_##_name##_show(struct device *dev,		\
+			       struct device_attribute *attr,	\
+			       char *page)			\
+{								\
+	BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);		\
+	return sprintf(page, _format "\n");			\
+}								\
+								\
+static struct device_attribute format_attr_##_name =		\
+	__ATTR(_name, 0444,					\
+	       pmu_format_attr_##_name##_show, NULL)
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_PERF_EVENT_H */
kernel/events/core.c +22 -0
index de859fb..8d2d6f3 100644
@@ -5503,6 +5503,22 @@ static struct bus_type pmu_bus = {
 	.dev_attrs	= pmu_dev_attrs,
 };
 
+/* Default format attributes. */
+PMU_FORMAT_ATTR(config,  "config:0-63");
+PMU_FORMAT_ATTR(config1, "config1:0-63");
+PMU_FORMAT_ATTR(config2, "config2:0-63");
+
+static struct attribute *format_attrs[] = {
+	&format_attr_config.attr,
+	&format_attr_config1.attr,
+	&format_attr_config2.attr,
+};
+
+static struct attribute_group format_attr_group = {
+	.name   = "format",
+	.attrs  = format_attrs,
+};
+
 static void pmu_dev_release(struct device *dev)
 {
 	kfree(dev);
@@ -5529,6 +5545,12 @@ static int pmu_dev_alloc(struct pmu *pmu)
 	if (ret)
 		goto free_dev;
 
+	if (!pmu->format_defined) {
+		ret = sysfs_create_group(&pmu->dev->kobj, &format_attr_group);
+		if (ret)
+			goto free_dev;
+	}
+
 out:
 	return ret;
 
Signature · 1 line
1.7.1
#37 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

Quoted 1 line · Jiri Olsa

please check attached patch, would something like this be ok?

Looks fine to me, Greg is that Documentation thing good enough

#38 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Jiri Olsa

please check attached patch, would something like this be ok?

Looks fine to me, Greg is that Documentation thing good enough

Yes, looks good to me, thanks.

#39 lore raw

Re: [RFCv3 0/9] perf tool: parser generator for events parsing

In reply to Peter Zijlstra
Quoted 24 lines · Peter Zijlstra
Quoted 2 lines · Greg KH

Well, what's to keep someone from exploding one of those files to go over the buffer size without knowing it?

The content is known at compile time, we could put checks in. But yeah 4k isn't that much text..

Quoted 3 lines

Even after reading the above link, I can't really understand what this is being used for. As it's sysfs files, why aren't Documentation/ABI/ files also being created with the patch explaining it all?

Ah, yeah, documentation, wasn't that written in C :-)

But fair enough... Anyway, the purpose is to describe the magic bits that go into perf_event_attr::config[012] for a particular pmu.

Basically they're the 'hardware' bitmasks we want to export, so that userspace can deal with sane name/value pairs.

Quoted 3 lines

Again, if at all possible, sysfs should be one value per file. Please NEVER create a sysfs file that requires a parser to determine what is going on in it. It should be a simple 'read the value' type thing.

Quoted 6 lines

The whole purpose was to drive a parser :-) Anyway, is:
"config:0-7,32-35" acceptable for a single file?

This means, the 'config' member of struct perf_event_attr bits 0-7,32-35 form a bitfield whose name is then given by the filename that has this content.

Yes, that would be fine.

Quoted 5 lines
Quoted 2 lines

So yes, multiple sysfs files do make sense, the resource load should be almost non-existant for new ones.

Surely all these attribute objects take more space than a few lines of text, but ok, I guess multiple files it is.

Great, thanks for asking.

greg k-h

author
#40 lore raw

v4 cover perf tool: parser generator for events parsing

In reply to Jiri Olsa

hi,
Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format sysfs group attribute
for pmu device
- adding new syntax to specify raw events based on the sysfs pmu's format attribute
eg. "cpu/config=1,config1=2,config2=3/u"

There are helping patches 1-4, which I did not want to mangle with the actual change. Patches 5-9 implement the feature itself.

v4 changes:
- 5/9 changed sysfs pmu format definitions to the group attribute, each line (in previous patch) is now represented by single sysfs attribute under format group
- 6/9 fix raw events so the number is always considered to be hex number
- 8/9 move config[12] definitions to be processed by the parser

Attached patches:
1/9 perf, tool: Make perf_evlist__splice_list_tail global 2/9 perf, tool: Remove unused functions from debugfs object 3/9 perf, tool: Add sysfs mountpoint interface
4/9 perf, tool: Add bitmap_or function into bitmap object 5/9 perf: Adding sysfs group format attribute for pmu device 6/9 perf, tool: Add parser generator for events parsing 7/9 perf, tool: Add config options support for event parsing 8/9 perf, tool: Add perf pmu object to access pmu format definition 9/9 perf, tool: Add support to specify pmu style event

thanks,
jirka

---
 .../testing/sysfs-bus-event_source-devices-format  |   14 +
 include/linux/perf_event.h                         |   22 +
 kernel/events/core.c                               |   22 +
 tools/perf/Makefile                                |   31 +
 tools/perf/builtin-test.c                          |   52 +-
 tools/perf/util/bitmap.c                           |   10 +
 tools/perf/util/debugfs.c                          |  141 --
 tools/perf/util/debugfs.h                          |    6 -
 tools/perf/util/evlist.c                           |    6 +-
 tools/perf/util/evlist.h                           |    5 +
 tools/perf/util/include/linux/bitmap.h             |   11 +
 tools/perf/util/parse-events-bison.c               | 1813 ++++++++++++++++
 tools/perf/util/parse-events-bison.h               |   81 +
 tools/perf/util/parse-events-flex.c                | 2225 ++++++++++++++++++++
 tools/perf/util/parse-events-flex.h                |  316 +++
 tools/perf/util/parse-events.c                     |  552 ++---
 tools/perf/util/parse-events.h                     |   37 +
 tools/perf/util/parse-events.l                     |  107 +
 tools/perf/util/parse-events.y                     |  191 ++
 tools/perf/util/pmu-bison.c                        | 1663 +++++++++++++++
 tools/perf/util/pmu-bison.h                        |   73 +
 tools/perf/util/pmu-flex.c                         | 1821 ++++++++++++++++
 tools/perf/util/pmu-flex.h                         |  316 +++
 tools/perf/util/pmu.c                              |  462 ++++
 tools/perf/util/pmu.h                              |   41 +
 tools/perf/util/pmu.l                              |   43 +
 tools/perf/util/pmu.y                              |   93 +
 tools/perf/util/sysfs.c                            |   60 +
 tools/perf/util/sysfs.h                            |    6 +
 29 files changed, 9740 insertions(+), 480 deletions(-)
author
#41 lore raw

PATCH v3 1/9 perf, tool: Make perf_evlist__splice_list_tail global

Making perf_evlist__splice_list_tail globaly accessible. It is used in the upcomming paches.

---
 tools/perf/util/evlist.c |    6 +++---
 tools/perf/util/evlist.h |    5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +3 -3
index a6d50e3..a57a8cf 100644
@@ -97,9 +97,9 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
 	++evlist->nr_entries;
 }
 
-static void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
-					  struct list_head *list,
-					  int nr_entries)
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries)
 {
 	list_splice_tail(list, &evlist->entries);
 	evlist->nr_entries += nr_entries;
tools/perf/util/evlist.h +5 -0
index 9c51660..1b4282b 100644
@@ -117,4 +117,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
 
 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
+
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries);
+
 #endif /* __PERF_EVLIST_H */
Signature · 1 line
1.7.4.4
#42 lore raw

[tip:perf/core] perf evlist: Make splice_list_tail method public

Commit-ID:  0529bc1fe1e3e509a2fc06fe887b0c76b1eb01f9
Gitweb:     http://git.kernel.org/tip/0529bc1fe1e3e509a2fc06fe887b0c76b1eb01f9
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 27 Jan 2012 15:34:20 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 1 Feb 2012 15:29:53 -0200

perf evlist: Make splice_list_tail method public

Making perf_evlist__splice_list_tail globaly accessible.

It is used in the upcomming paches.

---
 tools/perf/util/evlist.c |    6 +++---
 tools/perf/util/evlist.h |    5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +3 -3
index a6d50e3..a57a8cf 100644
@@ -97,9 +97,9 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
 	++evlist->nr_entries;
 }
 
-static void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
-					  struct list_head *list,
-					  int nr_entries)
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries)
 {
 	list_splice_tail(list, &evlist->entries);
 	evlist->nr_entries += nr_entries;
tools/perf/util/evlist.h +5 -0
index 9c51660..1b4282b 100644
@@ -117,4 +117,9 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
 
 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
+
+void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
+				   struct list_head *list,
+				   int nr_entries);
+
 #endif /* __PERF_EVLIST_H */
author
#43 lore raw

PATCH v3 2/9 perf, tool: Remove unused functions from debugfs object

In reply to Jiri Olsa

Following debugfs object functions are not referenced within the code:

  int debugfs_valid_entry(const char *path);
  int debugfs_umount(void);
  int debugfs_write(const char *entry, const char *value);
  int debugfs_read(const char *entry, char *buffer, size_t size);
  void debugfs_force_cleanup(void);
  int debugfs_make_path(const char *element, char *buffer, int size);

Removing them.

---
 tools/perf/util/debugfs.c |  141 ---------------------------------------------
 tools/perf/util/debugfs.h |    6 --
 2 files changed, 0 insertions(+), 147 deletions(-)
tools/perf/util/debugfs.c +0 -141
index ffc35e7..dd8b193 100644
@@ -15,32 +15,6 @@ static const char *debugfs_known_mountpoints[] = {
 	0,
 };
 
-/* use this to force a umount */
-void debugfs_force_cleanup(void)
-{
-	debugfs_find_mountpoint();
-	debugfs_premounted = 0;
-	debugfs_umount();
-}
-
-/* construct a full path to a debugfs element */
-int debugfs_make_path(const char *element, char *buffer, int size)
-{
-	int len;
-
-	if (strlen(debugfs_mountpoint) == 0) {
-		buffer[0] = '\0';
-		return -1;
-	}
-
-	len = strlen(debugfs_mountpoint) + strlen(element) + 1;
-	if (len >= size)
-		return len+1;
-
-	snprintf(buffer, size-1, "%s/%s", debugfs_mountpoint, element);
-	return 0;
-}
-
 static int debugfs_found;
 
 /* find the path to the mounted debugfs */
@@ -97,17 +71,6 @@ int debugfs_valid_mountpoint(const char *debugfs)
 	return 0;
 }
 
-
-int debugfs_valid_entry(const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st))
-		return -errno;
-
-	return 0;
-}
-
 static void debugfs_set_tracing_events_path(const char *mountpoint)
 {
 	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
@@ -149,107 +112,3 @@ void debugfs_set_path(const char *mountpoint)
 	snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
 	debugfs_set_tracing_events_path(mountpoint);
 }
-
-/* umount the debugfs */
-
-int debugfs_umount(void)
-{
-	char umountcmd[128];
-	int ret;
-
-	/* if it was already mounted, leave it */
-	if (debugfs_premounted)
-		return 0;
-
-	/* make sure it's a valid mount point */
-	ret = debugfs_valid_mountpoint(debugfs_mountpoint);
-	if (ret)
-		return ret;
-
-	snprintf(umountcmd, sizeof(umountcmd),
-		 "/bin/umount %s", debugfs_mountpoint);
-	return system(umountcmd);
-}
-
-int debugfs_write(const char *entry, const char *value)
-{
-	char path[PATH_MAX + 1];
-	int ret, count;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* get how many chars we're going to write */
-	count = strlen(value);
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDWR);
-	if (fd < 0)
-		return -errno;
-
-	while (count > 0) {
-		/* write it */
-		ret = write(fd, value, count);
-		if (ret <= 0) {
-			if (ret == EAGAIN)
-				continue;
-			close(fd);
-			return -errno;
-		}
-		count -= ret;
-	}
-
-	/* close it */
-	close(fd);
-
-	/* return success */
-	return 0;
-}
-
-/*
- * read a debugfs entry
- * returns the number of chars read or a negative errno
- */
-int debugfs_read(const char *entry, char *buffer, size_t size)
-{
-	char path[PATH_MAX + 1];
-	int ret;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		return -errno;
-
-	do {
-		/* read it */
-		ret = read(fd, buffer, size);
-		if (ret == 0) {
-			close(fd);
-			return EOF;
-		}
-	} while (ret < 0 && errno == EAGAIN);
-
-	/* close it */
-	close(fd);
-
-	/* make *sure* there's a null character at the end */
-	buffer[ret] = '\0';
-
-	/* return the number of chars read */
-	return ret;
-}
tools/perf/util/debugfs.h +0 -6
index 4a878f7..68f3e87 100644
@@ -3,14 +3,8 @@
 
 const char *debugfs_find_mountpoint(void);
 int debugfs_valid_mountpoint(const char *debugfs);
-int debugfs_valid_entry(const char *path);
 char *debugfs_mount(const char *mountpoint);
-int debugfs_umount(void);
 void debugfs_set_path(const char *mountpoint);
-int debugfs_write(const char *entry, const char *value);
-int debugfs_read(const char *entry, char *buffer, size_t size);
-void debugfs_force_cleanup(void);
-int debugfs_make_path(const char *element, char *buffer, int size);
 
 extern char debugfs_mountpoint[];
 extern char tracing_events_path[];
Signature · 1 line
1.7.4.4
#44 lore raw

[tip:perf/core] perf tools: Remove unused functions from debugfs object

Commit-ID:  2837609fefbfe8f1248bfce09d9f0b44d5eb713d
Gitweb:     http://git.kernel.org/tip/2837609fefbfe8f1248bfce09d9f0b44d5eb713d
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 27 Jan 2012 15:34:21 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 13 Feb 2012 23:25:38 -0200

perf tools: Remove unused functions from debugfs object

Following debugfs object functions are not referenced within the code:

  int debugfs_valid_entry(const char *path);
  int debugfs_umount(void);
  int debugfs_write(const char *entry, const char *value);
  int debugfs_read(const char *entry, char *buffer, size_t size);
  void debugfs_force_cleanup(void);
  int debugfs_make_path(const char *element, char *buffer, int size);

Removing them.

---
 tools/perf/util/debugfs.c |  141 ---------------------------------------------
 tools/perf/util/debugfs.h |    6 --
 2 files changed, 0 insertions(+), 147 deletions(-)
tools/perf/util/debugfs.c +0 -141
index ffc35e7..dd8b193 100644
@@ -15,32 +15,6 @@ static const char *debugfs_known_mountpoints[] = {
 	0,
 };
 
-/* use this to force a umount */
-void debugfs_force_cleanup(void)
-{
-	debugfs_find_mountpoint();
-	debugfs_premounted = 0;
-	debugfs_umount();
-}
-
-/* construct a full path to a debugfs element */
-int debugfs_make_path(const char *element, char *buffer, int size)
-{
-	int len;
-
-	if (strlen(debugfs_mountpoint) == 0) {
-		buffer[0] = '\0';
-		return -1;
-	}
-
-	len = strlen(debugfs_mountpoint) + strlen(element) + 1;
-	if (len >= size)
-		return len+1;
-
-	snprintf(buffer, size-1, "%s/%s", debugfs_mountpoint, element);
-	return 0;
-}
-
 static int debugfs_found;
 
 /* find the path to the mounted debugfs */
@@ -97,17 +71,6 @@ int debugfs_valid_mountpoint(const char *debugfs)
 	return 0;
 }
 
-
-int debugfs_valid_entry(const char *path)
-{
-	struct stat st;
-
-	if (stat(path, &st))
-		return -errno;
-
-	return 0;
-}
-
 static void debugfs_set_tracing_events_path(const char *mountpoint)
 {
 	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
@@ -149,107 +112,3 @@ void debugfs_set_path(const char *mountpoint)
 	snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
 	debugfs_set_tracing_events_path(mountpoint);
 }
-
-/* umount the debugfs */
-
-int debugfs_umount(void)
-{
-	char umountcmd[128];
-	int ret;
-
-	/* if it was already mounted, leave it */
-	if (debugfs_premounted)
-		return 0;
-
-	/* make sure it's a valid mount point */
-	ret = debugfs_valid_mountpoint(debugfs_mountpoint);
-	if (ret)
-		return ret;
-
-	snprintf(umountcmd, sizeof(umountcmd),
-		 "/bin/umount %s", debugfs_mountpoint);
-	return system(umountcmd);
-}
-
-int debugfs_write(const char *entry, const char *value)
-{
-	char path[PATH_MAX + 1];
-	int ret, count;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* get how many chars we're going to write */
-	count = strlen(value);
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDWR);
-	if (fd < 0)
-		return -errno;
-
-	while (count > 0) {
-		/* write it */
-		ret = write(fd, value, count);
-		if (ret <= 0) {
-			if (ret == EAGAIN)
-				continue;
-			close(fd);
-			return -errno;
-		}
-		count -= ret;
-	}
-
-	/* close it */
-	close(fd);
-
-	/* return success */
-	return 0;
-}
-
-/*
- * read a debugfs entry
- * returns the number of chars read or a negative errno
- */
-int debugfs_read(const char *entry, char *buffer, size_t size)
-{
-	char path[PATH_MAX + 1];
-	int ret;
-	int fd;
-
-	/* construct the path */
-	snprintf(path, sizeof(path), "%s/%s", debugfs_mountpoint, entry);
-
-	/* verify that it exists */
-	ret = debugfs_valid_entry(path);
-	if (ret)
-		return ret;
-
-	/* open the debugfs entry */
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		return -errno;
-
-	do {
-		/* read it */
-		ret = read(fd, buffer, size);
-		if (ret == 0) {
-			close(fd);
-			return EOF;
-		}
-	} while (ret < 0 && errno == EAGAIN);
-
-	/* close it */
-	close(fd);
-
-	/* make *sure* there's a null character at the end */
-	buffer[ret] = '\0';
-
-	/* return the number of chars read */
-	return ret;
-}
tools/perf/util/debugfs.h +0 -6
index 4a878f7..68f3e87 100644
@@ -3,14 +3,8 @@
 
 const char *debugfs_find_mountpoint(void);
 int debugfs_valid_mountpoint(const char *debugfs);
-int debugfs_valid_entry(const char *path);
 char *debugfs_mount(const char *mountpoint);
-int debugfs_umount(void);
 void debugfs_set_path(const char *mountpoint);
-int debugfs_write(const char *entry, const char *value);
-int debugfs_read(const char *entry, char *buffer, size_t size);
-void debugfs_force_cleanup(void);
-int debugfs_make_path(const char *element, char *buffer, int size);
 
 extern char debugfs_mountpoint[];
 extern char tracing_events_path[];
author
#45 lore raw

PATCH v3 3/9 perf, tool: Add sysfs mountpoint interface

In reply to Jiri Olsa

Adding sysfs object to provide sysfs mount information in the same way as debugfs object does.

The object provides following function:
sysfs_find_mountpoint

which returns the sysfs mount mount.

---
 tools/perf/Makefile     |    2 +
 tools/perf/util/sysfs.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/sysfs.h |    6 ++++
 3 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/util/sysfs.c
 create mode 100644 tools/perf/util/sysfs.h
tools/perf/Makefile +2 -0
index d64f581..f170235 100644
@@ -256,6 +256,7 @@ LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/debugfs.h
+LIB_H += util/sysfs.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
@@ -302,6 +303,7 @@ LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/debugfs.o
+LIB_OBJS += $(OUTPUT)util/sysfs.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
tools/perf/util/sysfs.c new file +60 -0

60 lines not on this page · raw message

tools/perf/util/sysfs.h new file +6 -0
new file mode 100644
index 0000000..a813b72
@@ -0,0 +1,6 @@
+#ifndef __SYSFS_H__
+#define __SYSFS_H__
+
+const char *sysfs_find_mountpoint(void);
+
+#endif /* __DEBUGFS_H__ */
Signature · 1 line
1.7.4.4
#46 lore raw

[tip:perf/core] perf tools: Add sysfs mountpoint interface

Commit-ID:  e90fda0635401225ca7c2343bea2f6d279347d10
Gitweb:     http://git.kernel.org/tip/e90fda0635401225ca7c2343bea2f6d279347d10
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 27 Jan 2012 15:34:22 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 13 Feb 2012 23:27:15 -0200

perf tools: Add sysfs mountpoint interface

Adding sysfs object to provide sysfs mount information in the same way as debugfs object does.

The object provides following function:
sysfs_find_mountpoint

which returns the sysfs mount mount.

---
 tools/perf/Makefile     |    2 +
 tools/perf/util/sysfs.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/sysfs.h |    6 ++++
 3 files changed, 68 insertions(+), 0 deletions(-)
tools/perf/Makefile +2 -0
index 8359fa1..e011b50 100644
@@ -259,6 +259,7 @@ LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/debugfs.h
+LIB_H += util/sysfs.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
@@ -305,6 +306,7 @@ LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/debugfs.o
+LIB_OBJS += $(OUTPUT)util/sysfs.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
tools/perf/util/sysfs.c new file +60 -0

60 lines not on this page · raw message

tools/perf/util/sysfs.h new file +6 -0
new file mode 100644
index 0000000..a813b72
@@ -0,0 +1,6 @@
+#ifndef __SYSFS_H__
+#define __SYSFS_H__
+
+const char *sysfs_find_mountpoint(void);
+
+#endif /* __DEBUGFS_H__ */
author
#47 lore raw

PATCH v3 4/9 perf, tool: Add bitmap_or function into bitmap object

In reply to Jiri Olsa

Adding implementation os bitmap_or function to the bitmap object. It is stolen from the kernel lib/bitmap.o object.

It is used in upcomming patches.

---
 tools/perf/util/bitmap.c               |   10 ++++++++++
 tools/perf/util/include/linux/bitmap.h |   11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
tools/perf/util/bitmap.c +10 -0
index 5e230ac..0a1adc1 100644
@@ -19,3 +19,13 @@ int __bitmap_weight(const unsigned long *bitmap, int bits)
 
 	return w;
 }
+
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits)
+{
+	int k;
+	int nr = BITS_TO_LONGS(bits);
+
+	for (k = 0; k < nr; k++)
+		dst[k] = bitmap1[k] | bitmap2[k];
+}
tools/perf/util/include/linux/bitmap.h +11 -0
index eda4416..bb162e4 100644
@@ -5,6 +5,8 @@
 #include <linux/bitops.h>
 
 int __bitmap_weight(const unsigned long *bitmap, int bits);
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits);
 
 #define BITMAP_LAST_WORD_MASK(nbits)					\
 (									\
@@ -32,4 +34,13 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)
 	return __bitmap_weight(src, nbits);
 }
 
+static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
+			     const unsigned long *src2, int nbits)
+{
+	if (small_const_nbits(nbits))
+		*dst = *src1 | *src2;
+	else
+		__bitmap_or(dst, src1, src2, nbits);
+}
+
 #endif /* _PERF_BITOPS_H */
Signature · 1 line
1.7.4.4
#48 lore raw

[tip:perf/core] perf tools: Add bitmap_or function into bitmap object

Commit-ID:  850f8127fa3666737881aecb3b16e8ede85e58f4
Gitweb:     http://git.kernel.org/tip/850f8127fa3666737881aecb3b16e8ede85e58f4
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 27 Jan 2012 15:34:23 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 13 Feb 2012 23:28:10 -0200

perf tools: Add bitmap_or function into bitmap object

Adding implementation os bitmap_or function to the bitmap object. It is stolen from the kernel lib/bitmap.o object.

It is used in upcomming patches.

---
 tools/perf/util/bitmap.c               |   10 ++++++++++
 tools/perf/util/include/linux/bitmap.h |   11 +++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
tools/perf/util/bitmap.c +10 -0
index 5e230ac..0a1adc1 100644
@@ -19,3 +19,13 @@ int __bitmap_weight(const unsigned long *bitmap, int bits)
 
 	return w;
 }
+
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits)
+{
+	int k;
+	int nr = BITS_TO_LONGS(bits);
+
+	for (k = 0; k < nr; k++)
+		dst[k] = bitmap1[k] | bitmap2[k];
+}
tools/perf/util/include/linux/bitmap.h +11 -0
index eda4416..bb162e4 100644
@@ -5,6 +5,8 @@
 #include <linux/bitops.h>
 
 int __bitmap_weight(const unsigned long *bitmap, int bits);
+void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
+		 const unsigned long *bitmap2, int bits);
 
 #define BITMAP_LAST_WORD_MASK(nbits)					\
 (									\
@@ -32,4 +34,13 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)
 	return __bitmap_weight(src, nbits);
 }
 
+static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
+			     const unsigned long *src2, int nbits)
+{
+	if (small_const_nbits(nbits))
+		*dst = *src1 | *src2;
+	else
+		__bitmap_or(dst, src1, src2, nbits);
+}
+
 #endif /* _PERF_BITOPS_H */
author
#49 lore raw

PATCH v3 5/9 perf: Adding sysfs group format attribute for pmu device

In reply to Jiri Olsa

Adding sysfs group 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each sysfs attribute within the format attribute group, describes mapping of name and bitfield definition within one of above attributes.

eg:
"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/umask" contains "config:8-15"
"/sys/...<dev>/format/usr" contains "config:16"

the attribute value syntax is:

  line:      config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE

Adding format_defined bool to the struct pmu to specify wether pmu defines its own set of format attributes (within the attr_groups member) or the default format attributes should be used:
"/sys/...<dev>/format/config" contains "config:0-63" "/sys/...<dev>/format/config1" contains "config1:0-63" "/sys/...<dev>/format/config2" contains "config2:0-63"

---
 .../testing/sysfs-bus-event_source-devices-format  |   14 ++++++++++++
 include/linux/perf_event.h                         |   22 ++++++++++++++++++++
 kernel/events/core.c                               |   22 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-format
Documentation/ABI/testing/sysfs-bus-event_source-devices-format new file +14 -0
new file mode 100644
index 0000000..079afc7
@@ -0,0 +1,14 @@
+Where:		/sys/bus/event_source/devices/<dev>/format
+Date:		January 2012
+Kernel Version: 3.3
+Contact:	Jiri Olsa <[email protected]>
+Description:
+		Attribute group to describe the magic bits that go into
+		perf_event_attr::config[012] for a particular pmu.
+		Each attribute of this group defines the 'hardware' bitmask
+		we want to export, so that userspace can deal with sane
+		name/value pairs.
+
+		Example: 'config1:1,6-10,44'
+		Defines contents of attribute that occupies bits 1,6-10,44 of
+		perf_event_attr::config1.
include/linux/perf_event.h +22 -0
index 0b91db2..e2bf1c7 100644
@@ -516,6 +516,7 @@ struct perf_guest_info_callbacks {
 #include <linux/irq_work.h>
 #include <linux/jump_label.h>
 #include <linux/atomic.h>
+#include <linux/sysfs.h>
 #include <asm/local.h>
 
 #define PERF_MAX_STACK_DEPTH		255
@@ -626,6 +627,12 @@ struct pmu {
 	int				task_ctx_nr;
 
 	/*
+	 * True if the pmu defines its own set of format attributes within
+	 * attr_groups. If false, default format attributes are used.
+	 */
+	bool				format_defined;
+
+	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
 	 * as well as for lazy/batch writing of the MSRs.
 	 */
@@ -1215,5 +1222,20 @@ do {									\
 	register_cpu_notifier(&fn##_nb);				\
 } while (0)
 
+
+#define PMU_FORMAT_ATTR(_name, _format)				\
+static ssize_t							\
+pmu_format_attr_##_name##_show(struct device *dev,		\
+			       struct device_attribute *attr,	\
+			       char *page)			\
+{								\
+	BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE);		\
+	return sprintf(page, _format "\n");			\
+}								\
+								\
+static struct device_attribute format_attr_##_name =		\
+	__ATTR(_name, 0444,					\
+	       pmu_format_attr_##_name##_show, NULL)
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_PERF_EVENT_H */
kernel/events/core.c +22 -0
index de859fb..8d2d6f3 100644
@@ -5503,6 +5503,22 @@ static struct bus_type pmu_bus = {
 	.dev_attrs	= pmu_dev_attrs,
 };
 
+/* Default format attributes. */
+PMU_FORMAT_ATTR(config,  "config:0-63");
+PMU_FORMAT_ATTR(config1, "config1:0-63");
+PMU_FORMAT_ATTR(config2, "config2:0-63");
+
+static struct attribute *format_attrs[] = {
+	&format_attr_config.attr,
+	&format_attr_config1.attr,
+	&format_attr_config2.attr,
+};
+
+static struct attribute_group format_attr_group = {
+	.name   = "format",
+	.attrs  = format_attrs,
+};
+
 static void pmu_dev_release(struct device *dev)
 {
 	kfree(dev);
@@ -5529,6 +5545,12 @@ static int pmu_dev_alloc(struct pmu *pmu)
 	if (ret)
 		goto free_dev;
 
+	if (!pmu->format_defined) {
+		ret = sysfs_create_group(&pmu->dev->kobj, &format_attr_group);
+		if (ret)
+			goto free_dev;
+	}
+
 out:
 	return ret;
 
Signature · 1 line
1.7.4.4
#50 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 26 lines · Jiri Olsa

Adding sysfs group 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each sysfs attribute within the format attribute group, describes mapping of name and bitfield definition within one of above attributes.

eg:
"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/umask" contains "config:8-15"
"/sys/...<dev>/format/usr" contains "config:16"

the attribute value syntax is:

  line:      config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE
Quoted 7 lines

Adding format_defined bool to the struct pmu to specify wether pmu defines its own set of format attributes (within the attr_groups member) or the default format attributes should be used:
"/sys/...<dev>/format/config" contains "config:0-63" "/sys/...<dev>/format/config1" contains "config1:0-63" "/sys/...<dev>/format/config2" contains "config2:0-63"

Hi Jiri,

I've been out of the perf_events loop for some time, but I did finally notice your patch series thread.

I think what you've done is very good and I'm excited to see progress in this area. However, it's not clear to me that it is as generalized as it needs to be for some PMU's. I say this because not all events on a given PMU will have the same needed fields.

As an example, the IBM PowerEN processor has roughly 20 different PMU's on it. Some of those PMU's are quite complex and divide their events up into subsets, each with different fields. For example, some events may have a PID matching field, and others may have an bus number matching field, or matching mode field, etc. The fields are different widths, and may overlap in the config/1/2 space.

It seems that there are two approaches you could take:

1) Keep your format, but allow the fields to overlap in the bit space. For example:

"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/pidmatch" contains "config:8-15"
"/sys/...<dev>/format/busmatch" contains "config:8-13"

Note that busmatch overlaps pidmatch

2) Create event groups that have their overlapping config space separated out:

"/sys/...<dev>/format/event" contains "config:0-7"

"/sys/...<dev>.1/format/pidmatch" contains "config:8-15"

"/sys/...<dev>.2/format/busmatch" contains "config:8-13"

Notice the .1 and .2 on the <dev>.

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

- Corey

#51 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 28 lines · Corey Ashford

s an example, the IBM PowerEN processor has roughly 20 different PMU's on it. Some of those PMU's are quite complex and divide their events up into subsets, each with different fields. For example, some events may have a PID matching field, and others may have an bus number matching field, or matching mode field, etc. The fields are different widths, and may overlap in the config/1/2 space.

It seems that there are two approaches you could take:

1) Keep your format, but allow the fields to overlap in the bit space. For example:

"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/pidmatch" contains "config:8-15"
"/sys/...<dev>/format/busmatch" contains "config:8-13"

Note that busmatch overlaps pidmatch

2) Create event groups that have their overlapping config space separated out:

"/sys/...<dev>/format/event" contains "config:0-7"

"/sys/...<dev>.1/format/pidmatch" contains "config:8-15"

"/sys/...<dev>.2/format/busmatch" contains "config:8-13"

Quoted 6 lines

Notice the .1 and .2 on the <dev>.

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

Why try and stuff those 20 in a single driver? Have 20 drivers and each their own format/ hierarchy.

#52 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 31 lines · Peter Zijlstra
Quoted 30 lines · Corey Ashford

s an example, the IBM PowerEN processor has roughly 20 different PMU's on it. Some of those PMU's are quite complex and divide their events up into subsets, each with different fields. For example, some events may have a PID matching field, and others may have an bus number matching field, or matching mode field, etc. The fields are different widths, and may overlap in the config/1/2 space.

It seems that there are two approaches you could take:

1) Keep your format, but allow the fields to overlap in the bit space. For example:

"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/pidmatch" contains "config:8-15"
"/sys/...<dev>/format/busmatch" contains "config:8-13"

Note that busmatch overlaps pidmatch

2) Create event groups that have their overlapping config space separated out:

"/sys/...<dev>/format/event" contains "config:0-7"

"/sys/...<dev>.1/format/pidmatch" contains "config:8-15"

"/sys/...<dev>.2/format/busmatch" contains "config:8-13"

Notice the .1 and .2 on the <dev>.

Quoted 7 lines
Quoted 4 lines

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

Why try and stuff those 20 in a single driver? Have 20 drivers and each their own format/ hierarchy.

I'm sure that could work. Since sysfs seems to be fairly independent (if necessary) of the hardware structure, I suppose this wouldn't be a problem.

What do you think of Jiri's (Jirka's ?) other ideas of subdividing the format directory?

- Corey

author
#53 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

In reply to Corey Ashford
Quoted 38 lines · Corey Ashford
Quoted 26 lines · Jiri Olsa

Adding sysfs group 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each sysfs attribute within the format attribute group, describes mapping of name and bitfield definition within one of above attributes.

eg:
"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/umask" contains "config:8-15"
"/sys/...<dev>/format/usr" contains "config:16"

the attribute value syntax is:

  line:      config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE
Quoted 7 lines

Adding format_defined bool to the struct pmu to specify wether pmu defines its own set of format attributes (within the attr_groups member) or the default format attributes should be used:
"/sys/...<dev>/format/config" contains "config:0-63" "/sys/...<dev>/format/config1" contains "config1:0-63" "/sys/...<dev>/format/config2" contains "config2:0-63"

Hi Jiri,

Quoted 7 lines

I've been out of the perf_events loop for some time, but I did finally notice your patch series thread.

I think what you've done is very good and I'm excited to see progress in this area. However, it's not clear to me that it is as generalized as it needs to be for some PMU's. I say this because not all events on a given PMU will have the same needed fields.

ok, I wasn't aware of this

Quoted 10 lines

As an example, the IBM PowerEN processor has roughly 20 different PMU's on it. Some of those PMU's are quite complex and divide their events up into subsets, each with different fields. For example, some events may have a PID matching field, and others may have an bus number matching field, or matching mode field, etc. The fields are different widths, and may overlap in the config/1/2 space.

It seems that there are two approaches you could take:

Quoted 8 lines

1) Keep your format, but allow the fields to overlap in the bit space. For example:

"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/pidmatch" contains "config:8-15"
"/sys/...<dev>/format/busmatch" contains "config:8-13"

Note that busmatch overlaps pidmatch

currently format fields definitions may overlap, there's no check to prevent that

Quoted 11 lines

2) Create event groups that have their overlapping config space separated out:

"/sys/...<dev>/format/event" contains "config:0-7"

"/sys/...<dev>.1/format/pidmatch" contains "config:8-15"

"/sys/...<dev>.2/format/busmatch" contains "config:8-13"

Quoted 6 lines

Notice the .1 and .2 on the <dev>.

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

Though I'm not sure we want allow separate devices inside single pmu, I think we could have multiple format groups if necessary :)

some quick ideas:

1) having format group attribute under format like:
<dev>/format/group1/.. <dev>/format/group2/.. <dev>/format/group2/..
...

2) having format group name within the format attribute name like:
<dev>/format/group1-krava1 <dev>/format/group1-krava2 <dev>/format/group2-krava3
...

3) having group name inside the foramt attributes like:
cat <dev>/format/group1-krava1
group1 config:0-1,62-63

I think I like the most ad 1)..

We could have something like default format directory if there's only a single format group, like:
<dev>/format/default/krava1 <dev>/format/default/krava2
...

The perf event syntax could have something like '::' to classify format attribute with a group like (none would go to default dir):

cpu/group1::config=1,group2::config1=2,config2=3/u
or
cpu::group1/config=1,config1=2,config2=3/u

Or we could say the format field names could not overlap and then we dont need to specify group at all :) It'd be just for user's awareness..

Any idea if we at all want to go this way? ;)

thanks,
jirka

#54 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 115 lines · Jiri Olsa
Quoted 38 lines · Corey Ashford
Quoted 26 lines · Jiri Olsa

Adding sysfs group 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

The event configuration is described in following
struct pefr_event_attr attributes:

config
config1
config2

Each sysfs attribute within the format attribute group, describes mapping of name and bitfield definition within one of above attributes.

eg:
"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/umask" contains "config:8-15"
"/sys/...<dev>/format/usr" contains "config:16"

the attribute value syntax is:

  line:      config ':' bits
  config:    'config' | 'config1' | 'config2"
  bits:      bits ',' bit_term | bit_term
  bit_term:  VALUE '-' VALUE | VALUE
Quoted 7 lines

Adding format_defined bool to the struct pmu to specify wether pmu defines its own set of format attributes (within the attr_groups member) or the default format attributes should be used:
"/sys/...<dev>/format/config" contains "config:0-63" "/sys/...<dev>/format/config1" contains "config1:0-63" "/sys/...<dev>/format/config2" contains "config2:0-63"

Hi Jiri,

Quoted 7 lines

I've been out of the perf_events loop for some time, but I did finally notice your patch series thread.

I think what you've done is very good and I'm excited to see progress in this area. However, it's not clear to me that it is as generalized as it needs to be for some PMU's. I say this because not all events on a given PMU will have the same needed fields.

ok, I wasn't aware of this

Quoted 10 lines

As an example, the IBM PowerEN processor has roughly 20 different PMU's on it. Some of those PMU's are quite complex and divide their events up into subsets, each with different fields. For example, some events may have a PID matching field, and others may have an bus number matching field, or matching mode field, etc. The fields are different widths, and may overlap in the config/1/2 space.

It seems that there are two approaches you could take:

Quoted 8 lines

1) Keep your format, but allow the fields to overlap in the bit space. For example:

"/sys/...<dev>/format/event" contains "config:0-7" "/sys/...<dev>/format/pidmatch" contains "config:8-15"
"/sys/...<dev>/format/busmatch" contains "config:8-13"

Note that busmatch overlaps pidmatch

currently format fields definitions may overlap, there's no check to prevent that

Quoted 11 lines

2) Create event groups that have their overlapping config space separated out:

"/sys/...<dev>/format/event" contains "config:0-7"

"/sys/...<dev>.1/format/pidmatch" contains "config:8-15"

"/sys/...<dev>.2/format/busmatch" contains "config:8-13"

Quoted 6 lines

Notice the .1 and .2 on the <dev>.

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

Though I'm not sure we want allow separate devices inside single pmu, I think we could have multiple format groups if necessary :)

some quick ideas:

1) having format group attribute under format like:

   <dev>/format/group1/..
   <dev>/format/group2/..
   <dev>/format/group2/..
   ...

2) having format group name within the format attribute name like:

   <dev>/format/group1-krava1
   <dev>/format/group1-krava2
   <dev>/format/group2-krava3
   ...

3) having group name inside the foramt attributes like:

   cat <dev>/format/group1-krava1
   group1 config:0-1,62-63

I think I like the most ad 1)..

We could have something like default format directory if there's only a single format group, like:

Quoted 8 lines
   <dev>/format/default/krava1
   <dev>/format/default/krava2
   ...

The perf event syntax could have something like '::' to classify format attribute with a group like (none would go to default dir):

   cpu/group1::config=1,group2::config1=2,config2=3/u

The "[::<group>|]" syntax is good.

Are you are suggesting that a single event could use multiple groups because they may share some common fields, such as the event code? If
so, I think that might be confusing. I think it would be better to
have every group fully lay out the bits in the config{,1,2} fields so that you only need to specify one group per event, even if that leads to some redundancy (e.g. group1..n all have an eventcode field.)

Something I missed before is that your config sysfs attribute group can look like:

config1:0-1,62-63

How does the user specify a value for these two bit fields, or does he concatenate the bit fields together, and perf will split it apart again?
e.g. cpu/group1::config1=1,2/u ?

Quoted 7 lines

or
cpu::group1/config=1,config1=2,config2=3/u

Or we could say the format field names could not overlap and then we dont need to specify group at all :) It'd be just for user's awareness..

perf would then "want" to check for overlap and also for fields coming from different groups. In some cases, I think you'd want to have the same name for a field, but have the field a different size, or perhaps a
different interpretation. For example "busid" might be a desirable
name for fields in two different event groups, but their sizes and position are different. Of course the quick fix is to name them uniquely, but since they are in subdirectories, it isn't really obvious that the names have to be unique.

One other comment that occurs to me is that it would be nice for perf to know when a supplied value is out of range, or will have undefined results. For example, a field may be 8 bits wide, but not all 8-bit values are legal. For example, there may be 208 events, and the codes may be somehwhat or even very sparsely encoded. So, ideally, a config field in sysfs might look like this:

config1:0-7:0x0-0xd8,0xdb-0xe2,0xe4-0xe6

This way perf could check for valid values before stuffing them into registers, and give a good error message to the user. If there is no restriction field, it would be assumed all of the possible values are valid.

I think the kernel code needs to check for bad values as well, because people can bypass the restrictions exposed by sysfs and use the perf_events API directly.

- Corey

author
#55 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 6 lines · Corey Ashford
Quoted 5 lines · Jiri Olsa
Quoted 4 lines · Corey Ashford
Quoted 3 lines · Jiri Olsa

Adding sysfs group 'format' attribute for pmu device that contains a syntax description on how to construct raw events.

SNIP

Quoted 40 lines
Quoted 31 lines
Quoted 4 lines

This might help the user understand which fields go together. I'm not sold on the .1 syntax... you could do it as <dev>.<event-group-name>/ or <dev>/<event-group-name>/... or whatever seems to make the most sense and is relatively easy to implement and use.

Though I'm not sure we want allow separate devices inside single pmu, I think we could have multiple format groups if necessary :)

some quick ideas:

1) having format group attribute under format like:

   <dev>/format/group1/..
   <dev>/format/group2/..
   <dev>/format/group2/..
   ...

2) having format group name within the format attribute name like:

   <dev>/format/group1-krava1
   <dev>/format/group1-krava2
   <dev>/format/group2-krava3
   ...

3) having group name inside the foramt attributes like:

   cat <dev>/format/group1-krava1
   group1 config:0-1,62-63

I think I like the most ad 1)..

We could have something like default format directory if there's only a single format group, like:

Quoted 8 lines
   <dev>/format/default/krava1
   <dev>/format/default/krava2
   ...

The perf event syntax could have something like '::' to classify format attribute with a group like (none would go to default dir):

   cpu/group1::config=1,group2::config1=2,config2=3/u
Quoted 8 lines

The "[::<group>|]" syntax is good.

Are you are suggesting that a single event could use multiple groups because they may share some common fields, such as the event code? If
so, I think that might be confusing. I think it would be better to
have every group fully lay out the bits in the config{,1,2} fields so that you only need to specify one group per event, even if that leads to some redundancy (e.g. group1..n all have an eventcode field.)

ok, it'd be the 'cpu::group1/config=1,config1=2,config2=3/u' then..

but let's see what Peter thinks about this, since he first suggested to 'fix' this by having separate pmu drivers.. not format groups :)

Quoted 9 lines

Something I missed before is that your config sysfs attribute group can look like:

config1:0-1,62-63

How does the user specify a value for these two bit fields, or does he concatenate the bit fields together, and perf will split it apart again?
e.g. cpu/group1::config1=1,2/u ?

user just set the value for the field and perf makes sure it is spread over the config[12] bits as configured

so as for your example, following format definiton:

	# cat <pmu>/format/krava
        config1:0-1,62-63

with user settings:

	cpu/krava=15/u

fills bits 0,1,62,63 of config1 with 1s

Quoted 28 lines
Quoted 9 lines

or
cpu::group1/config=1,config1=2,config2=3/u

Or we could say the format field names could not overlap and then we dont need to specify group at all :) It'd be just for user's awareness..

perf would then "want" to check for overlap and also for fields coming from different groups. In some cases, I think you'd want to have the same name for a field, but have the field a different size, or perhaps a
different interpretation. For example "busid" might be a desirable
name for fields in two different event groups, but their sizes and position are different. Of course the quick fix is to name them uniquely, but since they are in subdirectories, it isn't really obvious that the names have to be unique.

One other comment that occurs to me is that it would be nice for perf to know when a supplied value is out of range, or will have undefined results. For example, a field may be 8 bits wide, but not all 8-bit values are legal. For example, there may be 208 events, and the codes may be somehwhat or even very sparsely encoded. So, ideally, a config field in sysfs might look like this:

config1:0-7:0x0-0xd8,0xdb-0xe2,0xe4-0xe6

Quoted 7 lines

This way perf could check for valid values before stuffing them into registers, and give a good error message to the user. If there is no restriction field, it would be assumed all of the possible values are valid.

I think the kernel code needs to check for bad values as well, because people can bypass the restrictions exposed by sysfs and use the perf_events API directly.

ok, I think some kind of such restriction could be added as optional ':' behind the current format if needed.. np

thanks,
jirka

#56 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 11 lines · Jiri Olsa
Quoted 6 lines

Are you are suggesting that a single event could use multiple groups because they may share some common fields, such as the event code? If
so, I think that might be confusing. I think it would be better to
have every group fully lay out the bits in the config{,1,2} fields so that you only need to specify one group per event, even if that leads to some redundancy (e.g. group1..n all have an eventcode field.)

ok, it'd be the 'cpu::group1/config=1,config1=2,config2=3/u' then..

but let's see what Peter thinks about this, since he first suggested to 'fix' this by having separate pmu drivers.. not format groups :)

I'm not convinced we need the whole grouping thing. Even x86 might have overlapping definitions, even for a single PMU (config1 contents will radically differ depending on the actual events used for instance).

All we should do is warn the user when overlapping masks are used in a single event definition and other than that just do as they tell us.

PMUs can always do an informal namespace thing if really needed, eg. by using a consistent prefix.

author
#57 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Jiri Olsa
Quoted 6 lines

Are you are suggesting that a single event could use multiple groups because they may share some common fields, such as the event code? If
so, I think that might be confusing. I think it would be better to
have every group fully lay out the bits in the config{,1,2} fields so that you only need to specify one group per event, even if that leads to some redundancy (e.g. group1..n all have an eventcode field.)

Quoted 8 lines
Quoted 4 lines

ok, it'd be the 'cpu::group1/config=1,config1=2,config2=3/u' then..

but let's see what Peter thinks about this, since he first suggested to 'fix' this by having separate pmu drivers.. not format groups :)

I'm not convinced we need the whole grouping thing. Even x86 might have overlapping definitions, even for a single PMU (config1 contents will radically differ depending on the actual events used for instance).

well, I think let's go with what we have now, and see if need/want to care about format groups later after we use it for a while..

since the "cpu/..../" syntax is new interface, there should be no problem to change it

Quoted 3 lines

All we should do is warn the user when overlapping masks are used in a single event definition and other than that just do as they tell us.

that should be no problem..
do you want it in to take this.. ooor is later ok ;)

jirka

Quoted 4 lines

PMUs can always do an informal namespace thing if really needed, eg. by using a consistent prefix.

#58 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 1 line · Jiri Olsa

ooor is later ok ;)

later is fine ;-)

#59 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

In reply to Corey Ashford
Quoted 10 lines · Corey Ashford

One other comment that occurs to me is that it would be nice for perf to know when a supplied value is out of range, or will have undefined results. For example, a field may be 8 bits wide, but not all 8-bit values are legal. For example, there may be 208 events, and the codes may be somehwhat or even very sparsely encoded. So, ideally, a config field in sysfs might look like this:

config1:0-7:0x0-0xd8,0xdb-0xe2,0xe4-0xe6

Quoted 7 lines

This way perf could check for valid values before stuffing them into registers, and give a good error message to the user. If there is no restriction field, it would be assumed all of the possible values are valid.

I think the kernel code needs to check for bad values as well, because people can bypass the restrictions exposed by sysfs and use the perf_events API directly.

Define bad? The only case where perf cares (from a kernel pov) is when it can make the hardware melt and similar things. Programming the PMU in a non-nonsensical but non-destructive way is fine, you get what you ask for.

#60 lore raw

Re: [PATCH 5/9] perf: Adding sysfs group format attribute for pmu device

Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Corey Ashford

One other comment that occurs to me is that it would be nice for perf to know when a supplied value is out of range, or will have undefined results. For example, a field may be 8 bits wide, but not all 8-bit values are legal. For example, there may be 208 events, and the codes may be somehwhat or even very sparsely encoded. So, ideally, a config field in sysfs might look like this:

config1:0-7:0x0-0xd8,0xdb-0xe2,0xe4-0xe6

This way perf could check for valid values before stuffing them into registers, and give a good error message to the user. If there is no restriction field, it would be assumed all of the possible values are valid.

Quoted 8 lines
Quoted 3 lines

I think the kernel code needs to check for bad values as well, because people can bypass the restrictions exposed by sysfs and use the perf_events API directly.

Define bad? The only case where perf cares (from a kernel pov) is when it can make the hardware melt and similar things. Programming the PMU in a non-nonsensical but non-destructive way is fine, you get what you ask for.

The main definition of "bad" would be a known config that has no meaning (or perhaps is improperly implemented on the chip). This would just give the user some extra help that he might have incorrectly configured the PMU. Perf could identify down to the specific field that may not be set correctly. You could add an override switch to perf (--force-config etc.) that would allow the user to bypass the check if he really wanted to use that config.

It's also conceivable that there would be known PMU modes, that let's say, stores values into a memory buffer (like IBS, etc), that if you use a particular config, it would overwhelm the memory bus and choke the processor down.

That said, this feature would just be nice to have, and is only on my wish list.

Thanks for considering comments,

- Corey

author
#61 lore raw

PATCH v3 6/9 perf, tool: Add parser generator for events parsing

In reply to Jiri Olsa

Changing event parsing to use flex/bison parse generator. The event syntax stays as it was.

grammar description:

events: events ',' event | event

event: event_def PE_MODIFIER_EVENT | event_def

event_def: event_legacy_symbol sep_dc     |
           event_legacy_cache sep_dc      |
           event_legacy_breakpoint sep_dc |
           event_legacy_tracepoint sep_dc |
           event_legacy_numeric sep_dc    |

event_legacy_raw sep_dc

event_legacy_symbol: PE_NAME_SYM

event_legacy_cache: PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT |
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | PE_NAME_CACHE_TYPE

event_legacy_raw: PE_SEP_RAW PE_VALUE

event_legacy_numeric: PE_VALUE ':' PE_VALUE

event_legacy_breakpoint: PE_SEP_BP ':' PE_VALUE ':' PE_MODIFIER_BP

event_breakpoint_type: PE_MODIFIER_BPTYPE | empty

PE_NAME_SYM:              cpu-cycles|cycles                              |
                          stalled-cycles-frontend|idle-cycles-frontend   |
                          stalled-cycles-backend|idle-cycles-backend     |
                          instructions                                   |
                          cache-references                               |
                          cache-misses                                   |
                          branch-instructions|branches                   |
                          branch-misses                                  |
                          bus-cycles                                     |
                          cpu-clock                                      |
                          task-clock                                     |
                          page-faults|faults                             |
                          minor-faults                                   |
                          major-faults                                   |
                          context-switches|cs                            |
                          cpu-migrations|migrations                      |
                          alignment-faults                               |

emulation-faults

PE_NAME_CACHE_TYPE:       L1-dcache|l1-d|l1d|L1-data             |
                          L1-icache|l1-i|l1i|L1-instruction      |
                          LLC|L2                                 |
                          dTLB|d-tlb|Data-TLB                    |
                          iTLB|i-tlb|Instruction-TLB             |
                          branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT:  load|loads|read                        |
                          store|stores|write                     |
                          prefetch|prefetches                    |
                          speculative-read|speculative-load      |
                          refs|Reference|ops|access              |

misses|miss

PE_MODIFIER_EVENT: [ukhp]{0,5}

PE_MODIFIER_BP: [rwx]

PE_SEP_BP: 'mem'

PE_SEP_RAW: 'r'

sep_dc: ':' |

Added flex/bison files for event grammar parsing. The generated parser is part of the patch. Added makefile rule 'event-parser' to generate the parser code out of the bison/flex sources.

---
 tools/perf/Makefile                  |   17 +
 tools/perf/builtin-test.c            |    6 +-
 tools/perf/util/parse-events-bison.c | 1715 ++++++++++++++++++++++++++
 tools/perf/util/parse-events-bison.h |   79 ++
 tools/perf/util/parse-events-flex.c  | 2225 ++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events-flex.h  |  316 +++++
 tools/perf/util/parse-events.c       |  486 +++------
 tools/perf/util/parse-events.h       |   15 +
 tools/perf/util/parse-events.l       |  107 ++
 tools/perf/util/parse-events.y       |  127 ++
 10 files changed, 4752 insertions(+), 341 deletions(-)
 create mode 100644 tools/perf/util/parse-events-bison.c
 create mode 100644 tools/perf/util/parse-events-bison.h
 create mode 100644 tools/perf/util/parse-events-flex.c
 create mode 100644 tools/perf/util/parse-events-flex.h
 create mode 100644 tools/perf/util/parse-events.l
 create mode 100644 tools/perf/util/parse-events.y
tools/perf/Makefile +17 -0
index f170235..ee48082 100644
@@ -47,6 +47,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
+FLEX = $(CROSS_COMPILE)flex
+BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
@@ -340,6 +342,8 @@ LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
+LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -628,6 +632,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_FLEX     = @echo '   ' FLEX $@;
+	QUIET_BISON    = @echo '   ' BISON $@;
 endif
 endif
 
@@ -708,6 +714,9 @@ $(OUTPUT)perf.o perf.spec \
 	$(SCRIPTS) \
 	: $(OUTPUT)PERF-VERSION-FILE
 
+.SUFFIXES:
+.SUFFIXES: .o .c .S .s
+
 $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
@@ -740,6 +749,9 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -776,6 +788,7 @@ help:
 	@echo '  html		- make html documentation'
 	@echo '  info		- make GNU info documentation (access with info <foo>)'
 	@echo '  pdf		- make pdf documentation'
+	@echo '  event-parser	- make event parser code'
 	@echo '  TAGS		- use etags to make tag information for source browsing'
 	@echo '  tags		- use ctags to make tag information for source browsing'
 	@echo '  cscope	- use cscope to make interactive browsing database'
@@ -826,6 +839,10 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+event-parser:
+	$(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c
+	$(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/builtin-test.c +3 -3
index 70c4eb2..adf959f 100644
@@ -650,7 +650,7 @@ static int test__checkevent_raw(struct perf_evlist *evlist)
 
 	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
 	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
-	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
 	return 0;
 }
 
@@ -872,7 +872,7 @@ static struct test__event_st {
 		.check = test__checkevent_tracepoint_multi,
 	},
 	{
-		.name  = "r1",
+		.name  = "r1a",
 		.check = test__checkevent_raw,
 	},
 	{
@@ -916,7 +916,7 @@ static struct test__event_st {
 		.check = test__checkevent_tracepoint_multi_modifier,
 	},
 	{
-		.name  = "r1:kp",
+		.name  = "r1a:kp",
 		.check = test__checkevent_raw_modifier,
 	},
 	{
tools/perf/util/parse-events-bison.c new file +1715 -0

1,715 lines not on this page · raw message

tools/perf/util/parse-events-bison.h new file +79 -0

79 lines not on this page · raw message

tools/perf/util/parse-events-flex.c new file +2225 -0

1,123 lines not on this page · raw message

tools/perf/util/parse-events-flex.h new file +316 -0

316 lines not on this page · raw message

tools/perf/util/parse-events.c +148 -338

486 lines not on this page · raw message

tools/perf/util/parse-events.h +15 -0
index 7e0cbe7..84d3771 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/parse-events.l new file +107 -0

107 lines not on this page · raw message

tools/perf/util/parse-events.y new file +127 -0

127 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.4.4

Part of the diff is not shown here. View the raw message.

author
#62 lore raw

PATCH v3 7/9 perf, tool: Add config options support for event parsing

In reply to Jiri Olsa

Adding a new rule to the event grammar to be able to specify values of additional attributes of symbolic event.

The new syntax for event symbolic definition is:

event_legacy_symbol: PE_NAME_SYM '/' event_config '/' |
PE_NAME_SYM sep_slash_dc

event_config: event_config ',' event_term | event_term

event_term: PE_NAME '=' PE_NAME |
PE_NAME '=' PE_VALUE

sep_slash_dc: '/' | ':' |

At the moment the code is recognizing only 'period' config option, which modifies value sample_period event attribute.

Use is now allowed to specify events like:
cycles/period=100000/

---
 tools/perf/builtin-test.c            |   18 +++
 tools/perf/util/parse-events-bison.c |  245 +++++++++++++++++++++++-----------
 tools/perf/util/parse-events-bison.h |    6 +-
 tools/perf/util/parse-events.c       |   75 ++++++++++-
 tools/perf/util/parse-events.h       |   22 +++-
 tools/perf/util/parse-events.y       |   66 +++++++++-
 6 files changed, 340 insertions(+), 92 deletions(-)
tools/perf/builtin-test.c +18 -0
index adf959f..e46bf21 100644
@@ -677,6 +677,20 @@ static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong period",
+			100000 == evsel->attr.sample_period);
+	return 0;
+}
+
 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
 {
 	struct perf_evsel *evsel = list_entry(evlist->entries.next,
@@ -884,6 +898,10 @@ static struct test__event_st {
 		.check = test__checkevent_symbolic_name,
 	},
 	{
+		.name  = "cycles/period=100000/",
+		.check = test__checkevent_symbolic_name_config,
+	},
+	{
 		.name  = "faults",
 		.check = test__checkevent_symbolic_alias,
 	},
tools/perf/util/parse-events-bison.c +164 -81

442 lines not on this page · raw message

tools/perf/util/parse-events-bison.h +4 -2
index 097a632..b73c4bd 100644
@@ -59,15 +59,17 @@ typedef union YYSTYPE
 {
 
 /* Line 1685 of yacc.c  */
-#line 42 "util/parse-events.y"
+#line 44 "util/parse-events.y"
 
 	char *str;
 	unsigned long num;
+	struct list_head *head;
+	struct parse_events__term *term;
 
 
 
 /* Line 1685 of yacc.c  */
-#line 71 "util/parse-events-bison.h"
+#line 73 "util/parse-events-bison.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
tools/perf/util/parse-events.c +72 -3

90 lines not on this page · raw message

tools/perf/util/parse-events.h +21 -1
index 84d3771..2737f1e 100644
@@ -33,6 +33,25 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 #define EVENTS_HELP_MAX (128*1024)
 
+enum {
+	PARSE_EVENTS__TERM_TYPE_NUM,
+	PARSE_EVENTS__TERM_TYPE_STR,
+};
+
+struct parse_events__term {
+	char *config;
+	union {
+		char *str;
+		long  num;
+	} val;
+	int type;
+
+	struct list_head list;
+};
+
+int parse_events__new_term(struct parse_events__term **term, int type,
+			   char *config, char *str, long num);
+void parse_events__free_terms(struct list_head *terms);
 int parse_events_modifier(struct list_head *list __used, char *str __used);
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event);
@@ -40,7 +59,8 @@ int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config,
 			 unsigned long config1, unsigned long config2,
 			 char *mod);
 int parse_events_add_numeric(struct list_head *list, int *idx,
-			     unsigned long type, unsigned long config);
+			     unsigned long type, unsigned long config,
+			     struct list_head *head_config);
 int parse_events_add_cache(struct list_head *list, int *idx,
 			   char *type, char *op_result1, char *op_result2);
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
tools/perf/util/parse-events.y +61 -5

108 lines not on this page · raw message

Signature · 1 line
1.7.4.4
author
#63 lore raw

PATCH v3 8/9 perf, tool: Add perf pmu object to access pmu format definition

In reply to Jiri Olsa

Adding pmu object which provides interface to pmu's sysfs event format definition located at:
${sysfs_mount}/bus/event_source/devices/${pmu}/format

Following interface is exported:
struct perf_pmu* perf_pmu__find(char *name);
- this function returns pmu object, which is then passed as a handle to other interface functions

int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,

                       struct list_head *head_terms);

- this function configures perf_event_attr struct based on pmu's format definitions and config terms data, containined in head_terms list.

Parser generator is used to retrive the pmu's format definition. The generated parser is part of the patch. Added makefile rule 'pmu-parser' to generate the parser code out of the bison/flex sources.

Added builtin test 'Test perf pmu format parsing', which could be run like:
perf test pmu

---
 tools/perf/Makefile         |   12 +
 tools/perf/builtin-test.c   |   10 +
 tools/perf/util/pmu-bison.c | 1663 +++++++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu-bison.h |   73 ++
 tools/perf/util/pmu-flex.c  | 1821 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu-flex.h  |  316 ++++++++
 tools/perf/util/pmu.c       |  462 +++++++++++
 tools/perf/util/pmu.h       |   41 +
 tools/perf/util/pmu.l       |   43 +
 tools/perf/util/pmu.y       |   93 +++
 10 files changed, 4534 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/util/pmu-bison.c
 create mode 100644 tools/perf/util/pmu-bison.h
 create mode 100644 tools/perf/util/pmu-flex.c
 create mode 100644 tools/perf/util/pmu-flex.h
 create mode 100644 tools/perf/util/pmu.c
 create mode 100644 tools/perf/util/pmu.h
 create mode 100644 tools/perf/util/pmu.l
 create mode 100644 tools/perf/util/pmu.y
tools/perf/Makefile +12 -0
index ee48082..0b9a40e 100644
@@ -259,6 +259,7 @@ LIB_H += util/build-id.h
 LIB_H += util/debug.h
 LIB_H += util/debugfs.h
 LIB_H += util/sysfs.h
+LIB_H += util/pmu.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
 LIB_H += util/evlist.h
@@ -306,6 +307,7 @@ LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
 LIB_OBJS += $(OUTPUT)util/debugfs.o
 LIB_OBJS += $(OUTPUT)util/sysfs.o
+LIB_OBJS += $(OUTPUT)util/pmu.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
 LIB_OBJS += $(OUTPUT)util/evlist.o
@@ -344,6 +346,8 @@ LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
 LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
 LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
+LIB_OBJS += $(OUTPUT)util/pmu-flex.o
+LIB_OBJS += $(OUTPUT)util/pmu-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -752,6 +756,9 @@ $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
 
+$(OUTPUT)util/pmu-flex.o: util/pmu-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -789,6 +796,7 @@ help:
 	@echo '  info		- make GNU info documentation (access with info <foo>)'
 	@echo '  pdf		- make pdf documentation'
 	@echo '  event-parser	- make event parser code'
+	@echo '  pmu-parser	- make pmu format parser code'
 	@echo '  TAGS		- use etags to make tag information for source browsing'
 	@echo '  tags		- use ctags to make tag information for source browsing'
 	@echo '  cscope	- use cscope to make interactive browsing database'
@@ -843,6 +851,10 @@ event-parser:
 	$(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c
 	$(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c
 
+pmu-parser:
+	$(QUIET_BISON)$(BISON) -v util/pmu.y -d -o util/pmu-bison.c
+	$(QUIET_FLEX)$(FLEX) --header-file=util/pmu-flex.h -t util/pmu.l > util/pmu-flex.c
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/builtin-test.c +10 -0
index e46bf21..1969d3f 100644
@@ -13,6 +13,7 @@
 #include "util/parse-events.h"
 #include "util/symbol.h"
 #include "util/thread_map.h"
+#include "util/pmu.h"
 #include "../../include/linux/hw_breakpoint.h"
 
 #include <sys/mman.h>
@@ -1483,6 +1484,11 @@ static int test__rdpmc(void)
 
 #endif
 
+static int test__perf_pmu(void)
+{
+	return perf_pmu__test();
+}
+
 static struct test {
 	const char *desc;
 	int (*func)(void);
@@ -1518,6 +1524,10 @@ static struct test {
 		.func = test__PERF_RECORD,
 	},
 	{
+		.desc = "Test perf pmu format parsing",
+		.func = test__perf_pmu,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/util/pmu-bison.c new file +1663 -0

1,663 lines not on this page · raw message

tools/perf/util/pmu-bison.h new file +73 -0

73 lines not on this page · raw message

tools/perf/util/pmu-flex.c new file +1821 -0

1,188 lines not on this page · raw message

tools/perf/util/pmu-flex.h new file +316 -0

316 lines not on this page · raw message

tools/perf/util/pmu.c new file +462 -0

462 lines not on this page · raw message

tools/perf/util/pmu.h new file +41 -0

41 lines not on this page · raw message

tools/perf/util/pmu.l new file +43 -0

43 lines not on this page · raw message

tools/perf/util/pmu.y new file +93 -0

93 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.4.4

Part of the diff is not shown here. View the raw message.

author
#64 lore raw

PATCH v3 9/9 perf, tool: Add support to specify pmu style event

In reply to Jiri Olsa

Added new event rule to the event definition grammar:

event_def: event_pmu |

           ...

event_pmu: PE_NAME '/' event_config '/'

Using this rule, event could be now specified like:
cpu/config=1,config1=2,config2=3/u

where pmu name 'cpu' is looked up via following path:
${sysfs_mount}/bus/event_source/devices/${pmu}

and config options are bound to the pmu's format definiton:
${sysfs_mount}/bus/event_source/devices/${pmu}/format

---
 tools/perf/builtin-test.c            |   18 ++++
 tools/perf/util/parse-events-bison.c |  187 ++++++++++++++++++----------------
 tools/perf/util/parse-events.c       |   19 ++++
 tools/perf/util/parse-events.h       |    2 +
 tools/perf/util/parse-events.y       |   10 ++-
 5 files changed, 149 insertions(+), 87 deletions(-)
tools/perf/builtin-test.c +18 -0
index 1969d3f..ecfbf20 100644
@@ -873,6 +873,20 @@ static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
 	return test__checkevent_genhw(evlist);
 }
 
+static int test__checkevent_pmu(struct perf_evlist *evlist)
+{
+
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config2);
+	return 0;
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -954,6 +968,10 @@ static struct test__event_st {
 		.name  = "L1-dcache-load-miss:kp",
 		.check = test__checkevent_genhw_modifier,
 	},
+	{
+		.name  = "cpu/config=1,config1=2,config2=3/u",
+		.check = test__checkevent_pmu,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
tools/perf/util/parse-events-bison.c +101 -86

389 lines not on this page · raw message

tools/perf/util/parse-events.c +19 -0
index 7423049..cce8b7a 100644
@@ -12,6 +12,7 @@
 #include "header.h"
 #include "debugfs.h"
 #include "parse-events-flex.h"
+#include "pmu.h"
 
 #define MAX_NAME_LEN 100
 
@@ -632,6 +633,24 @@ int parse_events_add_numeric(struct list_head *list, int *idx,
 			 (char *) __event_name(type, config));
 }
 
+int parse_events_add_pmu(struct list_head *list, int *idx,
+			 char *name, struct list_head *head_config)
+{
+	struct perf_event_attr attr;
+	struct perf_pmu *pmu;
+
+	pmu = perf_pmu__find(name);
+	if (!pmu)
+		return -EINVAL;
+
+	memset(&attr, 0, sizeof(attr));
+
+	if (perf_pmu__config(pmu, &attr, head_config))
+		return -EINVAL;
+
+	return add_event(list, idx, &attr, (char *) "pmu");
+}
+
 int parse_events_modifier(struct list_head *list, char *str)
 {
 	struct perf_evsel *evsel;
tools/perf/util/parse-events.h +2 -0
index 2737f1e..0ebc68c 100644
@@ -65,6 +65,8 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 			   char *type, char *op_result1, char *op_result2);
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
 				void *ptr, char *type);
+int parse_events_add_pmu(struct list_head *list, int *idx,
+			 char *pmu , struct list_head *head_config);
 void parse_events_error(struct list_head *list, int *idx,
 			char const *msg);
 
tools/perf/util/parse-events.y +9 -1
index 0be12dc..588f115 100644
@@ -60,13 +60,21 @@ event_def PE_MODIFIER_EVENT
 |
 event_def
 
-event_def: event_legacy_symbol |
+event_def: event_pmu |
+	   event_legacy_symbol |
 	   event_legacy_cache sep_dc |
 	   event_legacy_mem |
 	   event_legacy_tracepoint sep_dc |
 	   event_legacy_numeric sep_dc |
 	   event_legacy_raw sep_dc
 
+event_pmu:
+PE_NAME '/' event_config '/'
+{
+	ABORT_ON(parse_events_add_pmu(list, idx, $1, $3));
+	parse_events__free_terms($3);
+}
+
 event_legacy_symbol:
 PE_VALUE_SYM '/' event_config '/'
 {
Signature · 1 line
1.7.4.4
author
#65 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

In reply to Jiri Olsa

hi,
any feedback? ;)
I saw 1/9 was already taken, thanks
I can send rebased patchset if needed..

thanks,
jirka

Quoted 66 lines · Jiri Olsa

hi,
Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format sysfs group attribute
for pmu device
- adding new syntax to specify raw events based on the sysfs pmu's format attribute
eg. "cpu/config=1,config1=2,config2=3/u"

There are helping patches 1-4, which I did not want to mangle with the actual change. Patches 5-9 implement the feature itself.

v4 changes:
- 5/9 changed sysfs pmu format definitions to the group attribute, each line (in previous patch) is now represented by single sysfs attribute under format group
- 6/9 fix raw events so the number is always considered to be hex number
- 8/9 move config[12] definitions to be processed by the parser

Attached patches:
1/9 perf, tool: Make perf_evlist__splice_list_tail global 2/9 perf, tool: Remove unused functions from debugfs object 3/9 perf, tool: Add sysfs mountpoint interface
4/9 perf, tool: Add bitmap_or function into bitmap object 5/9 perf: Adding sysfs group format attribute for pmu device 6/9 perf, tool: Add parser generator for events parsing 7/9 perf, tool: Add config options support for event parsing 8/9 perf, tool: Add perf pmu object to access pmu format definition 9/9 perf, tool: Add support to specify pmu style event

thanks,
jirka

---
 .../testing/sysfs-bus-event_source-devices-format  |   14 +
 include/linux/perf_event.h                         |   22 +
 kernel/events/core.c                               |   22 +
 tools/perf/Makefile                                |   31 +
 tools/perf/builtin-test.c                          |   52 +-
 tools/perf/util/bitmap.c                           |   10 +
 tools/perf/util/debugfs.c                          |  141 --
 tools/perf/util/debugfs.h                          |    6 -
 tools/perf/util/evlist.c                           |    6 +-
 tools/perf/util/evlist.h                           |    5 +
 tools/perf/util/include/linux/bitmap.h             |   11 +
 tools/perf/util/parse-events-bison.c               | 1813 ++++++++++++++++
 tools/perf/util/parse-events-bison.h               |   81 +
 tools/perf/util/parse-events-flex.c                | 2225 ++++++++++++++++++++
 tools/perf/util/parse-events-flex.h                |  316 +++
 tools/perf/util/parse-events.c                     |  552 ++---
 tools/perf/util/parse-events.h                     |   37 +
 tools/perf/util/parse-events.l                     |  107 +
 tools/perf/util/parse-events.y                     |  191 ++
 tools/perf/util/pmu-bison.c                        | 1663 +++++++++++++++
 tools/perf/util/pmu-bison.h                        |   73 +
 tools/perf/util/pmu-flex.c                         | 1821 ++++++++++++++++
 tools/perf/util/pmu-flex.h                         |  316 +++
 tools/perf/util/pmu.c                              |  462 ++++
 tools/perf/util/pmu.h                              |   41 +
 tools/perf/util/pmu.l                              |   43 +
 tools/perf/util/pmu.y                              |   93 +
 tools/perf/util/sysfs.c                            |   60 +
 tools/perf/util/sysfs.h                            |    6 +
 29 files changed, 9740 insertions(+), 480 deletions(-)
#66 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

In reply to Jiri Olsa
Quoted 14 lines · Jiri Olsa

hi,
Here's new version of event parsing patchset. To summarize:
- adding event parser bison/flex generator
- the event syntax stays as it was
- adding event format sysfs group attribute
for pmu device
- adding new syntax to specify raw events based on the sysfs pmu's format attribute
eg. "cpu/config=1,config1=2,config2=3/u"

There are helping patches 1-4, which I did not want to mangle with the actual change. Patches 5-9 implement the feature itself.

Quoted 6 lines

v4 changes:
- 5/9 changed sysfs pmu format definitions to the group attribute, each line (in previous patch) is now represented by single sysfs attribute under format group
- 6/9 fix raw events so the number is always considered to be hex number
- 8/9 move config[12] definitions to be processed by the parser

I added the below but all I managed was to crash my kernel, its probably a simple thing, but sysfs didn't give a hint.

---
Subject: perf, x86: Add simple format descriptions
From: Peter Zijlstra <[email protected]>
Date: Tue Feb 14 16:37:27 CET 2012

---
 arch/x86/kernel/cpu/perf_event.c       |    7 ++++++
 arch/x86/kernel/cpu/perf_event.h       |    1 
 arch/x86/kernel/cpu/perf_event_amd.c   |   18 +++++++++++++++++
 arch/x86/kernel/cpu/perf_event_intel.c |   34 +++++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/perf_event_p6.c    |   18 +++++++++++++++++
 include/linux/perf_event.h             |    6 -----
 kernel/events/core.c                   |   22 ---------------------
 7 files changed, 78 insertions(+), 28 deletions(-)
arch/x86/kernel/cpu/perf_event.c +7 -0
@@ -1250,6 +1250,11 @@ static void __init pmu_check_apic(void)
 	pr_info("no hardware sampling interrupt available.\n");
 }
 
+static struct attribute_group x86_pmu_format_group = {
+	.name = "format",
+	.attrs = NULL,
+};
+
 static int __init init_hw_perf_events(void)
 {
 	struct x86_pmu_quirk *quirk;
@@ -1324,6 +1329,7 @@ static int __init init_hw_perf_events(vo
 	}
 
 	x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
+	x86_pmu_format_group.attrs = x86_pmu.format_attrs;
 
 	pr_info("... version:                %d\n",     x86_pmu.version);
 	pr_info("... bit width:              %d\n",     x86_pmu.cntval_bits);
@@ -1604,6 +1610,7 @@ static struct attribute_group x86_pmu_at
 
 static const struct attribute_group *x86_pmu_attr_groups[] = {
 	&x86_pmu_attr_group,
+	&x86_pmu_format_group,
 	NULL,
 };
 
arch/x86/kernel/cpu/perf_event.h +1 -0
@@ -311,6 +311,7 @@ struct x86_pmu {
 	 * sysfs attrs
 	 */
 	int		attr_rdpmc;
+	struct attribute **format_attrs;
 
 	/*
 	 * CPU Hotplug hooks
arch/x86/kernel/cpu/perf_event_amd.c +18 -0
@@ -398,6 +398,20 @@ static void amd_pmu_cpu_dead(int cpu)
 	}
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7,32-35");
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *amd_format_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+};
+
 static __initconst const struct x86_pmu amd_pmu = {
 	.name			= "AMD",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -420,6 +434,8 @@ static __initconst const struct x86_pmu 
 	.get_event_constraints	= amd_get_event_constraints,
 	.put_event_constraints	= amd_put_event_constraints,
 
+	.format_attrs		= amd_format_attr,
+
 	.cpu_prepare		= amd_pmu_cpu_prepare,
 	.cpu_starting		= amd_pmu_cpu_starting,
 	.cpu_dead		= amd_pmu_cpu_dead,
@@ -590,6 +606,8 @@ static __initconst const struct x86_pmu 
 	.cpu_starting		= amd_pmu_cpu_starting,
 	.cpu_dead		= amd_pmu_cpu_dead,
 #endif
+
+	.format_attrs		= amd_format_attr,
 };
 
 __init int amd_pmu_init(void)
arch/x86/kernel/cpu/perf_event_intel.c +34 -0
@@ -1382,6 +1382,23 @@ static void core_pmu_enable_all(int adde
 	}
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7"	);
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(pc,	"config:19"	);
+PMU_FORMAT_ATTR(any,	"config:21"	); /* v3 + */
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *intel_arch_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+};
+
 static __initconst const struct x86_pmu core_pmu = {
 	.name			= "core",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -1406,6 +1423,7 @@ static __initconst const struct x86_pmu 
 	.put_event_constraints	= intel_put_event_constraints,
 	.event_constraints	= intel_core_event_constraints,
 	.guest_get_msrs		= core_guest_get_msrs,
+	.format_attrs		= intel_arch_formats_attr,
 };
 
 struct intel_shared_regs *allocate_shared_regs(int cpu)
@@ -1486,6 +1504,20 @@ static void intel_pmu_cpu_dying(int cpu)
 	fini_debug_store_on_cpu(cpu);
 }
 
+PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63");
+
+static struct attribute *intel_arch3_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_any.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+
+	&format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */
+};
+
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -1509,6 +1541,8 @@ static __initconst const struct x86_pmu 
 	.get_event_constraints	= intel_get_event_constraints,
 	.put_event_constraints	= intel_put_event_constraints,
 
+	.format_attrs		= intel_arch3_formats_attr,
+
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
arch/x86/kernel/cpu/perf_event_p6.c +18 -0
@@ -87,6 +87,22 @@ static void p6_pmu_enable_event(struct p
 	(void)checking_wrmsrl(hwc->config_base, val);
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7"	);
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(pc,	"config:19"	);
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *intel_p6_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+};
+
 static __initconst const struct x86_pmu p6_pmu = {
 	.name			= "p6",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -115,6 +131,8 @@ static __initconst const struct x86_pmu 
 	.cntval_mask		= (1ULL << 32) - 1,
 	.get_event_constraints	= x86_get_event_constraints,
 	.event_constraints	= p6_event_constraints,
+
+	.format_attrs		= intel_p6_formats_attr,
 };
 
 __init int p6_pmu_init(void)
include/linux/perf_event.h +0 -6
@@ -628,12 +628,6 @@ struct pmu {
 	int				task_ctx_nr;
 
 	/*
-	 * True if the pmu defines its own set of format attributes within
-	 * attr_groups. If false, default format attributes are used.
-	 */
-	bool				format_defined;
-
-	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
 	 * as well as for lazy/batch writing of the MSRs.
 	 */
kernel/events/core.c +0 -22
@@ -5540,22 +5540,6 @@ static struct bus_type pmu_bus = {
 	.dev_attrs	= pmu_dev_attrs,
 };
 
-/* Default format attributes. */
-PMU_FORMAT_ATTR(config,  "config:0-63");
-PMU_FORMAT_ATTR(config1, "config1:0-63");
-PMU_FORMAT_ATTR(config2, "config2:0-63");
-
-static struct attribute *format_attrs[] = {
-	&format_attr_config.attr,
-	&format_attr_config1.attr,
-	&format_attr_config2.attr,
-};
-
-static struct attribute_group format_attr_group = {
-	.name   = "format",
-	.attrs  = format_attrs,
-};
-
 static void pmu_dev_release(struct device *dev)
 {
 	kfree(dev);
@@ -5582,12 +5566,6 @@ static int pmu_dev_alloc(struct pmu *pmu
 	if (ret)
 		goto free_dev;
 
-	if (!pmu->format_defined) {
-		ret = sysfs_create_group(&pmu->dev->kobj, &format_attr_group);
-		if (ret)
-			goto free_dev;
-	}
-
 out:
 	return ret;
 
maintainer
#67 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 3 lines · Peter Zijlstra

I added the below but all I managed was to crash my kernel, its probably a simple thing, but sysfs didn't give a hint.

This isn't it either..

crash looks like:

general protection fault: 0000 [#1] PREEMPT SMP 
CPU 0 
Modules linked in:

Pid: 1, comm: swapper/0 Not tainted 3.3.0-rc3-01426-g2ce21a5-dirty #78 Supermicro X8DTN/X8DTN

RIP: 0010:[<ffffffff812e258e>]  [<ffffffff812e258e>] strcmp+0x4/0x21
RSP: 0018:ffff880236879c90  EFLAGS: 00010286
RAX: ffff880235ac7660 RBX: 0000000000000000 RCX: ffff880236870000
RDX: 0000000000000000 RSI: ffffffff81b295a6 RDI: 6e7500746e657665
RBP: ffff880236879c90 R08: 0000000000000180 R09: 6e7500746e657665
R10: ffffffff812ddedd R11: ffff880236879dc0 R12: 0000000000000000
R13: ffff880235ac7630 R14: 6e7500746e657665 R15: 0000000000000008
FS:  0000000000000000(0000) GS:ffff880237c00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 0000000000000000 CR3: 0000000001c05000 CR4: 00000000000007f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process swapper/0 (pid: 1, threadinfo ffff880236878000, task ffff880236870000)
Stack:
 ffff880236879cc0 ffffffff811996e2 ffff880235ac7ab0 ffff880236879d30
 ffff880236879d30 ffff880235ac7ab0 ffff880236879ce0 ffffffff81199957
 ffff880236879d30 ffff880235ac75a0 ffff880236879d10 ffffffff81199a06
Call Trace:
 [<ffffffff811996e2>] sysfs_find_dirent+0x79/0xda
 [<ffffffff81199957>] __sysfs_add_one+0x73/0xc3
 [<ffffffff81199a06>] sysfs_add_one+0x1b/0xab
 [<ffffffff81198fa8>] sysfs_add_file_mode+0x7e/0xb7
 [<ffffffff8119b841>] internal_create_group+0xed/0x168
 [<ffffffff8119b8e7>] sysfs_create_group+0x13/0x18
 [<ffffffff814861fc>] device_add_groups+0x2a/0x69
 [<ffffffff81198ff3>] ? sysfs_add_file+0x12/0x14
 [<ffffffff81486f8f>] device_add+0x37f/0x636
 [<ffffffff8148672b>] ? kzalloc.clone.0+0xe/0x10
 [<ffffffff810f069a>] pmu_dev_alloc+0x88/0xa4
 [<ffffffff81d11114>] ? init_kprobe_trace+0x90/0x90
 [<ffffffff81d1115f>] perf_event_sysfs_init+0x4b/0x9a
 [<ffffffff81d11114>] ? init_kprobe_trace+0x90/0x90
 [<ffffffff8100020f>] do_one_initcall+0x7f/0x139
 [<ffffffff81cf65ba>] kernel_init+0xa2/0x122
 [<ffffffff8109083e>] ? schedule_tail+0x31/0x74
 [<ffffffff817af2a4>] kernel_thread_helper+0x4/0x10
 [<ffffffff81cf6518>] ? parse_early_options+0x20/0x20
 [<ffffffff817af2a0>] ? gs_change+0x13/0x13
Code: 48 ff c1 80 39 00 75 f8 eb 0d 48 ff c1 48 ff ca 75 05 c6 01 00 eb

0e 40 8a 3e 48 ff c6 40 88 39 40 84 ff 75 e5 c9 c3 55 48 89 e5 <8a> 07 8a 16 48 ff c7 48 ff c6 38 d0 74 07 19 c0 83 c8 01 eb 06 RIP [<ffffffff812e258e>] strcmp+0x4/0x21
RSP <ffff880236879c90>

---[ end trace 5283cffd22793f50 ]---

And yes, I already send greg a patch for that sillyness in sysfs_find_dirent.

---

arch/x86/kernel/cpu/perf_event.c +1 -0
@@ -1605,6 +1605,7 @@ static struct attribute *x86_pmu_attrs[]
 };
 
 static struct attribute_group x86_pmu_attr_group = {
+	.name = "attributes",
 	.attrs = x86_pmu_attrs,
 };
 
maintainer
#68 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 2 lines · Peter Zijlstra
Quoted 2 lines

I added the below but all I managed was to crash my kernel, its probably a simple thing, but sysfs didn't give a hint.

OK, this one works. the attributes thing wants NULL termination. Thanks for mentioning that Jiri.

---
Subject: perf, x86: Add simple format descriptions
From: Peter Zijlstra <[email protected]>
Date: Tue Feb 14 16:37:27 CET 2012

---
 arch/x86/kernel/cpu/perf_event.c       |    7 ++++++
 arch/x86/kernel/cpu/perf_event.h       |    1 
 arch/x86/kernel/cpu/perf_event_amd.c   |   19 +++++++++++++++++
 arch/x86/kernel/cpu/perf_event_intel.c |   36 +++++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/perf_event_p6.c    |   19 +++++++++++++++++
 include/linux/perf_event.h             |    6 -----
 kernel/events/core.c                   |   22 --------------------
 7 files changed, 82 insertions(+), 28 deletions(-)
arch/x86/kernel/cpu/perf_event.c +7 -0
@@ -1250,6 +1250,11 @@ static void __init pmu_check_apic(void)
 	pr_info("no hardware sampling interrupt available.\n");
 }
 
+static struct attribute_group x86_pmu_format_group = {
+	.name = "format",
+	.attrs = NULL,
+};
+
 static int __init init_hw_perf_events(void)
 {
 	struct x86_pmu_quirk *quirk;
@@ -1324,6 +1329,7 @@ static int __init init_hw_perf_events(vo
 	}
 
 	x86_pmu.attr_rdpmc = 1; /* enable userspace RDPMC usage by default */
+	x86_pmu_format_group.attrs = x86_pmu.format_attrs;
 
 	pr_info("... version:                %d\n",     x86_pmu.version);
 	pr_info("... bit width:              %d\n",     x86_pmu.cntval_bits);
@@ -1604,6 +1610,7 @@ static struct attribute_group x86_pmu_at
 
 static const struct attribute_group *x86_pmu_attr_groups[] = {
 	&x86_pmu_attr_group,
+	&x86_pmu_format_group,
 	NULL,
 };
 
arch/x86/kernel/cpu/perf_event.h +1 -0
@@ -311,6 +311,7 @@ struct x86_pmu {
 	 * sysfs attrs
 	 */
 	int		attr_rdpmc;
+	struct attribute **format_attrs;
 
 	/*
 	 * CPU Hotplug hooks
arch/x86/kernel/cpu/perf_event_amd.c +19 -0
@@ -398,6 +398,21 @@ static void amd_pmu_cpu_dead(int cpu)
 	}
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7,32-35");
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *amd_format_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+	NULL,
+};
+
 static __initconst const struct x86_pmu amd_pmu = {
 	.name			= "AMD",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -420,6 +435,8 @@ static __initconst const struct x86_pmu 
 	.get_event_constraints	= amd_get_event_constraints,
 	.put_event_constraints	= amd_put_event_constraints,
 
+	.format_attrs		= amd_format_attr,
+
 	.cpu_prepare		= amd_pmu_cpu_prepare,
 	.cpu_starting		= amd_pmu_cpu_starting,
 	.cpu_dead		= amd_pmu_cpu_dead,
@@ -590,6 +607,8 @@ static __initconst const struct x86_pmu 
 	.cpu_starting		= amd_pmu_cpu_starting,
 	.cpu_dead		= amd_pmu_cpu_dead,
 #endif
+
+	.format_attrs		= amd_format_attr,
 };
 
 __init int amd_pmu_init(void)
arch/x86/kernel/cpu/perf_event_intel.c +36 -0
@@ -1382,6 +1382,24 @@ static void core_pmu_enable_all(int adde
 	}
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7"	);
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(pc,	"config:19"	);
+PMU_FORMAT_ATTR(any,	"config:21"	); /* v3 + */
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *intel_arch_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+	NULL,
+};
+
 static __initconst const struct x86_pmu core_pmu = {
 	.name			= "core",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -1406,6 +1424,7 @@ static __initconst const struct x86_pmu 
 	.put_event_constraints	= intel_put_event_constraints,
 	.event_constraints	= intel_core_event_constraints,
 	.guest_get_msrs		= core_guest_get_msrs,
+	.format_attrs		= intel_arch_formats_attr,
 };
 
 struct intel_shared_regs *allocate_shared_regs(int cpu)
@@ -1486,6 +1505,21 @@ static void intel_pmu_cpu_dying(int cpu)
 	fini_debug_store_on_cpu(cpu);
 }
 
+PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63");
+
+static struct attribute *intel_arch3_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_any.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+
+	&format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */
+	NULL,
+};
+
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -1509,6 +1543,8 @@ static __initconst const struct x86_pmu 
 	.get_event_constraints	= intel_get_event_constraints,
 	.put_event_constraints	= intel_put_event_constraints,
 
+	.format_attrs		= intel_arch3_formats_attr,
+
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
arch/x86/kernel/cpu/perf_event_p6.c +19 -0
@@ -87,6 +87,23 @@ static void p6_pmu_enable_event(struct p
 	(void)checking_wrmsrl(hwc->config_base, val);
 }
 
+PMU_FORMAT_ATTR(event,	"config:0-7"	);
+PMU_FORMAT_ATTR(umask,	"config:8-15"	);
+PMU_FORMAT_ATTR(edge,	"config:18"	);
+PMU_FORMAT_ATTR(pc,	"config:19"	);
+PMU_FORMAT_ATTR(inv,	"config:23"	);
+PMU_FORMAT_ATTR(cmask,	"config:24-31"	);
+
+static struct attribute *intel_p6_formats_attr[] = {
+	&format_attr_event.attr,
+	&format_attr_umask.attr,
+	&format_attr_edge.attr,
+	&format_attr_pc.attr,
+	&format_attr_inv.attr,
+	&format_attr_cmask.attr,
+	NULL,
+};
+
 static __initconst const struct x86_pmu p6_pmu = {
 	.name			= "p6",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -115,6 +132,8 @@ static __initconst const struct x86_pmu 
 	.cntval_mask		= (1ULL << 32) - 1,
 	.get_event_constraints	= x86_get_event_constraints,
 	.event_constraints	= p6_event_constraints,
+
+	.format_attrs		= intel_p6_formats_attr,
 };
 
 __init int p6_pmu_init(void)
include/linux/perf_event.h +0 -6
@@ -628,12 +628,6 @@ struct pmu {
 	int				task_ctx_nr;
 
 	/*
-	 * True if the pmu defines its own set of format attributes within
-	 * attr_groups. If false, default format attributes are used.
-	 */
-	bool				format_defined;
-
-	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
 	 * as well as for lazy/batch writing of the MSRs.
 	 */
kernel/events/core.c +0 -22
@@ -5540,22 +5540,6 @@ static struct bus_type pmu_bus = {
 	.dev_attrs	= pmu_dev_attrs,
 };
 
-/* Default format attributes. */
-PMU_FORMAT_ATTR(config,  "config:0-63");
-PMU_FORMAT_ATTR(config1, "config1:0-63");
-PMU_FORMAT_ATTR(config2, "config2:0-63");
-
-static struct attribute *format_attrs[] = {
-	&format_attr_config.attr,
-	&format_attr_config1.attr,
-	&format_attr_config2.attr,
-};
-
-static struct attribute_group format_attr_group = {
-	.name   = "format",
-	.attrs  = format_attrs,
-};
-
 static void pmu_dev_release(struct device *dev)
 {
 	kfree(dev);
@@ -5582,12 +5566,6 @@ static int pmu_dev_alloc(struct pmu *pmu
 	if (ret)
 		goto free_dev;
 
-	if (!pmu->format_defined) {
-		ret = sysfs_create_group(&pmu->dev->kobj, &format_attr_group);
-		if (ret)
-			goto free_dev;
-	}
-
 out:
 	return ret;
 
maintainer
#69 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 3 lines · Peter Zijlstra

OK, this one works. the attributes thing wants NULL termination. Thanks
for mentioning that Jiri.

OK, it mostly works, except:

perf record -e "cpu/config=0x108000c0/upp" ./loop_1b_locks

doesn't seem to work...

One thing that might be nice is not having to do =1 for single bit fields, so that we can write: inv,edge instead of inv=1,edge=1.

maintainer
#70 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

OK, this one works. the attributes thing wants NULL termination. Thanks
for mentioning that Jiri.

OK, it mostly works, except:

perf record -e "cpu/config=0x108000c0/upp" ./loop_1b_locks

doesn't seem to work...

This seems to come back to hardcoding config* vs including it in every single format description.

I prefer to have all perf_event_attr fields (of interest) hard-coded in the parser so that we can omit them for all actual format descriptions.

These would be: period, config, config1, config2 and stephane's new branch_sample_type, although that might want to get a shorter name.

author
#71 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 12 lines · Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

OK, this one works. the attributes thing wants NULL termination. Thanks
for mentioning that Jiri.

OK, it mostly works, except:

perf record -e "cpu/config=0x108000c0/upp" ./loop_1b_locks

doesn't seem to work...

Quoted 8 lines

This seems to come back to hardcoding config* vs including it in every single format description.

I prefer to have all perf_event_attr fields (of interest) hard-coded in the parser so that we can omit them for all actual format descriptions.

These would be: period, config, config1, config2 and stephane's new branch_sample_type, although that might want to get a shorter name.

right, for pmu/.../ syntax there are allowed only fields from 'format' directory are so far.. with exceptions like: cycles/period=100000/

so I'll hardcode following config fields:
config
config1
config2
period
branch_sample_type (branch, branch_type, branch_st ???)

to be used in xxx/.../ syntax

also we need to choose some strategy of format field name shadowing with hardcoded fields:

- BUILD_BUG in kernel PMU_FORMAT_ATTR
- not allowed.. report error in perf runtime
- allowed - hardcoded field have precedence
- allowed - format field values have precedence

I'd say either allow shadowing(with whatever precedence we this is better), or have the BUILD_BUG line in kernel..

jirka

maintainer
#72 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 8 lines · Jiri Olsa
Quoted 2 lines · Peter Zijlstra

These would be: period, config, config1, config2 and stephane's new branch_sample_type, although that might want to get a shorter name.

right, for pmu/.../ syntax there are allowed only fields from 'format' directory are so far.. with exceptions like: cycles/period=100000/

Quoted 6 lines

so I'll hardcode following config fields:
config
config1
config2
period
branch_sample_type (branch, branch_type, branch_st ???)

Uhmm,.. Stephane any particular preference on this?

Quoted 5 lines

to be used in xxx/.../ syntax

also we need to choose some strategy of format field name shadowing with hardcoded fields:

Quoted 7 lines

- BUILD_BUG in kernel PMU_FORMAT_ATTR
- not allowed.. report error in perf runtime
- allowed - hardcoded field have precedence
- allowed - format field values have precedence

I'd say either allow shadowing(with whatever precedence we this is better), or have the BUILD_BUG line in kernel..

I agree, if we can get the BUILD_BUG thing working that might be the best option, otherwise we can do the precedence thing. We could even add a syntax to resolve the namespace conflict in the latter case (eg. use '$' PE_NAME to mean the hardcoded in case of conflict).

author
#73 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 28 lines · Peter Zijlstra
Quoted 8 lines · Jiri Olsa
Quoted 2 lines · Peter Zijlstra

These would be: period, config, config1, config2 and stephane's new branch_sample_type, although that might want to get a shorter name.

right, for pmu/.../ syntax there are allowed only fields from 'format' directory are so far.. with exceptions like: cycles/period=100000/

Quoted 6 lines

so I'll hardcode following config fields:
config
config1
config2
period
branch_sample_type (branch, branch_type, branch_st ???)

Uhmm,.. Stephane any particular preference on this?

Quoted 10 lines

to be used in xxx/.../ syntax

also we need to choose some strategy of format field name shadowing with hardcoded fields:

- BUILD_BUG in kernel PMU_FORMAT_ATTR
- not allowed.. report error in perf runtime
- allowed - hardcoded field have precedence
- allowed - format field values have precedence

Quoted 7 lines
Quoted 2 lines

I'd say either allow shadowing(with whatever precedence we this is better), or have the BUILD_BUG line in kernel..

I agree, if we can get the BUILD_BUG thing working that might be the best option, otherwise we can do the precedence thing. We could even add a syntax to resolve the namespace conflict in the latter case (eg. use '$' PE_NAME to mean the hardcoded in case of conflict).

err.. I could not get the BUILD_BUG working... looks like string comparison is something you are not supposed to do in cpp.. ;)

currently, I have the hardcoded fields to have a precedence, and I'd workaround/fix it if there's need.. later I mean..

also, any idea when's the branch_sample_type going in?

thanks,
jirka

maintainer
#74 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 1 line · Jiri Olsa

also, any idea when's the branch_sample_type going in?

any day now, I've queued it and will see if it compiles runs in a bit after which I'll try and throw it over the wall to mingo.

author
#75 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

OK, this one works. the attributes thing wants NULL termination. Thanks
for mentioning that Jiri.

Quoted 8 lines

OK, it mostly works, except:

perf record -e "cpu/config=0x108000c0/upp" ./loop_1b_locks

doesn't seem to work...

One thing that might be nice is not having to do =1 for single bit fields, so that we can write: inv,edge instead of inv=1,edge=1.

ok, would you think there's any use for following behaviour:
whenever field is written without the assignment, all the field defined bits are set.. regardless if it's sengle ot multiple bit field..

looks like this would ease the implementation a little, not mentioning the above behaviour could be usefull ;)

jirka

maintainer
#76 lore raw

Re: [PATCHv4 0/9] perf tool: parser generator for events parsing

Quoted 15 lines · Jiri Olsa
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

OK, this one works. the attributes thing wants NULL termination. Thanks
for mentioning that Jiri.

Quoted 8 lines

OK, it mostly works, except:

perf record -e "cpu/config=0x108000c0/upp" ./loop_1b_locks

doesn't seem to work...

One thing that might be nice is not having to do =1 for single bit fields, so that we can write: inv,edge instead of inv=1,edge=1.

Quoted 6 lines

ok, would you think there's any use for following behaviour:
whenever field is written without the assignment, all the field defined bits are set.. regardless if it's sengle ot multiple bit field..

looks like this would ease the implementation a little, not mentioning the above behaviour could be usefull ;)

I'm not sure that behaviour would be useful for anything other than this, but sure -- or set the value to 1 when not set, either works.

#77 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

In reply to Peter Zijlstra
Quoted 4 lines · Peter Zijlstra

This would allow us to write things like:

perf record -e cpu/event=0x34,umask=0x01,inv,cmask=2

I know this is beating a dead horse, but are you guys *really* that against just linking against libpfm4?

Instead of (to use your example):

    perf record -e cpu/event=0x34,umask=0x01,inv,cmask=2

Insn't
perf record -e nhm::UNC_CBO_CACHE_LOOKUP:M:i=1:cmask=2
much nicer?

And the code that translates that to bits for you already exists in a nice library form. And it supports Pentium 4 already.

In PAPI we're finally moving to all string-based event names simply because trying to create cross-platform ways of specifying bits like you are just didn't work very well.

Vince

author
#78 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

In reply to Peter Zijlstra
Quoted 1 line · Peter Zijlstra

On Thu, 2011-12-15 at 16:30 +0100, Jiri Olsa wrote:

SNIP

Quoted 6 lines
Quoted 3 lines
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty

This isn't complete, we need means of specifying perf_event_attr::config[12] when specifying a raw event.

ok

Quoted 2 lines

SNIP

Quoted 6 lines
Quoted 3 lines

cpu-migrations|migrations |
alignment-faults |
emulation-faults

It might make sense to allow means of custom symbol -> raw mappings.

right, will save some code..

Quoted 15 lines
Quoted 15 lines
PE_NAME_CACHE_TYPE:     L1-dcache|l1-d|l1d|L1-data             |
                        L1-icache|l1-i|l1i|L1-instruction      |
                        LLC|L2                                 |
                        dTLB|d-tlb|Data-TLB                    |
                        iTLB|i-tlb|Instruction-TLB             |
                        branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT: load|loads|read                       |
                        store|stores|write                     |
                        prefetch|prefetches                    |
                        speculative-read|speculative-load      |
                        refs|Reference|ops|access              |

misses|miss

Quoted 7 lines
Quoted 3 lines
PE_SEP_RAW:             'r'
PE_SEP_BP:              'mem'
PE_MODIFIER_EVENT:      :[ukhp]{1,2}

You can actually have more than 2 modifiers, eg. "upp".

[u] | [k] | [h] | [p]{,3} would be more correct I think.

yay, the boundaries are indeed [0,3], I thought it was bool..

* precise_ip:
*
* 0 - SAMPLE_IP can have arbitrary
* skid
* 1 - SAMPLE_IP must have constant
* skid
* 2 - SAMPLE_IP requested to have 0
* skid
* 3 - SAMPLE_IP must have 0 skid
*

Quoted 11 lines
Quoted 7 lines
PE_MODIFIER_BPTYPE:     :[rwx]{1,3}
PE_NAME_TP:             [a-zA-Z_*?]+
PE_VALUE:               number

Added flex/bison files for event grammar parsing. Added flex/bison Makefile rules plus few special dependencies.

It might be good to include the .c output of flex/bison so that we can build perf without a hard dependency on them -- only people changing the parser will need them.

ok

thanks,
jirka

author
#79 lore raw

v2 cover perf tool: parser generator for events parsing

In reply to Peter Zijlstra

hi,
adding an event parser generator to handle the '-e' option data. I strip this version of the event grouping enhancement, so it's more straightforward. I'll send those patches later.

Attached patches:
- 1/2 perf, tool: Add parser generator for events parsing
- 2/2 perf, tool: Add more automated tests for event parsing

v2 changes:
1/2 perf, tool: Add parser generator for events parsing
- added a way to specify config[12] for raw events
- added direct symbol -> raw mapping in parser itself
- fixed modifier syntax to allow all correct precise values
- added generated parser as part of the patch, however.. flex and bison dont care about the linux kernel coding standard, checkpatch.pl complains quite a lot:

total: 728 errors, 1316 warnings, 5379 lines checked

after I tried cleanpatch scripts I've got:

total: 664 errors, 1287 warnings, 5382 lines checked

so I'm not sure it's worth to do that (the cleanup), considering it needs to be regenerated each time we change the parser grammar.
- added 'event-parser' Makefile target to generate the parser out of the flex/bison sources

thanks,
jirka

---
 tools/perf/Makefile                  |   18 +
 tools/perf/builtin-test.c            |  276 +++++-
 tools/perf/util/parse-events-bison.c | 1743 ++++++++++++++++++++++++++
 tools/perf/util/parse-events-bison.h |   78 ++
 tools/perf/util/parse-events-flex.c  | 2256 ++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events-flex.h  |  317 +++++
 tools/perf/util/parse-events.c       |  475 +++-----
 tools/perf/util/parse-events.h       |   10 +
 tools/perf/util/parse-events.l       |  114 ++
 tools/perf/util/parse-events.y       |  131 ++
 10 files changed, 5094 insertions(+), 324 deletions(-)
author
#80 lore raw

PATCH v2 1/2 perf, tool: Add parser generator for events parsing

Changing event parsing to use flex/bison parse generator. The event syntax stays as it was. Added a way to specify config[12] for raw events.

grammar description:

events: events ',' event | event

event: event_tracepoint |
event_raw |
event_numeric |
event_symbolic |
event_generic_hw |
event_breakpoint

event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier |
                        PE_SEP_RAW PE_VALUE '-' PE_VALUE modifier
                        PE_SEP_RAW PE_VALUE '-' PE_VALUE '-' PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
PE_NAME_SYM:            cpu-cycles|cycles                              |
                        stalled-cycles-frontend|idle-cycles-frontend   |
                        stalled-cycles-backend|idle-cycles-backend     |
                        instructions                                   |
                        cache-references                               |
                        cache-misses                                   |
                        branch-instructions|branches                   |
                        branch-misses                                  |
                        bus-cycles                                     |
                        cpu-clock                                      |
                        task-clock                                     |
                        page-faults|faults                             |
                        minor-faults                                   |
                        major-faults                                   |
                        context-switches|cs                            |
                        cpu-migrations|migrations                      |
                        alignment-faults                               |

emulation-faults

PE_NAME_CACHE_TYPE:     L1-dcache|l1-d|l1d|L1-data             |
                        L1-icache|l1-i|l1i|L1-instruction      |
                        LLC|L2                                 |
                        dTLB|d-tlb|Data-TLB                    |
                        iTLB|i-tlb|Instruction-TLB             |
                        branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT: load|loads|read                       |
                        store|stores|write                     |
                        prefetch|prefetches                    |
                        speculative-read|speculative-load      |
                        refs|Reference|ops|access              |

misses|miss

PE_SEP_RAW:             'r'
PE_SEP_BP:              'mem'
PE_MODIFIER_EVENT:      :[ukhp]{1,4}
PE_MODIFIER_BPTYPE:     :[rwx]{1,3}
PE_NAME_TP:             [a-zA-Z_*?]+
PE_VALUE:               number

Added flex/bison files for event grammar parsing. The generated parser is part of the patch. Added makefile rule 'event-parser' to generate the parser code out of the bison/flex sources.

---
 tools/perf/Makefile                  |   18 +
 tools/perf/util/parse-events-bison.c | 1743 ++++++++++++++++++++++++++
 tools/perf/util/parse-events-bison.h |   78 ++
 tools/perf/util/parse-events-flex.c  | 2256 ++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events-flex.h  |  317 +++++
 tools/perf/util/parse-events.c       |  475 +++-----
 tools/perf/util/parse-events.h       |   10 +
 tools/perf/util/parse-events.l       |  114 ++
 tools/perf/util/parse-events.y       |  131 ++
 9 files changed, 4819 insertions(+), 323 deletions(-)
 create mode 100644 tools/perf/util/parse-events-bison.c
 create mode 100644 tools/perf/util/parse-events-bison.h
 create mode 100644 tools/perf/util/parse-events-flex.c
 create mode 100644 tools/perf/util/parse-events-flex.h
 create mode 100644 tools/perf/util/parse-events.l
 create mode 100644 tools/perf/util/parse-events.y
tools/perf/Makefile +18 -0
index ac86d67..a78a48c 100644
@@ -47,6 +47,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
+FLEX = $(CROSS_COMPILE)flex
+BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
@@ -341,6 +343,8 @@ LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
+LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -627,6 +631,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_FLEX     = @echo '   ' FLEX $@;
+	QUIET_BISON    = @echo '   ' BISON $@;
 endif
 endif
 
@@ -707,6 +713,9 @@ $(OUTPUT)perf.o perf.spec \
 	$(SCRIPTS) \
 	: $(OUTPUT)PERF-VERSION-FILE
 
+.SUFFIXES:
+.SUFFIXES: .o .c .S .s
+
 $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
@@ -739,6 +748,10 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+
+$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -775,6 +788,7 @@ help:
 	@echo '  html		- make html documentation'
 	@echo '  info		- make GNU info documentation (access with info <foo>)'
 	@echo '  pdf		- make pdf documentation'
+	@echo '  event-parser	- make event parser code'
 	@echo '  TAGS		- use etags to make tag information for source browsing'
 	@echo '  tags		- use ctags to make tag information for source browsing'
 	@echo '  cscope	- use cscope to make interactive browsing database'
@@ -825,6 +839,10 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+event-parser:
+	$(QUIET_BISON)$(BISON) -v util/parse-events.y -d -o util/parse-events-bison.c
+	$(QUIET_FLEX)$(FLEX) --header-file=util/parse-events-flex.h -t util/parse-events.l > util/parse-events-flex.c
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
tools/perf/util/parse-events-bison.c new file +1743 -0

1,743 lines not on this page · raw message

tools/perf/util/parse-events-bison.h new file +78 -0

78 lines not on this page · raw message

tools/perf/util/parse-events-flex.c new file +2256 -0

1,119 lines not on this page · raw message

tools/perf/util/parse-events-flex.h new file +317 -0

317 lines not on this page · raw message

tools/perf/util/parse-events.c +152 -323

475 lines not on this page · raw message

tools/perf/util/parse-events.h +10 -0
index 7e0cbe7..fcd6088 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/parse-events.l new file +114 -0

114 lines not on this page · raw message

tools/perf/util/parse-events.y new file +131 -0

131 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.4

Part of the diff is not shown here. View the raw message.

author
#81 lore raw

PATCH v2 2/2 perf, tool: Add more automated tests for event parsing

In reply to Jiri Olsa

Adding automated tests for event parsing to include testing for modifier and ',' operator.

---
 tools/perf/builtin-test.c |  276 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 275 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +275 -1
index 6173f78..c45e2ae 100644
@@ -603,7 +603,7 @@ out_free_threads:
 
 #define TEST_ASSERT_VAL(text, cond) \
 do { \
-	if (!cond) { \
+	if (!(cond)) { \
 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
 		return -1; \
 	} \
@@ -649,6 +649,34 @@ static int test__checkevent_raw(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
 	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
 	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config2);
+	return 0;
+}
+
+static int test__checkevent_raw_config1(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config2);
+	return 0;
+}
+
+static int test__checkevent_raw_config12(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config2);
 	return 0;
 }
 
@@ -759,6 +787,196 @@ static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_tracepoint(evlist);
+}
+
+static int
+test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		TEST_ASSERT_VAL("wrong exclude_user",
+				!evsel->attr.exclude_user);
+		TEST_ASSERT_VAL("wrong exclude_kernel",
+				evsel->attr.exclude_kernel);
+		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	}
+
+	return test__checkevent_tracepoint_multi(evlist);
+}
+
+static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_raw(evlist);
+}
+
+static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_numeric(evlist);
+}
+
+static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_alias(evlist);
+}
+
+static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
+
+	return test__checkevent_genhw(evlist);
+}
+
+static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint(evlist);
+}
+
+static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_x(evlist);
+}
+
+static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_r(evlist);
+}
+
+static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_w(evlist);
+}
+
+static int test__checkevent_list(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* r1 */
+	evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config1);
+	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config2);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	/* syscalls:sys_enter_open:k */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong sample_type",
+		(PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
+		evsel->attr.sample_type);
+	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	/* 1:1:hp */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return 0;
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -777,6 +995,14 @@ static struct test__event_st {
 		.check = test__checkevent_raw,
 	},
 	{
+		.name  = "r1-2",
+		.check = test__checkevent_raw_config1,
+	},
+	{
+		.name  = "r1-2-3",
+		.check = test__checkevent_raw_config12,
+	},
+	{
 		.name  = "1:1",
 		.check = test__checkevent_numeric,
 	},
@@ -808,6 +1034,54 @@ static struct test__event_st {
 		.name  = "mem:0:w",
 		.check = test__checkevent_breakpoint_w,
 	},
+	{
+		.name  = "syscalls:sys_enter_open:k",
+		.check = test__checkevent_tracepoint_modifier,
+	},
+	{
+		.name  = "syscalls:*:u",
+		.check = test__checkevent_tracepoint_multi_modifier,
+	},
+	{
+		.name  = "r1:kp",
+		.check = test__checkevent_raw_modifier,
+	},
+	{
+		.name  = "1:1:hp",
+		.check = test__checkevent_numeric_modifier,
+	},
+	{
+		.name  = "instructions:h",
+		.check = test__checkevent_symbolic_name_modifier,
+	},
+	{
+		.name  = "faults:u",
+		.check = test__checkevent_symbolic_alias_modifier,
+	},
+	{
+		.name  = "L1-dcache-load-miss:kpp",
+		.check = test__checkevent_genhw_modifier,
+	},
+	{
+		.name  = "mem:0:u",
+		.check = test__checkevent_breakpoint_modifier,
+	},
+	{
+		.name  = "mem:0:x:k",
+		.check = test__checkevent_breakpoint_x_modifier,
+	},
+	{
+		.name  = "mem:0:r:hp",
+		.check = test__checkevent_breakpoint_r_modifier,
+	},
+	{
+		.name  = "mem:0:w:up",
+		.check = test__checkevent_breakpoint_w_modifier,
+	},
+	{
+		.name  = "r1-2,syscalls:sys_enter_open:k,1:1:hp",
+		.check = test__checkevent_list,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
Signature · 1 line
1.7.4
#82 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

In reply to Jiri Olsa

Em Thu, Dec 15, 2011 at 04:30:37PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Changing event parsing to use flex/bison parse generator. The event syntax stays as it is.

Seems really cool, using the right tool for the task, comments:

. Can we avoid more globals? Like that __event_list one.
. All those ABORT_ON do what? die() like stuff? /me googles YYABORT...

----
YYABORT
Return immediately with value 1 (to report failure).
----

Ok, so it gets propagated back and hopefully the we die() just
back at main() in tools/perf/perf.c, right?

. make help | perf

Then running one of those targets and trying to build perf still
works? I guess so, but better check that.

Having it added to some new "make perf-test" that does that +
'perf test' too would get you brownie points. Leave it for later/someone else if you're busy/not looking for more work, of course 8-)

. We have some tests to parse events in 'perf test', right? From the top of my head it was even ya that did that, guess those are ok/improved (still need to look at the other patches in the backlog).

- Arnaldo

Quoted 1,071 lines

grammar description:

events: events ',' event | event

event: event_tracepoint |
event_raw |
event_numeric |
event_symbolic |
event_generic_hw |
event_breakpoint

event_tracepoint:       PE_NAME_TP ':' PE_NAME_TP modifier
event_raw:              PE_SEP_RAW PE_VALUE modifier
event_numeric:          PE_VALUE ':' PE_VALUE modifier
event_symbolic:         PE_NAME_SYM modifier
event_generic_hw:       PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier |
                        PE_NAME_CACHE_TYPE modifier
event_breakpoint:       PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
event_breakpoint_type:  PE_MODIFIER_BPTYPE | empty
modifier:               PE_MODIFIER_EVENT | empty
PE_NAME_SYM:            cpu-cycles|cycles                              |
                        stalled-cycles-frontend|idle-cycles-frontend   |
                        stalled-cycles-backend|idle-cycles-backend     |
                        instructions                                   |
                        cache-references                               |
                        cache-misses                                   |
                        branch-instructions|branches                   |
                        branch-misses                                  |
                        bus-cycles                                     |
                        cpu-clock                                      |
                        task-clock                                     |
                        page-faults|faults                             |
                        minor-faults                                   |
                        major-faults                                   |
                        context-switches|cs                            |
                        cpu-migrations|migrations                      |
                        alignment-faults                               |

emulation-faults

PE_NAME_CACHE_TYPE:     L1-dcache|l1-d|l1d|L1-data             |
                        L1-icache|l1-i|l1i|L1-instruction      |
                        LLC|L2                                 |
                        dTLB|d-tlb|Data-TLB                    |
                        iTLB|i-tlb|Instruction-TLB             |
                        branch|branches|bpu|btb|bpc            |

node

PE_NAME_CACHE_OP_RESULT: load|loads|read                       |
                        store|stores|write                     |
                        prefetch|prefetches                    |
                        speculative-read|speculative-load      |
                        refs|Reference|ops|access              |

misses|miss

PE_SEP_RAW:             'r'
PE_SEP_BP:              'mem'
PE_MODIFIER_EVENT:      :[ukhp]{1,2}
PE_MODIFIER_BPTYPE:     :[rwx]{1,3}
PE_NAME_TP:             [a-zA-Z_*?]+
PE_VALUE:               number

Added flex/bison files for event grammar parsing. Added flex/bison Makefile rules plus few special dependencies.

---
 tools/perf/Makefile                  |   21 ++
 tools/perf/util/parse-events-bison.y |  119 +++++++++
 tools/perf/util/parse-events-flex.l  |  111 ++++++++
 tools/perf/util/parse-events.c       |  459 +++++++++++-----------------------
 tools/perf/util/parse-events.h       |    9 +
 5 files changed, 411 insertions(+), 308 deletions(-)
 create mode 100644 tools/perf/util/parse-events-bison.y
 create mode 100644 tools/perf/util/parse-events-flex.l
tools/perf/Makefile +21 -0
index ac86d67..ef6b621 100644
@@ -47,6 +47,8 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
+FLEX = $(CROSS_COMPILE)flex
+BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
@@ -341,6 +343,8 @@ LIB_OBJS += $(OUTPUT)util/session.o
 LIB_OBJS += $(OUTPUT)util/thread.o
 LIB_OBJS += $(OUTPUT)util/thread_map.o
 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
+LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
@@ -627,6 +631,8 @@ ifndef V
 	QUIET_LINK     = @echo '   ' LINK $@;
 	QUIET_MKDIR    = @echo '   ' MKDIR $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
+	QUIET_FLEX     = @echo '   ' FLEX $@;
+	QUIET_BISON    = @echo '   ' BISON $@;
 endif
 endif
 
@@ -713,6 +719,10 @@ $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 $(OUTPUT)%.o: %.S
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+$(OUTPUT)%.c: %.l
+	$(QUIET_FLEX)$(FLEX) --header-file=$*.h -t $< > $@
+$(OUTPUT)%.c: %.y
+	$(QUIET_BISON)$(BISON) -v $< -d -o $@
 
 $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
@@ -739,6 +749,16 @@ $(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+
+.SECONDARY: util/parse-events-flex.c util/parse-events-flex.h
+.SECONDARY: util/parse-events-bison.c util/parse-events-bison.h
+
+util/parse-events.o: util/parse-events-flex.c
+util/parse-events-flex.c: util/parse-events-bison.c
+
+$(OUTPUT)util/parse-events-flex.o: util/parse-events-flex.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-unused-function $<
+
 $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
@@ -910,6 +930,7 @@ clean:
 	$(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS)
 	$(RM) $(ALL_PROGRAMS) perf
 	$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
+	$(RM) util/parse-events-flex.[ch] util/parse-events-bison.[cho]*
 	$(MAKE) -C Documentation/ clean
 	$(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS
 	$(python-clean)
tools/perf/util/parse-events-bison.y new file +119 -0
new file mode 100644
index 0000000..403cbf6
@@ -0,0 +1,119 @@
+
+%name-prefix "parse_events_"
+
+%{
+
+#define YYDEBUG 1
+
+#include <linux/compiler.h>
+#include "types.h"
+#include "util.h"
+#include "parse-events.h"
+
+extern int parse_events_lex (void);
+
+#define ABORT_ON(val) \
+do { \
+	if (val) \
+		YYABORT; \
+} while (0)
+
+%}
+
+%token PE_VALUE
+%token PE_MODIFIER_BPTYPE PE_MODIFIER_EVENT
+%token PE_NAME_TP PE_NAME_SYM
+%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
+%token PE_SEP_RAW PE_SEP_BP
+%token PE_ERROR
+%type <l> PE_VALUE
+%type <s> PE_NAME_TP
+%type <s> PE_NAME_SYM
+%type <s> PE_NAME_CACHE_TYPE
+%type <s> PE_NAME_CACHE_OP_RESULT
+%type <s> PE_MODIFIER_EVENT
+%type <s> modifier
+%type <s> PE_MODIFIER_BPTYPE
+%type <s> event_breakpoint_type
+
+%union
+{
+	char *s;
+	long l;
+}
+
+%%
+
+events: events ',' event | event
+
+event:  event_tracepoint |
+	event_raw |
+	event_numeric |
+	event_symbolic |
+	event_generic_hw |
+	event_breakpoint
+
+event_tracepoint: PE_NAME_TP ':' PE_NAME_TP modifier
+{
+	ABORT_ON(parse_events_add_tracepoint($1, $3, $4));
+}
+
+event_raw: PE_SEP_RAW PE_VALUE modifier
+{
+	ABORT_ON(parse_events_add_raw($2, $3));
+}
+
+event_numeric: PE_VALUE ':' PE_VALUE modifier
+{
+	ABORT_ON(parse_events_add_numeric($1, $3, $4));
+}
+
+event_symbolic: PE_NAME_SYM modifier
+{
+	ABORT_ON(parse_events_add_symbolic($1, $2));
+}
+
+event_generic_hw:
+PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT modifier
+{
+	ABORT_ON(parse_events_add_generic_hw($1, $3, $5, $6));
+}
+|
+PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT modifier
+{
+	ABORT_ON(parse_events_add_generic_hw($1, $3, NULL, $4));
+}
+|
+PE_NAME_CACHE_TYPE modifier
+{
+	ABORT_ON(parse_events_add_generic_hw($1, NULL, NULL, $2));
+}
+
+event_breakpoint: PE_SEP_BP ':' PE_VALUE event_breakpoint_type modifier
+{
+	ABORT_ON(parse_events_add_breakpoint((void *) $3, $4, $5))
+}
+
+event_breakpoint_type: PE_MODIFIER_BPTYPE
+{
+	$$ = $1
+}
+|
+{
+	$$ = NULL;
+}
+
+modifier: PE_MODIFIER_EVENT
+{
+	$$ = $1;
+}
+|
+{
+	$$ = NULL;
+}
+
+%%
+
+void parse_events_error(char const *msg __used)
+{
+}
tools/perf/util/parse-events-flex.l new file +111 -0
new file mode 100644
index 0000000..84b9b0e
@@ -0,0 +1,111 @@
+
+%option prefix="parse_events_"
+
+%{
+#include <errno.h>
+#include "parse-events-bison.h"
+
+enum {
+	VALUE_DEC,
+	VALUE_HEX,
+};
+
+static int value(int base)
+{
+	long num;
+
+	errno = 0;
+	num = strtol(parse_events_text, NULL, base);
+	if (errno)
+		return PE_ERROR;
+
+	parse_events_lval.l = num;
+	return PE_VALUE;
+}
+
+static int __str(char *s, int token)
+{
+	parse_events_lval.s = strdup(s);
+	return token;
+}
+
+static int str(int token)
+{
+	return __str(parse_events_text, token);
+}
+
+static int mod(int token)
+{
+	return __str(parse_events_text + 1, token);
+}
+
+%}
+
+num_dec		[0-9]+
+num_hex		0x[a-fA-F0-9]+
+name_tp		[a-zA-Z_*?]+
+
+%x BP
+
+%%
+
+cpu-cycles|cycles				|
+stalled-cycles-frontend|idle-cycles-frontend	|
+stalled-cycles-backend|idle-cycles-backend	|
+instructions					|
+cache-references				|
+cache-misses					|
+branch-instructions|branches			|
+branch-misses					|
+bus-cycles					|
+cpu-clock					|
+task-clock					|
+page-faults|faults				|
+minor-faults					|
+major-faults					|
+context-switches|cs				|
+cpu-migrations|migrations			|
+alignment-faults				|
+emulation-faults				{ return str(PE_NAME_SYM); }
+
+L1-dcache|l1-d|l1d|L1-data		|
+L1-icache|l1-i|l1i|L1-instruction	|
+LLC|L2					|
+dTLB|d-tlb|Data-TLB			|
+iTLB|i-tlb|Instruction-TLB		|
+branch|branches|bpu|btb|bpc		|
+node					{ return str(PE_NAME_CACHE_TYPE); }
+
+load|loads|read				|
+store|stores|write			|
+prefetch|prefetches			|
+speculative-read|speculative-load	|
+refs|Reference|ops|access		|
+misses|miss				{ return str(PE_NAME_CACHE_OP_RESULT); }
+
+{num_dec}		{ return value(10); }
+{num_hex}		{ return value(16); }
+
+r			{ return PE_SEP_RAW; }
+
+mem			{ BEGIN(BP); return PE_SEP_BP; }
+<BP>:[rwx]{1,3}		{ return mod(PE_MODIFIER_BPTYPE); }
+<BP>:[ukhp]{1,2}	{ return mod(PE_MODIFIER_EVENT); }
+<BP>:			{ return ':'; }
+<BP>{num_dec}		{ return value(10); }
+<BP>{num_hex}		{ return value(16); }
+<BP><<EOF>>		{ BEGIN(INITIAL); }
+<BP>.			{ BEGIN(INITIAL); }
+
+:[ukhp]{1,2}		{ return mod(PE_MODIFIER_EVENT); }
+{name_tp}		{ return str(PE_NAME_TP); }
+-			{ return '-'; }
+,			{ return ','; }
+:			{ return ':'; }
+
+%%
+
+int parse_events_wrap(void)
+{
+	return 1;
+}
tools/perf/util/parse-events.c +151 -308
index 586ab3f..b9c4189 100644
@@ -11,6 +11,9 @@
 #include "cache.h"
 #include "header.h"
 #include "debugfs.h"
+#include "parse-events-flex.h"
+
+#define MAX_NAME_LEN 100
 
 struct event_symbol {
 	u8		type;
@@ -19,11 +22,9 @@ struct event_symbol {
 	const char	*alias;
 };
 
-enum event_result {
-	EVT_FAILED,
-	EVT_HANDLED,
-	EVT_HANDLED_ALL
-};
+int parse_events_parse(void);
+
+static struct perf_evlist *__evlist;
 
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
@@ -352,7 +353,31 @@ const char *__event_name(int type, u64 config)
 	return "unknown";
 }
 
-static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
+static void
+parse_event_modifier(char *mod, struct perf_event_attr *attr);
+
+static int add_event(struct perf_event_attr *attr, char *name, char *mod)
+{
+	struct perf_evsel *evsel;
+	int len = strlen(name);
+
+	parse_event_modifier(mod, attr);
+
+	evsel = perf_evsel__new(attr, __evlist->nr_entries);
+	if (!evsel)
+		return -ENOMEM;
+
+	perf_evlist__add(__evlist, evsel);
+
+	evsel->name = zalloc(len);
+	if (!evsel->name)
+		return -ENOMEM;
+
+	strncpy(evsel->name, name, len);
+	return 0;
+}
+
+static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size)
 {
 	int i, j;
 	int n, longest = -1;
@@ -360,58 +385,57 @@ static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int
 	for (i = 0; i < size; i++) {
 		for (j = 0; j < MAX_ALIASES && names[i][j]; j++) {
 			n = strlen(names[i][j]);
-			if (n > longest && !strncasecmp(*str, names[i][j], n))
+			if (n > longest && !strncasecmp(str, names[i][j], n))
 				longest = n;
 		}
-		if (longest > 0) {
-			*str += longest;
+		if (longest > 0)
 			return i;
-		}
 	}
 
 	return -1;
 }
 
-static enum event_result
-parse_generic_hw_event(const char **str, struct perf_event_attr *attr)
+int parse_events_add_generic_hw(char *type, char *op_result1, char *op_result2,
+				char *mod)
 {
-	const char *s = *str;
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
 	int cache_type = -1, cache_op = -1, cache_result = -1;
+	char *op_result[2] = { op_result1, op_result2 };
+	int i, n;
 
-	cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX);
 	/*
 	 * No fallback - if we cannot get a clear cache type
 	 * then bail out:
 	 */
+	cache_type = parse_aliases(type, hw_cache,
+				   PERF_COUNT_HW_CACHE_MAX);
 	if (cache_type == -1)
-		return EVT_FAILED;
+		return -EINVAL;
 
-	while ((cache_op == -1 || cache_result == -1) && *s == '-') {
-		++s;
+	n = snprintf(name, MAX_NAME_LEN, "%s", type);
+
+	for (i = 0; (i < 2) && (op_result[i]); i++) {
+		char *str = op_result[i];
+
+		snprintf(name + n, MAX_NAME_LEN - n, "-%s\n", str);
 
 		if (cache_op == -1) {
-			cache_op = parse_aliases(&s, hw_cache_op,
-						PERF_COUNT_HW_CACHE_OP_MAX);
+			cache_op = parse_aliases(str, hw_cache_op,
+						 PERF_COUNT_HW_CACHE_OP_MAX);
 			if (cache_op >= 0) {
 				if (!is_cache_op_valid(cache_type, cache_op))
-					return EVT_FAILED;
+					return -EINVAL;
 				continue;
 			}
 		}
 
 		if (cache_result == -1) {
-			cache_result = parse_aliases(&s, hw_cache_result,
+			cache_result = parse_aliases(str, hw_cache_result,
 						PERF_COUNT_HW_CACHE_RESULT_MAX);
 			if (cache_result >= 0)
 				continue;
 		}
-
-		/*
-		 * Can't parse this as a cache op or result, so back up
-		 * to the '-'.
-		 */
-		--s;
-		break;
 	}
 
 	/*
@@ -426,20 +450,16 @@ parse_generic_hw_event(const char **str, struct perf_event_attr *attr)
 	if (cache_result == -1)
 		cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
 
-	attr->config = cache_type | (cache_op << 8) | (cache_result << 16);
-	attr->type = PERF_TYPE_HW_CACHE;
-
-	*str = s;
-	return EVT_HANDLED;
+	memset(&attr, 0, sizeof(attr));
+	attr.config = cache_type | (cache_op << 8) | (cache_result << 16);
+	attr.type = PERF_TYPE_HW_CACHE;
+	return add_event(&attr, name, mod);
 }
 
-static enum event_result
-parse_single_tracepoint_event(char *sys_name,
-			      const char *evt_name,
-			      unsigned int evt_length,
-			      struct perf_event_attr *attr,
-			      const char **strp)
+static int add_tracepoint(char *sys_name, char *evt_name, char *mod)
 {
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
 	char evt_path[MAXPATHLEN];
 	char id_buf[4];
 	u64 id;
@@ -450,130 +470,78 @@ parse_single_tracepoint_event(char *sys_name,
 
 	fd = open(evt_path, O_RDONLY);
 	if (fd < 0)
-		return EVT_FAILED;
+		return -1;
 
 	if (read(fd, id_buf, sizeof(id_buf)) < 0) {
 		close(fd);
-		return EVT_FAILED;
+		return -1;
 	}
 
 	close(fd);
 	id = atoll(id_buf);
-	attr->config = id;
-	attr->type = PERF_TYPE_TRACEPOINT;
-	*strp += strlen(sys_name) + evt_length + 1; /* + 1 for the ':' */
-
-	attr->sample_type |= PERF_SAMPLE_RAW;
-	attr->sample_type |= PERF_SAMPLE_TIME;
-	attr->sample_type |= PERF_SAMPLE_CPU;
 
-	attr->sample_period = 1;
+	memset(&attr, 0, sizeof(attr));
+	attr.config = id;
+	attr.type = PERF_TYPE_TRACEPOINT;
+	attr.sample_type |= PERF_SAMPLE_RAW;
+	attr.sample_type |= PERF_SAMPLE_TIME;
+	attr.sample_type |= PERF_SAMPLE_CPU;
+	attr.sample_period = 1;
 
-
-	return EVT_HANDLED;
+	snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name);
+	return add_event(&attr, name, mod);
 }
 
-/* sys + ':' + event + ':' + flags*/
-#define MAX_EVOPT_LEN	(MAX_EVENT_LENGTH * 2 + 2 + 128)
-static enum event_result
-parse_multiple_tracepoint_event(struct perf_evlist *evlist, char *sys_name,
-				const char *evt_exp, char *flags)
+static int add_tracepoint_multi(char *sys_name, char *evt_name, char *mod)
 {
 	char evt_path[MAXPATHLEN];
 	struct dirent *evt_ent;
 	DIR *evt_dir;
+	int ret = 0;
 
 	snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
 	evt_dir = opendir(evt_path);
-
 	if (!evt_dir) {
 		perror("Can't open event dir");
-		return EVT_FAILED;
+		return -1;
 	}
 
-	while ((evt_ent = readdir(evt_dir))) {
-		char event_opt[MAX_EVOPT_LEN + 1];
-		int len;
-
+	while (!ret && (evt_ent = readdir(evt_dir))) {
 		if (!strcmp(evt_ent->d_name, ".")
 		    || !strcmp(evt_ent->d_name, "..")
 		    || !strcmp(evt_ent->d_name, "enable")
 		    || !strcmp(evt_ent->d_name, "filter"))
 			continue;
 
-		if (!strglobmatch(evt_ent->d_name, evt_exp))
+		if (!strglobmatch(evt_ent->d_name, evt_name))
 			continue;
 
-		len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s%s%s", sys_name,
-			       evt_ent->d_name, flags ? ":" : "",
-			       flags ?: "");
-		if (len < 0)
-			return EVT_FAILED;
-
-		if (parse_events(evlist, event_opt, 0))
-			return EVT_FAILED;
+		ret = add_tracepoint(sys_name, evt_ent->d_name, mod);
 	}
 
-	return EVT_HANDLED_ALL;
+	return ret;
 }
 
-static enum event_result
-parse_tracepoint_event(struct perf_evlist *evlist, const char **strp,
-		       struct perf_event_attr *attr)
+int parse_events_add_tracepoint(char *sys, char *event, char *mod)
 {
-	const char *evt_name;
-	char *flags = NULL, *comma_loc;
-	char sys_name[MAX_EVENT_LENGTH];
-	unsigned int sys_length, evt_length;
-
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return 0;
+	int ret;
 
-	evt_name = strchr(*strp, ':');
-	if (!evt_name)
-		return EVT_FAILED;
-
-	sys_length = evt_name - *strp;
-	if (sys_length >= MAX_EVENT_LENGTH)
-		return 0;
+	ret = debugfs_valid_mountpoint(tracing_events_path);
+	if (ret)
+		return ret;
 
-	strncpy(sys_name, *strp, sys_length);
-	sys_name[sys_length] = '\0';
-	evt_name = evt_name + 1;
-
-	comma_loc = strchr(evt_name, ',');
-	if (comma_loc) {
-		/* take the event name up to the comma */
-		evt_name = strndup(evt_name, comma_loc - evt_name);
-	}
-	flags = strchr(evt_name, ':');
-	if (flags) {
-		/* split it out: */
-		evt_name = strndup(evt_name, flags - evt_name);
-		flags++;
-	}
-
-	evt_length = strlen(evt_name);
-	if (evt_length >= MAX_EVENT_LENGTH)
-		return EVT_FAILED;
-	if (strpbrk(evt_name, "*?")) {
-		*strp += strlen(sys_name) + evt_length + 1; /* 1 == the ':' */
-		return parse_multiple_tracepoint_event(evlist, sys_name,
-						       evt_name, flags);
-	} else {
-		return parse_single_tracepoint_event(sys_name, evt_name,
-						     evt_length, attr, strp);
-	}
+	return strpbrk(event, "*?") ?
+	       add_tracepoint_multi(sys, event, mod) :
+	       add_tracepoint(sys, event, mod);
 }
 
-static enum event_result
-parse_breakpoint_type(const char *type, const char **strp,
-		      struct perf_event_attr *attr)
+static int
+parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
 {
 	int i;
 
 	for (i = 0; i < 3; i++) {
-		if (!type[i])
+		if (!type || !type[i])
 			break;
 
 		switch (type[i]) {
@@ -587,65 +555,40 @@ parse_breakpoint_type(const char *type, const char **strp,
 			attr->bp_type |= HW_BREAKPOINT_X;
 			break;
 		default:
-			return EVT_FAILED;
+			return -EINVAL;
 		}
 	}
+
 	if (!attr->bp_type) /* Default */
 		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
 
-	*strp = type + i;
-
-	return EVT_HANDLED;
+	return 0;
 }
 
-static enum event_result
-parse_breakpoint_event(const char **strp, struct perf_event_attr *attr)
+int parse_events_add_breakpoint(void *ptr, char *type, char *mod)
 {
-	const char *target;
-	const char *type;
-	char *endaddr;
-	u64 addr;
-	enum event_result err;
-
-	target = strchr(*strp, ':');
-	if (!target)
-		return EVT_FAILED;
-
-	if (strncmp(*strp, "mem", target - *strp) != 0)
-		return EVT_FAILED;
-
-	target++;
-
-	addr = strtoull(target, &endaddr, 0);
-	if (target == endaddr)
-		return EVT_FAILED;
-
-	attr->bp_addr = addr;
-	*strp = endaddr;
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
 
-	type = strchr(target, ':');
+	memset(&attr, 0, sizeof(attr));
+	attr.bp_addr = (u64) ptr;
 
-	/* If no type is defined, just rw as default */
-	if (!type) {
-		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
-	} else {
-		err = parse_breakpoint_type(++type, strp, attr);
-		if (err == EVT_FAILED)
-			return EVT_FAILED;
-	}
+	if (parse_breakpoint_type(type, &attr))
+		return -EINVAL;
 
 	/*
 	 * We should find a nice way to override the access length
 	 * Provide some defaults for now
 	 */
-	if (attr->bp_type == HW_BREAKPOINT_X)
-		attr->bp_len = sizeof(long);
+	if (attr.bp_type == HW_BREAKPOINT_X)
+		attr.bp_len = sizeof(long);
 	else
-		attr->bp_len = HW_BREAKPOINT_LEN_4;
+		attr.bp_len = HW_BREAKPOINT_LEN_4;
 
-	attr->type = PERF_TYPE_BREAKPOINT;
+	attr.type = PERF_TYPE_BREAKPOINT;
 
-	return EVT_HANDLED;
+	snprintf(name, MAX_NAME_LEN, "mem:%p:%s", ptr, type ? type : "rw");
+	return add_event(&attr, name, mod);
 }
 
 static int check_events(const char *str, unsigned int i)
@@ -665,85 +608,59 @@ static int check_events(const char *str, unsigned int i)
 	return 0;
 }
 
-static enum event_result
-parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
+int parse_events_add_symbolic(char *symbol, char *mod)
 {
-	const char *str = *strp;
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
 	unsigned int i;
-	int n;
 
 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
-		n = check_events(str, i);
-		if (n > 0) {
-			attr->type = event_symbols[i].type;
-			attr->config = event_symbols[i].config;
-			*strp = str + n;
-			return EVT_HANDLED;
-		}
+		if (!check_events(symbol, i))
+			continue;
+		memset(&attr, 0, sizeof(attr));
+		attr.type = event_symbols[i].type;
+		attr.config = event_symbols[i].config;
+		snprintf(name, MAX_NAME_LEN, "%s", event_symbols[i].symbol);
+		return add_event(&attr, name, mod);
 	}
-	return EVT_FAILED;
+
+	return -EINVAL;
 }
 
-static enum event_result
-parse_raw_event(const char **strp, struct perf_event_attr *attr)
+int parse_events_add_raw(long code, char *mod)
 {
-	const char *str = *strp;
-	u64 config;
-	int n;
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
 
-	if (*str != 'r')
-		return EVT_FAILED;
-	n = hex2u64(str + 1, &config);
-	if (n > 0) {
-		const char *end = str + n + 1;
-		if (*end != '\0' && *end != ',' && *end != ':')
-			return EVT_FAILED;
-
-		*strp = end;
-		attr->type = PERF_TYPE_RAW;
-		attr->config = config;
-		return EVT_HANDLED;
-	}
-	return EVT_FAILED;
+	memset(&attr, 0, sizeof(attr));
+	attr.type = PERF_TYPE_RAW;
+	attr.config = code;
+
+	snprintf(name, MAX_NAME_LEN, "r%lx", code);
+	return add_event(&attr, name, mod);
 }
 
-static enum event_result
-parse_numeric_event(const char **strp, struct perf_event_attr *attr)
+int parse_events_add_numeric(long type, long config, char *mod)
 {
-	const char *str = *strp;
-	char *endp;
-	unsigned long type;
-	u64 config;
-
-	type = strtoul(str, &endp, 0);
-	if (endp > str && type < PERF_TYPE_MAX && *endp == ':') {
-		str = endp + 1;
-		config = strtoul(str, &endp, 0);
-		if (endp > str) {
-			attr->type = type;
-			attr->config = config;
-			*strp = endp;
-			return EVT_HANDLED;
-		}
-	}
-	return EVT_FAILED;
+	struct perf_event_attr attr;
+	char name[MAX_NAME_LEN];
+
+	memset(&attr, 0, sizeof(attr));
+	attr.type = type;
+	attr.config = config;
+
+	snprintf(name, MAX_NAME_LEN, "%lx:%lx", type, config);
+	return add_event(&attr, name, mod);
 }
 
-static int
-parse_event_modifier(const char **strp, struct perf_event_attr *attr)
+static void
+parse_event_modifier(char *str, struct perf_event_attr *attr)
 {
-	const char *str = *strp;
 	int exclude = 0;
 	int eu = 0, ek = 0, eh = 0, precise = 0;
 
-	if (!*str)
-		return 0;
-
-	if (*str == ',')
-		return 0;
-
-	if (*str++ != ':')
-		return -1;
+	if (str == NULL)
+		return;
 
 	while (*str) {
 		if (*str == 'u') {
@@ -765,108 +682,36 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr)
 
 		++str;
 	}
-	if (str < *strp + 2)
-		return -1;
-
-	*strp = str;
 
 	attr->exclude_user   = eu;
 	attr->exclude_kernel = ek;
 	attr->exclude_hv     = eh;
 	attr->precise_ip     = precise;
-
-	return 0;
+	return;
 }
 
-/*
- * Each event can have multiple symbolic names.
- * Symbolic names are (almost) exactly matched.
- */
-static enum event_result
-parse_event_symbols(struct perf_evlist *evlist, const char **str,
-		    struct perf_event_attr *attr)
+int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
 {
-	enum event_result ret;
-
-	ret = parse_tracepoint_event(evlist, str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
-
-	ret = parse_raw_event(str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
+	YY_BUFFER_STATE buffer;
+	int ret;
 
-	ret = parse_numeric_event(str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
+	__evlist = evlist;
 
-	ret = parse_symbolic_event(str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
+	buffer = parse_events__scan_string(str);
 
-	ret = parse_generic_hw_event(str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
+	ret = parse_events_parse();
 
-	ret = parse_breakpoint_event(str, attr);
-	if (ret != EVT_FAILED)
-		goto modifier;
+	parse_events__flush_buffer(buffer);
+	parse_events__delete_buffer(buffer);
 
-	fprintf(stderr, "invalid or unsupported event: '%s'\n", *str);
-	fprintf(stderr, "Run 'perf list' for a list of valid events\n");
-	return EVT_FAILED;
-
-modifier:
-	if (parse_event_modifier(str, attr) < 0) {
-		fprintf(stderr, "invalid event modifier: '%s'\n", *str);
-		fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n");
-
-		return EVT_FAILED;
+	if (ret) {
+		fprintf(stderr, "invalid or unsupported event: '%s'\n", str);
+		fprintf(stderr, "Run 'perf list' for a list of valid events\n");
 	}
 
 	return ret;
 }
 
-int parse_events(struct perf_evlist *evlist , const char *str, int unset __used)
-{
-	struct perf_event_attr attr;
-	enum event_result ret;
-	const char *ostr;
-
-	for (;;) {
-		ostr = str;
-		memset(&attr, 0, sizeof(attr));
-		ret = parse_event_symbols(evlist, &str, &attr);
-		if (ret == EVT_FAILED)
-			return -1;
-
-		if (!(*str == 0 || *str == ',' || isspace(*str)))
-			return -1;
-
-		if (ret != EVT_HANDLED_ALL) {
-			struct perf_evsel *evsel;
-			evsel = perf_evsel__new(&attr, evlist->nr_entries);
-			if (evsel == NULL)
-				return -1;
-			perf_evlist__add(evlist, evsel);
-
-			evsel->name = calloc(str - ostr + 1, 1);
-			if (!evsel->name)
-				return -1;
-			strncpy(evsel->name, ostr, str - ostr);
-		}
-
-		if (*str == 0)
-			break;
-		if (*str == ',')
-			++str;
-		while (isspace(*str))
-			++str;
-	}
-
-	return 0;
-}
-
 int parse_events_option(const struct option *opt, const char *str,
 			int unset __used)
 {
@@ -1039,8 +884,6 @@ int print_hwcache_events(const char *event_glob)
 	return printed;
 }
 
-#define MAX_NAME_LEN 100
-
 /*
  * Print the help text for the event symbols:
  */
tools/perf/util/parse-events.h +9 -0
index 7e0cbe7..fa3ac7f 100644
@@ -33,6 +33,15 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
 
 #define EVENTS_HELP_MAX (128*1024)
 
+int parse_events_add_tracepoint(char *sys, char *event, char *mod);
+int parse_events_add_raw(long code, char *mod);
+int parse_events_add_numeric(long type, long config, char *mod);
+int parse_events_add_symbolic(char *symbol, char *mod);
+int parse_events_add_generic_hw(char *type, char *op_result1, char *op_result2,
+				char *mod);
+int parse_events_add_breakpoint(void *ptr, char *type, char *mod);
+void parse_events_error(char const *msg);
+
 void print_events(const char *event_glob);
 void print_events_type(u8 type);
 void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
Signature · 1 line
1.7.4
author
#83 lore raw

Re: [PATCH 1/3] perf, tool: Add parser generator for events parsing

Quoted 7 lines · Arnaldo Carvalho de Melo

Em Thu, Dec 15, 2011 at 04:30:37PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Changing event parsing to use flex/bison parse generator. The event syntax stays as it is.

Seems really cool, using the right tool for the task, comments:

. Can we avoid more globals? Like that __event_list one.

ok, looks like there's a way to pass an parameter to the parse function, I'll chec and make the change if possible

Quoted 9 lines

. All those ABORT_ON do what? die() like stuff? /me googles YYABORT...

----
YYABORT
Return immediately with value 1 (to report failure).
----

Ok, so it gets propagated back and hopefully the we die() just
back at main() in tools/perf/perf.c, right?

right, it'll make parse_events_parse return error

Quoted 6 lines

. make help | perf

Then running one of those targets and trying to build perf still
works? I guess so, but better check that.

Quoted 7 lines

Having it added to some new "make perf-test" that does that +
'perf test' too would get you brownie points. Leave it for later/someone else if you're busy/not looking for more work, of course 8-)

. We have some tests to parse events in 'perf test', right? From the top of my head it was even ya that did that, guess those are ok/improved (still need to look at the other patches in the backlog).

right ;)

thanks,
jirka

author
#84 lore raw

PATCH 2/3 perf, tool: Add new event group management

In reply to Jiri Olsa

The current event grouping is basic. If you specify the '--group' option for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Extending the '--group/-g' option power while preserving the current behaviour.

It is now possible to use '--group/-g' option with 'parsed' value, which will create groups based on the command line events layout.

With the '--group/-g parsed' option specified, all events separated by ',' within a single '-e' option now become members of a group with the first event specified as a group leader. Another '-e' option with multiple events creates separate group.

All groups are created with regards to threads and cpus. Thus recording an event group within a 2 threads on server with 4 CPUs will create 8 separate groups.

Examples (first event in brackets is group leader):

  # 1 group (cpu-clock,task-clock)
  perf record --group -e cpu-clock,task-clock ls
  perf record --group parsed -e cpu-clock,task-clock ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record --group parsed -e cpu-clock,task-clock \
   -e minor-faults,major-faults ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record --group parsed -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults,instructions)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls
---
 tools/perf/Makefile            |    2 ++
 tools/perf/builtin-record.c    |    8 +++++---
 tools/perf/builtin-stat.c      |   10 ++++++----
 tools/perf/builtin-top.c       |    8 +++++---
 tools/perf/perf.h              |    2 +-
 tools/perf/util/evsel.c        |   28 ++++++++++++++++++++++------
 tools/perf/util/evsel.h        |    9 +++++----
 tools/perf/util/group.c        |   23 +++++++++++++++++++++++
 tools/perf/util/group.h        |   25 +++++++++++++++++++++++++
 tools/perf/util/parse-events.c |    6 ++++++
 tools/perf/util/python.c       |    4 ++++
 tools/perf/util/top.h          |    2 +-
 12 files changed, 105 insertions(+), 22 deletions(-)
 create mode 100644 tools/perf/util/group.c
 create mode 100644 tools/perf/util/group.h
tools/perf/Makefile +2 -0
index ef6b621..c54b595 100644
@@ -299,6 +299,7 @@ LIB_H += util/cpumap.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
+LIB_H += util/group.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -356,6 +357,7 @@ LIB_OBJS += $(OUTPUT)util/util.o
 LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cpumap.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
+LIB_OBJS += $(OUTPUT)util/group.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
tools/perf/builtin-record.c +5 -3
index 766fa0a..581c72d 100644
@@ -26,6 +26,7 @@
 #include "util/symbol.h"
 #include "util/cpumap.h"
 #include "util/thread_map.h"
+#include "util/group.h"
 
 #include <unistd.h>
 #include <sched.h>
@@ -202,7 +203,7 @@ static void perf_record__open(struct perf_record *rec)
 		 */
 		bool time_needed = attr->sample_type & PERF_SAMPLE_TIME;
 
-		if (opts->group && pos != first)
+		if (group_is_single(opts->group) && pos != first)
 			group_fd = first->fd;
 retry_sample_id:
 		attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0;
@@ -688,8 +689,9 @@ const struct option record_options[] = {
 	OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
 	OPT_UINTEGER('m', "mmap-pages", &record.opts.mmap_pages,
 		     "number of mmap data pages"),
-	OPT_BOOLEAN(0, "group", &record.opts.group,
-		    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT(0, "group", &record.opts.group, "[parsed]",
+		     "put the counters into a counter group",
+		     parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('g', "call-graph", &record.opts.call_graph,
 		    "do call-graph (stack chain/backtrace) recording"),
 	OPT_INCR('v', "verbose", &verbose,
tools/perf/builtin-stat.c +6 -4
index cc53de3..c28c852 100644
@@ -55,6 +55,7 @@
 #include "util/cpumap.h"
 #include "util/thread.h"
 #include "util/thread_map.h"
+#include "util/group.h"
 
 #include <sys/prctl.h>
 #include <math.h>
@@ -193,7 +194,7 @@ static int			big_num_opt			=  -1;
 static const char		*cpu_list;
 static const char		*csv_sep			= NULL;
 static bool			csv_output			= false;
-static bool			group				= false;
+static int			group;
 static const char		*output_name			= NULL;
 static FILE			*output				= NULL;
 static int			output_fd;
@@ -284,7 +285,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
 	struct perf_event_attr *attr = &evsel->attr;
 	struct xyarray *group_fd = NULL;
 
-	if (group && evsel != first)
+	if (group_is_single(group) && evsel != first)
 		group_fd = first->fd;
 
 	if (scale)
@@ -1068,8 +1069,9 @@ static const struct option options[] = {
 		    "stat events on existing thread id"),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
-	OPT_BOOLEAN('g', "group", &group,
-		    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT('g', "group", &group, "[parsed]",
+		    "put the counters into a counter group",
+		    parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('c', "scale", &scale,
 		    "scale/normalize counters"),
 	OPT_INCR('v', "verbose", &verbose,
tools/perf/builtin-top.c +5 -3
index c3836b9..c1f205c 100644
@@ -38,6 +38,7 @@
 #include "util/cpumap.h"
 #include "util/xyarray.h"
 #include "util/sort.h"
+#include "util/group.h"
 
 #include "util/debug.h"
 
@@ -830,7 +831,7 @@ static void perf_top__start_counters(struct perf_top *top)
 		struct perf_event_attr *attr = &counter->attr;
 		struct xyarray *group_fd = NULL;
 
-		if (top->group && counter != first)
+		if (group_is_single(top->group) && counter != first)
 			group_fd = first->fd;
 
 		attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
@@ -1120,8 +1121,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
 			    "dump the symbol table used for profiling"),
 	OPT_INTEGER('f', "count-filter", &top.count_filter,
 		    "only display functions with more events than this"),
-	OPT_BOOLEAN('g', "group", &top.group,
-			    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT('g', "group", &top.group, "[parsed]",
+		    "put the counters into a counter group",
+		    parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('i', "inherit", &top.inherit,
 		    "child tasks inherit counters"),
 	OPT_STRING(0, "sym-annotate", &top.sym_filter, "symbol name",
tools/perf/perf.h +1 -1
index ea804f5..b2aa37a 100644
@@ -189,7 +189,7 @@ struct perf_record_opts {
 	pid_t	     target_pid;
 	pid_t	     target_tid;
 	bool	     call_graph;
-	bool	     group;
+	int	     group;
 	bool	     inherit_stat;
 	bool	     no_delay;
 	bool	     no_inherit;
tools/perf/util/evsel.c +22 -6
index 4a8c8b0..280286a 100644
@@ -14,6 +14,7 @@
 #include "util.h"
 #include "cpumap.h"
 #include "thread_map.h"
+#include "group.h"
 
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
@@ -284,8 +285,17 @@ int __perf_evsel__read(struct perf_evsel *evsel,
 	return 0;
 }
 
+static int perf_evsel_group(struct perf_evsel *evsel,
+			    int cpu, int thread)
+{
+	if (evsel->group_leader)
+		return FD(evsel->group_leader, cpu, thread);
+
+	return -1;
+}
+
 static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-			      struct thread_map *threads, bool group,
+			      struct thread_map *threads, int group,
 			      struct xyarray *group_fds)
 {
 	int cpu, thread;
@@ -302,13 +312,19 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 	}
 
 	for (cpu = 0; cpu < cpus->nr; cpu++) {
-		int group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1;
+		int group_fd = -1;
+
+		if (group_is_single(group))
+			group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1;
 
 		for (thread = 0; thread < threads->nr; thread++) {
 
 			if (!evsel->cgrp)
 				pid = threads->map[thread];
 
+			if (group_is_parsed(group))
+				group_fd = perf_evsel_group(evsel, cpu, thread);
+
 			FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr,
 								     pid,
 								     cpus->map[cpu],
@@ -318,7 +334,7 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 				goto out_close;
 			}
 
-			if (group && group_fd == -1)
+			if (group_is_single(group) && group_fd == -1)
 				group_fd = FD(evsel, cpu, thread);
 		}
 	}
@@ -363,7 +379,7 @@ static struct {
 };
 
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-		     struct thread_map *threads, bool group,
+		     struct thread_map *threads, int group,
 		     struct xyarray *group_fd)
 {
 	if (cpus == NULL) {
@@ -378,7 +394,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 }
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus, bool group,
+			     struct cpu_map *cpus, int group,
 			     struct xyarray *group_fd)
 {
 	return __perf_evsel__open(evsel, cpus, &empty_thread_map.map, group,
@@ -386,7 +402,7 @@ int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
 }
 
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads, bool group,
+				struct thread_map *threads, int group,
 				struct xyarray *group_fd)
 {
 	return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group,
tools/perf/util/evsel.h +5 -4
index 326b8e4..db9ee0b 100644
@@ -66,6 +66,7 @@ struct perf_evsel {
 		void		*data;
 	} handler;
 	bool 			supported;
+	struct perf_evsel	*group_leader;
 };
 
 struct cpu_map;
@@ -90,14 +91,14 @@ void perf_evsel__free_id(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus, bool group,
+			     struct cpu_map *cpus, int group,
 			     struct xyarray *group_fds);
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads, bool group,
+				struct thread_map *threads, int group,
 				struct xyarray *group_fds);
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-		     struct thread_map *threads, bool group,
-		     struct xyarray *group_fds);
+		     struct thread_map *threads, int group,
+		     struct xyarray *group_fd);
 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 #define perf_evsel__match(evsel, t, c)		\
tools/perf/util/group.c new file +23 -0
new file mode 100644
index 0000000..89468a9
@@ -0,0 +1,23 @@
+
+#include <linux/compiler.h>
+#include "types.h"
+#include "util.h"
+#include "parse-options.h"
+#include "group.h"
+
+int parse_group(const struct option *opt, const char *str,
+		int unset __used)
+{
+	int *group_opt = (int *) opt->value;
+
+	if (!str)
+		*group_opt = PERF_GROUP_SINGLE;
+	else if (!strcmp(str, "parsed"))
+		*group_opt = PERF_GROUP_PARSED;
+	else {
+		fprintf(stderr, "unknown group option value\n");
+		return -1;
+	}
+
+	return 0;
+}
tools/perf/util/group.h new file +25 -0
new file mode 100644
index 0000000..ad80015
@@ -0,0 +1,25 @@
+#ifndef __GROUP_H__
+#define __GROUP_H__
+
+struct option;
+
+enum perf_group_opt {
+	PERF_GROUP_NONE,
+	PERF_GROUP_SINGLE,
+	PERF_GROUP_PARSED
+};
+
+int parse_group(const struct option *opt, const char *str,
+		int unset);
+
+static inline bool group_is_single(int group)
+{
+	return group == PERF_GROUP_SINGLE;
+}
+
+static inline bool group_is_parsed(int group)
+{
+	return group == PERF_GROUP_PARSED;
+}
+
+#endif /* __GROUP_H__ */
tools/perf/util/parse-events.c +6 -0
index b9c4189..b7913c3 100644
@@ -25,6 +25,7 @@ struct event_symbol {
 int parse_events_parse(void);
 
 static struct perf_evlist *__evlist;
+static struct perf_evsel *group_leader;
 
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
@@ -373,6 +374,10 @@ static int add_event(struct perf_event_attr *attr, char *name, char *mod)
 	if (!evsel->name)
 		return -ENOMEM;
 
+	evsel->group_leader = group_leader;
+	if (!group_leader)
+		group_leader = evsel;
+
 	strncpy(evsel->name, name, len);
 	return 0;
 }
@@ -696,6 +701,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
 	int ret;
 
 	__evlist = evlist;
+	group_leader = NULL;
 
 	buffer = parse_events__scan_string(str);
 
tools/perf/util/python.c +4 -0
index 9dd47a4..b91a43b 100644
@@ -7,6 +7,7 @@
 #include "event.h"
 #include "cpumap.h"
 #include "thread_map.h"
+#include "group.h"
 
 /* Define PyVarObject_HEAD_INIT for python 2.5 */
 #ifndef PyVarObject_HEAD_INIT
@@ -828,6 +829,9 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group))
 		return NULL;
 
+	if (group)
+		group = PERF_GROUP_SINGLE;
+
 	if (perf_evlist__open(evlist, group) < 0) {
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
tools/perf/util/top.h +1 -1
index a248f3c..f545bc6 100644
@@ -32,7 +32,7 @@ struct perf_top {
 	bool		   kptr_restrict_warned;
 	bool		   vmlinux_warned;
 	bool		   inherit;
-	bool		   group;
+	int		   group;
 	bool		   sample_id_all_avail;
 	bool		   dump_symtab;
 	const char	   *cpu_list;
Signature · 1 line
1.7.4
#85 lore raw

Re: [PATCH 2/3] perf, tool: Add new event group management

Em Thu, Dec 15, 2011 at 04:30:38PM +0100, Jiri Olsa escreveu:

Quoted 34 lines

The current event grouping is basic. If you specify the '--group' option for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Extending the '--group/-g' option power while preserving the current behaviour.

It is now possible to use '--group/-g' option with 'parsed' value, which will create groups based on the command line events layout.

With the '--group/-g parsed' option specified, all events separated by ',' within a single '-e' option now become members of a group with the first event specified as a group leader. Another '-e' option with multiple events creates separate group.

All groups are created with regards to threads and cpus. Thus recording an event group within a 2 threads on server with 4 CPUs will create 8 separate groups.

Examples (first event in brackets is group leader):

  # 1 group (cpu-clock,task-clock)
  perf record --group -e cpu-clock,task-clock ls
  perf record --group parsed -e cpu-clock,task-clock ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record --group parsed -e cpu-clock,task-clock \
   -e minor-faults,major-faults ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults ls
Quoted 7 lines
  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record --group parsed -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults,instructions)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls

Looks awesome! Peter, comments? All OK with you?

Jiri, can we have some 'perf test' that tests this thoroughly? Are they there already on that next patch and I'm being to change my glasses yet again?

Some minor nits below:

- Arnaldo

Quoted 151 lines
---
 tools/perf/Makefile            |    2 ++
 tools/perf/builtin-record.c    |    8 +++++---
 tools/perf/builtin-stat.c      |   10 ++++++----
 tools/perf/builtin-top.c       |    8 +++++---
 tools/perf/perf.h              |    2 +-
 tools/perf/util/evsel.c        |   28 ++++++++++++++++++++++------
 tools/perf/util/evsel.h        |    9 +++++----
 tools/perf/util/group.c        |   23 +++++++++++++++++++++++
 tools/perf/util/group.h        |   25 +++++++++++++++++++++++++
 tools/perf/util/parse-events.c |    6 ++++++
 tools/perf/util/python.c       |    4 ++++
 tools/perf/util/top.h          |    2 +-
 12 files changed, 105 insertions(+), 22 deletions(-)
 create mode 100644 tools/perf/util/group.c
 create mode 100644 tools/perf/util/group.h
tools/perf/Makefile +2 -0
index ef6b621..c54b595 100644
@@ -299,6 +299,7 @@ LIB_H += util/cpumap.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
+LIB_H += util/group.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -356,6 +357,7 @@ LIB_OBJS += $(OUTPUT)util/util.o
 LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cpumap.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
+LIB_OBJS += $(OUTPUT)util/group.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
tools/perf/builtin-record.c +5 -3
index 766fa0a..581c72d 100644
@@ -26,6 +26,7 @@
 #include "util/symbol.h"
 #include "util/cpumap.h"
 #include "util/thread_map.h"
+#include "util/group.h"
 
 #include <unistd.h>
 #include <sched.h>
@@ -202,7 +203,7 @@ static void perf_record__open(struct perf_record *rec)
 		 */
 		bool time_needed = attr->sample_type & PERF_SAMPLE_TIME;
 
-		if (opts->group && pos != first)
+		if (group_is_single(opts->group) && pos != first)
 			group_fd = first->fd;
 retry_sample_id:
 		attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0;
@@ -688,8 +689,9 @@ const struct option record_options[] = {
 	OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
 	OPT_UINTEGER('m', "mmap-pages", &record.opts.mmap_pages,
 		     "number of mmap data pages"),
-	OPT_BOOLEAN(0, "group", &record.opts.group,
-		    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT(0, "group", &record.opts.group, "[parsed]",
+		     "put the counters into a counter group",
+		     parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('g', "call-graph", &record.opts.call_graph,
 		    "do call-graph (stack chain/backtrace) recording"),
 	OPT_INCR('v', "verbose", &verbose,
tools/perf/builtin-stat.c +6 -4
index cc53de3..c28c852 100644
@@ -55,6 +55,7 @@
 #include "util/cpumap.h"
 #include "util/thread.h"
 #include "util/thread_map.h"
+#include "util/group.h"
 
 #include <sys/prctl.h>
 #include <math.h>
@@ -193,7 +194,7 @@ static int			big_num_opt			=  -1;
 static const char		*cpu_list;
 static const char		*csv_sep			= NULL;
 static bool			csv_output			= false;
-static bool			group				= false;
+static int			group;
 static const char		*output_name			= NULL;
 static FILE			*output				= NULL;
 static int			output_fd;
@@ -284,7 +285,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
 	struct perf_event_attr *attr = &evsel->attr;
 	struct xyarray *group_fd = NULL;
 
-	if (group && evsel != first)
+	if (group_is_single(group) && evsel != first)
 		group_fd = first->fd;
 
 	if (scale)
@@ -1068,8 +1069,9 @@ static const struct option options[] = {
 		    "stat events on existing thread id"),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
-	OPT_BOOLEAN('g', "group", &group,
-		    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT('g', "group", &group, "[parsed]",
+		    "put the counters into a counter group",
+		    parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('c', "scale", &scale,
 		    "scale/normalize counters"),
 	OPT_INCR('v', "verbose", &verbose,
tools/perf/builtin-top.c +5 -3
index c3836b9..c1f205c 100644
@@ -38,6 +38,7 @@
 #include "util/cpumap.h"
 #include "util/xyarray.h"
 #include "util/sort.h"
+#include "util/group.h"
 
 #include "util/debug.h"
 
@@ -830,7 +831,7 @@ static void perf_top__start_counters(struct perf_top *top)
 		struct perf_event_attr *attr = &counter->attr;
 		struct xyarray *group_fd = NULL;
 
-		if (top->group && counter != first)
+		if (group_is_single(top->group) && counter != first)
 			group_fd = first->fd;
 
 		attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
@@ -1120,8 +1121,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
 			    "dump the symbol table used for profiling"),
 	OPT_INTEGER('f', "count-filter", &top.count_filter,
 		    "only display functions with more events than this"),
-	OPT_BOOLEAN('g', "group", &top.group,
-			    "put the counters into a counter group"),
+	OPT_CALLBACK_DEFAULT('g', "group", &top.group, "[parsed]",
+		    "put the counters into a counter group",
+		    parse_group, PERF_GROUP_NONE),
 	OPT_BOOLEAN('i', "inherit", &top.inherit,
 		    "child tasks inherit counters"),
 	OPT_STRING(0, "sym-annotate", &top.sym_filter, "symbol name",
tools/perf/perf.h +0 -0
index ea804f5..b2aa37a 100644

tools/perf/perf.h struct perf_record_opts { · line 192

Quoted 5 lines
tools/perf/perf.h +1 -1
@@ -189,7 +189,7 @@ struct perf_record_opts {
 	pid_t	     target_pid;
 	pid_t	     target_tid;
 	bool	     call_graph;
-	bool	     group;
+	int	     group;

When doing that move it consider alignment, you've just added a 2 bytes hole here :-) Not critical path, but never the less good to have things properly aligned.

Shameless plug: pahole would help here, I think I should even add a pahole check to checkpatch.pl to warn the user if he/she is adding holes...

Quoted 16 lines
tools/perf/perf.h +0 -0
 	bool	     inherit_stat;
 	bool	     no_delay;
 	bool	     no_inherit;
tools/perf/util/evsel.c +1 -0
index 4a8c8b0..280286a 100644
@@ -14,6 +14,7 @@
 #include "util.h"
 #include "cpumap.h"
 #include "thread_map.h"
+#include "group.h"
 
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))

tools/perf/util/evsel.c int __perf_evsel__read(struct perf_evsel *evsel, · line 289

Quoted 5 lines
tools/perf/util/evsel.c +2 -0
@@ -284,8 +285,17 @@ int __perf_evsel__read(struct perf_evsel *evsel,
 	return 0;
 }
 
+static int perf_evsel_group(struct perf_evsel *evsel,
+			    int cpu, int thread)

Please use "perf_evsel__group(...)

The double __ is to ease grepping/ctag'in and to separate class name (perf_evsel) from method name (group), a convention I used in other projects and have been trying to keep consistent in tools/perf/ even not being completely crazy about it to refuse patches based only on that aspect.

Quoted 229 lines
tools/perf/util/evsel.c +19 -6
+{
+	if (evsel->group_leader)
+		return FD(evsel->group_leader, cpu, thread);
+
+	return -1;
+}
+
 static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-			      struct thread_map *threads, bool group,
+			      struct thread_map *threads, int group,
 			      struct xyarray *group_fds)
 {
 	int cpu, thread;
@@ -302,13 +312,19 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 	}
 
 	for (cpu = 0; cpu < cpus->nr; cpu++) {
-		int group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1;
+		int group_fd = -1;
+
+		if (group_is_single(group))
+			group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1;
 
 		for (thread = 0; thread < threads->nr; thread++) {
 
 			if (!evsel->cgrp)
 				pid = threads->map[thread];
 
+			if (group_is_parsed(group))
+				group_fd = perf_evsel_group(evsel, cpu, thread);
+
 			FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr,
 								     pid,
 								     cpus->map[cpu],
@@ -318,7 +334,7 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 				goto out_close;
 			}
 
-			if (group && group_fd == -1)
+			if (group_is_single(group) && group_fd == -1)
 				group_fd = FD(evsel, cpu, thread);
 		}
 	}
@@ -363,7 +379,7 @@ static struct {
 };
 
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-		     struct thread_map *threads, bool group,
+		     struct thread_map *threads, int group,
 		     struct xyarray *group_fd)
 {
 	if (cpus == NULL) {
@@ -378,7 +394,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 }
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus, bool group,
+			     struct cpu_map *cpus, int group,
 			     struct xyarray *group_fd)
 {
 	return __perf_evsel__open(evsel, cpus, &empty_thread_map.map, group,
@@ -386,7 +402,7 @@ int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
 }
 
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads, bool group,
+				struct thread_map *threads, int group,
 				struct xyarray *group_fd)
 {
 	return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group,
tools/perf/util/evsel.h +5 -4
index 326b8e4..db9ee0b 100644
@@ -66,6 +66,7 @@ struct perf_evsel {
 		void		*data;
 	} handler;
 	bool 			supported;
+	struct perf_evsel	*group_leader;
 };
 
 struct cpu_map;
@@ -90,14 +91,14 @@ void perf_evsel__free_id(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus, bool group,
+			     struct cpu_map *cpus, int group,
 			     struct xyarray *group_fds);
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads, bool group,
+				struct thread_map *threads, int group,
 				struct xyarray *group_fds);
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-		     struct thread_map *threads, bool group,
-		     struct xyarray *group_fds);
+		     struct thread_map *threads, int group,
+		     struct xyarray *group_fd);
 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 #define perf_evsel__match(evsel, t, c)		\
tools/perf/util/group.c new file +23 -0
new file mode 100644
index 0000000..89468a9
@@ -0,0 +1,23 @@
+
+#include <linux/compiler.h>
+#include "types.h"
+#include "util.h"
+#include "parse-options.h"
+#include "group.h"
+
+int parse_group(const struct option *opt, const char *str,
+		int unset __used)
+{
+	int *group_opt = (int *) opt->value;
+
+	if (!str)
+		*group_opt = PERF_GROUP_SINGLE;
+	else if (!strcmp(str, "parsed"))
+		*group_opt = PERF_GROUP_PARSED;
+	else {
+		fprintf(stderr, "unknown group option value\n");
+		return -1;
+	}
+
+	return 0;
+}
tools/perf/util/group.h new file +25 -0
new file mode 100644
index 0000000..ad80015
@@ -0,0 +1,25 @@
+#ifndef __GROUP_H__
+#define __GROUP_H__
+
+struct option;
+
+enum perf_group_opt {
+	PERF_GROUP_NONE,
+	PERF_GROUP_SINGLE,
+	PERF_GROUP_PARSED
+};
+
+int parse_group(const struct option *opt, const char *str,
+		int unset);
+
+static inline bool group_is_single(int group)
+{
+	return group == PERF_GROUP_SINGLE;
+}
+
+static inline bool group_is_parsed(int group)
+{
+	return group == PERF_GROUP_PARSED;
+}
+
+#endif /* __GROUP_H__ */
tools/perf/util/parse-events.c +6 -0
index b9c4189..b7913c3 100644
@@ -25,6 +25,7 @@ struct event_symbol {
 int parse_events_parse(void);
 
 static struct perf_evlist *__evlist;
+static struct perf_evsel *group_leader;
 
 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
@@ -373,6 +374,10 @@ static int add_event(struct perf_event_attr *attr, char *name, char *mod)
 	if (!evsel->name)
 		return -ENOMEM;
 
+	evsel->group_leader = group_leader;
+	if (!group_leader)
+		group_leader = evsel;
+
 	strncpy(evsel->name, name, len);
 	return 0;
 }
@@ -696,6 +701,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
 	int ret;
 
 	__evlist = evlist;
+	group_leader = NULL;
 
 	buffer = parse_events__scan_string(str);
 
tools/perf/util/python.c +4 -0
index 9dd47a4..b91a43b 100644
@@ -7,6 +7,7 @@
 #include "event.h"
 #include "cpumap.h"
 #include "thread_map.h"
+#include "group.h"
 
 /* Define PyVarObject_HEAD_INIT for python 2.5 */
 #ifndef PyVarObject_HEAD_INIT
@@ -828,6 +829,9 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group))
 		return NULL;
 
+	if (group)
+		group = PERF_GROUP_SINGLE;
+
 	if (perf_evlist__open(evlist, group) < 0) {
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
tools/perf/util/top.h +1 -1
index a248f3c..f545bc6 100644
@@ -32,7 +32,7 @@ struct perf_top {
 	bool		   kptr_restrict_warned;
 	bool		   vmlinux_warned;
 	bool		   inherit;
-	bool		   group;
+	int		   group;
 	bool		   sample_id_all_avail;
 	bool		   dump_symtab;
 	const char	   *cpu_list;
Signature · 1 line
1.7.4
#86 lore raw

Re: [PATCH 2/3] perf, tool: Add new event group management

Quoted 1 line · Arnaldo Carvalho de Melo

Looks awesome! Peter, comments? All OK with you?

Read my replies, not really. I'm ok with the idea, but I think we should take this possibility to clean up the syntax, sod backward compat.

#87 lore raw

Re: [PATCH 2/3] perf, tool: Add new event group management

Em Tue, Dec 20, 2011 at 10:20:51PM +0100, Peter Zijlstra escreveu:

Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Looks awesome! Peter, comments? All OK with you?

Read my replies, not really. I'm ok with the idea, but I think we should take this possibility to clean up the syntax, sod backward compat.

Ok, I meant the idea mostly, didn't looked that much at the syntax and haven't taken any of those patches :)

- Arnaldo

author
#88 lore raw

PATCH 3/3 perf, tool: Add more automated tests for event parsing

In reply to Jiri Olsa

Adding automated tests for event parsing to include testing for modifier, ',' operator and group_leader.

---
 tools/perf/builtin-test.c |  245 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 244 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +244 -1
index 6173f78..0cdb4c9 100644
@@ -603,7 +603,7 @@ out_free_threads:
 
 #define TEST_ASSERT_VAL(text, cond) \
 do { \
-	if (!cond) { \
+	if (!(cond)) { \
 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
 		return -1; \
 	} \
@@ -759,6 +759,201 @@ static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_tracepoint(evlist);
+}
+
+static int
+test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		TEST_ASSERT_VAL("wrong exclude_user",
+				!evsel->attr.exclude_user);
+		TEST_ASSERT_VAL("wrong exclude_kernel",
+				evsel->attr.exclude_kernel);
+		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	}
+
+	return test__checkevent_tracepoint_multi(evlist);
+}
+
+static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_raw(evlist);
+}
+
+static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_numeric(evlist);
+}
+
+static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_alias(evlist);
+}
+
+static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_genhw(evlist);
+}
+
+static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint(evlist);
+}
+
+static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_x(evlist);
+}
+
+static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_r(evlist);
+}
+
+static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_w(evlist);
+}
+
+static int test__checkevent_list(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+	struct perf_evsel *group_leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* r1 */
+	evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
+	group_leader = evsel;
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader", !evsel->group_leader);
+
+	/* syscalls:sys_enter_open:k */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong sample_type",
+		(PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
+		evsel->attr.sample_type);
+	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader",
+			evsel->group_leader == group_leader);
+
+	/* 1:1:hp */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader",
+			evsel->group_leader == group_leader);
+
+	return 0;
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -808,6 +1003,54 @@ static struct test__event_st {
 		.name  = "mem:0:w",
 		.check = test__checkevent_breakpoint_w,
 	},
+	{
+		.name  = "syscalls:sys_enter_open:k",
+		.check = test__checkevent_tracepoint_modifier,
+	},
+	{
+		.name  = "syscalls:*:u",
+		.check = test__checkevent_tracepoint_multi_modifier,
+	},
+	{
+		.name  = "r1:kp",
+		.check = test__checkevent_raw_modifier,
+	},
+	{
+		.name  = "1:1:hp",
+		.check = test__checkevent_numeric_modifier,
+	},
+	{
+		.name  = "instructions:h",
+		.check = test__checkevent_symbolic_name_modifier,
+	},
+	{
+		.name  = "faults:u",
+		.check = test__checkevent_symbolic_alias_modifier,
+	},
+	{
+		.name  = "L1-dcache-load-miss:kp",
+		.check = test__checkevent_genhw_modifier,
+	},
+	{
+		.name  = "mem:0:u",
+		.check = test__checkevent_breakpoint_modifier,
+	},
+	{
+		.name  = "mem:0:x:k",
+		.check = test__checkevent_breakpoint_x_modifier,
+	},
+	{
+		.name  = "mem:0:r:hp",
+		.check = test__checkevent_breakpoint_r_modifier,
+	},
+	{
+		.name  = "mem:0:w:up",
+		.check = test__checkevent_breakpoint_w_modifier,
+	},
+	{
+		.name  = "r1,syscalls:sys_enter_open:k,1:1:hp",
+		.check = test__checkevent_list,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
Signature · 1 line
1.7.4
#89 lore raw

Re: [PATCH 3/3] perf, tool: Add more automated tests for event parsing

Em Thu, Dec 15, 2011 at 04:30:39PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Adding automated tests for event parsing to include testing for modifier, ',' operator and group_leader.

Aha! Brownie points hereby granted, good stuff,

- Arnaldo

Quoted 277 lines
---
 tools/perf/builtin-test.c |  245 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 244 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +244 -1
index 6173f78..0cdb4c9 100644
@@ -603,7 +603,7 @@ out_free_threads:
 
 #define TEST_ASSERT_VAL(text, cond) \
 do { \
-	if (!cond) { \
+	if (!(cond)) { \
 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
 		return -1; \
 	} \
@@ -759,6 +759,201 @@ static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_tracepoint(evlist);
+}
+
+static int
+test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		TEST_ASSERT_VAL("wrong exclude_user",
+				!evsel->attr.exclude_user);
+		TEST_ASSERT_VAL("wrong exclude_kernel",
+				evsel->attr.exclude_kernel);
+		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	}
+
+	return test__checkevent_tracepoint_multi(evlist);
+}
+
+static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_raw(evlist);
+}
+
+static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_numeric(evlist);
+}
+
+static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_alias(evlist);
+}
+
+static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_genhw(evlist);
+}
+
+static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint(evlist);
+}
+
+static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_x(evlist);
+}
+
+static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_r(evlist);
+}
+
+static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_breakpoint_w(evlist);
+}
+
+static int test__checkevent_list(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+	struct perf_evsel *group_leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* r1 */
+	evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
+	group_leader = evsel;
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader", !evsel->group_leader);
+
+	/* syscalls:sys_enter_open:k */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong sample_type",
+		(PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
+		evsel->attr.sample_type);
+	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader",
+			evsel->group_leader == group_leader);
+
+	/* 1:1:hp */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong group_leader",
+			evsel->group_leader == group_leader);
+
+	return 0;
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -808,6 +1003,54 @@ static struct test__event_st {
 		.name  = "mem:0:w",
 		.check = test__checkevent_breakpoint_w,
 	},
+	{
+		.name  = "syscalls:sys_enter_open:k",
+		.check = test__checkevent_tracepoint_modifier,
+	},
+	{
+		.name  = "syscalls:*:u",
+		.check = test__checkevent_tracepoint_multi_modifier,
+	},
+	{
+		.name  = "r1:kp",
+		.check = test__checkevent_raw_modifier,
+	},
+	{
+		.name  = "1:1:hp",
+		.check = test__checkevent_numeric_modifier,
+	},
+	{
+		.name  = "instructions:h",
+		.check = test__checkevent_symbolic_name_modifier,
+	},
+	{
+		.name  = "faults:u",
+		.check = test__checkevent_symbolic_alias_modifier,
+	},
+	{
+		.name  = "L1-dcache-load-miss:kp",
+		.check = test__checkevent_genhw_modifier,
+	},
+	{
+		.name  = "mem:0:u",
+		.check = test__checkevent_breakpoint_modifier,
+	},
+	{
+		.name  = "mem:0:x:k",
+		.check = test__checkevent_breakpoint_x_modifier,
+	},
+	{
+		.name  = "mem:0:r:hp",
+		.check = test__checkevent_breakpoint_r_modifier,
+	},
+	{
+		.name  = "mem:0:w:up",
+		.check = test__checkevent_breakpoint_w_modifier,
+	},
+	{
+		.name  = "r1,syscalls:sys_enter_open:k,1:1:hp",
+		.check = test__checkevent_list,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
Signature · 1 line
1.7.4
#90 lore raw

[tip:perf/core] perf test: Add more automated tests for event parsing

In reply to Jiri Olsa
Commit-ID:  65c1e0452a3389f9b7b8c1b23305ed2922fafb2d
Gitweb:     http://git.kernel.org/tip/65c1e0452a3389f9b7b8c1b23305ed2922fafb2d
Author:     Jiri Olsa <[email protected]>
AuthorDate: Thu, 15 Dec 2011 16:30:39 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 20 Dec 2011 14:46:14 -0200

perf test: Add more automated tests for event parsing

Adding automated tests for event parsing to include testing for modifier and ',' operator.

Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ committer note: Remove some tests that need group_leader & bison patchkits ]
---
 tools/perf/builtin-test.c |  127 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 126 insertions(+), 1 deletions(-)
tools/perf/builtin-test.c +126 -1
index 6173f78..2b9a7f4 100644
@@ -603,7 +603,7 @@ out_free_threads:
 
 #define TEST_ASSERT_VAL(text, cond) \
 do { \
-	if (!cond) { \
+	if (!(cond)) { \
 		pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
 		return -1; \
 	} \
@@ -759,6 +759,103 @@ static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_tracepoint(evlist);
+}
+
+static int
+test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		TEST_ASSERT_VAL("wrong exclude_user",
+				!evsel->attr.exclude_user);
+		TEST_ASSERT_VAL("wrong exclude_kernel",
+				evsel->attr.exclude_kernel);
+		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	}
+
+	return test__checkevent_tracepoint_multi(evlist);
+}
+
+static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_raw(evlist);
+}
+
+static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_numeric(evlist);
+}
+
+static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_name(evlist);
+}
+
+static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+
+	return test__checkevent_symbolic_alias(evlist);
+}
+
+static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = list_entry(evlist->entries.next,
+					      struct perf_evsel, node);
+
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
+
+	return test__checkevent_genhw(evlist);
+}
+
 static struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -808,6 +905,34 @@ static struct test__event_st {
 		.name  = "mem:0:w",
 		.check = test__checkevent_breakpoint_w,
 	},
+	{
+		.name  = "syscalls:sys_enter_open:k",
+		.check = test__checkevent_tracepoint_modifier,
+	},
+	{
+		.name  = "syscalls:*:u",
+		.check = test__checkevent_tracepoint_multi_modifier,
+	},
+	{
+		.name  = "r1:kp",
+		.check = test__checkevent_raw_modifier,
+	},
+	{
+		.name  = "1:1:hp",
+		.check = test__checkevent_numeric_modifier,
+	},
+	{
+		.name  = "instructions:h",
+		.check = test__checkevent_symbolic_name_modifier,
+	},
+	{
+		.name  = "faults:u",
+		.check = test__checkevent_symbolic_alias_modifier,
+	},
+	{
+		.name  = "L1-dcache-load-miss:kp",
+		.check = test__checkevent_genhw_modifier,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))