perf, tool: Allow to use hw events in PMU syntax
Subsystems (2)
v4 cover perf, tool: Allow to use hw events in PMU syntax
hi,
here's the change to make following syntax available:
perf stat -e cpu/event=instructions/u ls perf stat -e cpu/cycles/u ls
this is identical to:
perf stat -e instructions:u ls
perf stat -e cycles:u ls
v4 changes:
- kernel change is now structured differently allowing to pick up cpu differences
- added support for intel/p6/amd PMUs - intel and amd tested, did not get p6 server, but should be ok.. feel free to omit
Attached patches:
1/8 perf x86: Making hardware events translations available in sysfs 2/8 perf x86: Filter out undefined events from sysfs events attribute 3/8 perf x86: Adding hardware events translations for intel cpus 4/8 perf x86: Adding hardware events translations for amd cpus 5/8 perf x86: Adding hardware events translations for p6 cpus 6/8 perf tools: Fix pmu object alias initialization
7/8 perf tools: Add support to specify hw event as pmu event term 8/8 perf test: Add automated tests for pmu sysfs translated events
jirka
--- arch/x86/kernel/cpu/perf_event.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 ++ arch/x86/kernel/cpu/perf_event_amd.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_intel.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_p6.c | 2 ++ include/linux/perf_event.h | 3 +++ tools/perf/util/parse-events-test.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 18 ++++++++++++++ tools/perf/util/parse-events.h | 2 ++ tools/perf/util/parse-events.y | 18 ++++++++++++++ tools/perf/util/pmu.c | 7 +++--- 11 files changed, 256 insertions(+), 3 deletions(-)
PATCH v4 4/8 perf x86: Adding hardware events translations for amd cpus
Adding support for amd processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations.
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event.c | 3 +-- arch/x86/kernel/cpu/perf_event_amd.c | 9 +++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 11 +++++++++-- include/linux/perf_event.h | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event.c +1 -2
@@ -1384,9 +1384,8 @@ static struct attribute_group x86_pmu_events_group = { .attrs = events_attr, }; -ssize_t x86_event_sysfs_show (char *page,u64 config) +ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event) { -u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT );u64 umask = (config &ARCH_PERFMON_EVENTSEL_UMASK ) >>8 ;u64 cmask = (config &ARCH_PERFMON_EVENTSEL_CMASK ) >>24 ;bool edge = (config &ARCH_PERFMON_EVENTSEL_EDGE );
arch/x86/kernel/cpu/perf_event_amd.c +9 -0
@@ -568,6 +568,14 @@ amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *ev } } +static ssize_t amd_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ) | + (config &AMD64_EVENTSEL_EVENT ) >>24 ; + +return x86_event_sysfs_show (page, config, event); +} +static __initconst const struct x86_pmu amd_pmu = { .name ="AMD" , .handle_irq = x86_pmu_handle_irq,
@@ -591,6 +599,7 @@ static __initconst const struct x86_pmu amd_pmu = { .put_event_constraints = amd_put_event_constraints, .format_attrs = amd_format_attr, + .events_sysfs_show = amd_event_sysfs_show, .cpu_prepare = amd_pmu_cpu_prepare, .cpu_starting = amd_pmu_cpu_starting,
arch/x86/kernel/cpu/perf_event_intel.c +9 -2
@@ -1603,6 +1603,13 @@ static struct attribute *intel_arch_formats_attr[] = { NULL, }; +ssize_t intel_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ); + +return x86_event_sysfs_show (page, config, event); +} +static __initconst const struct x86_pmu core_pmu = { .name ="core" , .handle_irq = x86_pmu_handle_irq,
@@ -1628,7 +1635,7 @@ static __initconst const struct x86_pmu core_pmu = { .event_constraints = intel_core_event_constraints, .guest_get_msrs = core_guest_get_msrs, .format_attrs = intel_arch_formats_attr, - .events_sysfs_show = x86_event_sysfs_show, + .events_sysfs_show = intel_event_sysfs_show, };struct intel_shared_regs *allocate_shared_regs (int cpu)
@@ -1767,7 +1774,7 @@ static __initconst const struct x86_pmu intel_pmu = { .pebs_aliases = intel_pebs_aliases_core2, .format_attrs = intel_arch3_formats_attr, - .events_sysfs_show = x86_event_sysfs_show, + .events_sysfs_show = intel_event_sysfs_show, .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting,
include/linux/perf_event.h +1 -1
@@ -1418,7 +1418,7 @@ _name##_show(struct device *dev, \ \ static struct device_attribute format_attr_##_name = __ATTR_RO(_name) -ssize_t x86_event_sysfs_show (char *page,u64 config); +ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event);#endif /* __KERNEL__ */ #endif /* _LINUX_PERF_EVENT_H */
Signature · 1 line
1.7.11.4
PATCH v4 6/8 perf tools: Fix pmu object alias initialization
In reply to Jiri OlsaThe pmu_lookup should return pmus that do not expose the 'events' group attribute in sysfs. Also it should fail when any other error during 'events' lookup is hit (pmu_aliases fails).
--- tools/perf/util/pmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/pmu.c +4 -3
@@ -164,7 +164,7 @@ static int pmu_aliases(char *name, struct list_head *head) "%s/bus/event_source/devices/%s/events", sysfs, name);if (stat (path, &st) <0 ) -return -1 ; +return 0 ;/* no error if 'events' does not exist */ if (pmu_aliases_parse (path, head))return -1 ;
@@ -296,6 +296,9 @@ static struct perf_pmu *pmu_lookup(char *name)if (pmu_format (name, &format))return NULL ; +if (pmu_aliases (name, &aliases)) +return NULL ; +if (pmu_type (name, &type))return NULL ;
@@ -305,8 +308,6 @@ static struct perf_pmu *pmu_lookup(char *name) pmu->cpus =pmu_cpumask (name); -pmu_aliases (name, &aliases); -INIT_LIST_HEAD (&pmu->format);INIT_LIST_HEAD (&pmu->aliases);list_splice (&format, &pmu->format);
Signature · 1 line
1.7.11.4
PATCH v4 7/8 perf tools: Add support to specify hw event as pmu event term
In reply to Jiri OlsaAdding a way to specify hw event as pmu event term like:
'cpu/event=cpu-cycles/u' 'cpu/event=instructions,.../u' 'cpu/cycles,.../u'
The 'event=cpu-cycles' term is replaced/translated by the hw events term translation, which is exposed by sysfs 'events' group attribute.
Adding parser bits, the rest is already handled by the pmu alias code.
--- tools/perf/util/parse-events.c | 18 ++++++++++++++++++ tools/perf/util/parse-events.h | 2 ++ tools/perf/util/parse-events.y | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+)
tools/perf/util/parse-events.c +18 -0
@@ -1139,6 +1139,24 @@ int parse_events__term_str(struct parse_events__term **term, config, str, 0); } +int parse_events__term_sym_hw (struct parse_events__term **term, +char *config,unsigned idx) +{ +struct event_symbol *sym; + +BUG_ON (idx >=PERF_COUNT_HW_MAX ); + sym = &event_symbols_hw[idx]; + +if (config) +return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , +PARSE_EVENTS__TERM_TYPE_USER , config, + (char *) sym->symbol,0 ); +else +return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , +PARSE_EVENTS__TERM_TYPE_USER , + (char *)"event" , (char *) sym->symbol,0 ); +} +int parse_events__term_clone (struct parse_events__term **new,struct parse_events__term *term) {
tools/perf/util/parse-events.h +2 -0
@@ -76,6 +76,8 @@ int parse_events__term_num(struct parse_events__term **_term, int type_term, char *config, u64 num);int parse_events__term_str (struct parse_events__term **_term,int type_term,char *config,char *str); +int parse_events__term_sym_hw (struct parse_events__term **term, +char *config,unsigned idx);int parse_events__term_clone (struct parse_events__term **new,struct parse_events__term *term);void parse_events__free_terms (struct list_head *terms);
tools/perf/util/parse-events.y +18 -0
@@ -352,6 +352,15 @@ PE_NAME '=' PE_VALUE $$ = term; } | +PE_NAME '=' PE_VALUE_SYM_HW +{ + struct parse_events__term *term; + int config = $3 & 255; + + ABORT_ON(parse_events__term_sym_hw(&term, $1, config)); + $$ = term; +} +| PE_NAME { struct parse_events__term *term;
@@ -361,6 +370,15 @@ PE_NAME $$ = term; } | +PE_VALUE_SYM_HW +{ + struct parse_events__term *term; + int config = $1 & 255; + + ABORT_ON(parse_events__term_sym_hw(&term, NULL, config)); + $$ = term; +} +| PE_TERM '=' PE_NAME { struct parse_events__term *term;
Signature · 1 line
1.7.11.4
PATCH v4 8/8 perf test: Add automated tests for pmu sysfs translated events
In reply to Jiri OlsaAdding automated tests for all events found under PMU/events directory. Tested events are in 'cpu/event=xxx/u' format, where 'xxx' is substituted by every event found.
The 'event=xxx' term is translated to the cpu specific term. We only check that the event is created (not the real config numbers) and that modifier is properly set.
--- tools/perf/util/parse-events-test.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
tools/perf/util/parse-events-test.c +68 -0
@@ -443,6 +443,23 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)return 0 ; } +static int test__checkevent_pmu_events (struct perf_evlist *evlist) +{ +struct perf_evsel *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 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 int test__checkterms_simple (struct list_head *terms) {struct parse_events__term *term;
@@ -1020,6 +1037,51 @@ static int test_pmu(void)return !ret; } +static int test_pmu_events (void ) +{ +struct stat st; +char path[PATH_MAX ]; +struct dirent *ent; +DIR *dir; +int ret; + +snprintf (path,PATH_MAX ,"%s/bus/event_source/devices/cpu/events/" , +sysfs_find_mountpoint ()); + + ret =stat (path, &st); +if (ret) { +pr_debug ("ommiting PMU cpu events tests\n" ); +return 0 ; + } + + dir =opendir (path); +if (!dir) { +pr_debug ("can't open pmu event dir" ); +return -1 ; + } + +while (!ret && (ent =readdir (dir))) { +#define MAX_NAME 100 +struct test__event_st e; +char name[MAX_NAME ]; + +if (!strcmp (ent->d_name,"." ) || + !strcmp (ent->d_name,".." )) +continue ; + +snprintf (name,MAX_NAME ,"cpu/event=%s/u" , ent->d_name); + + e.name = name; + e.check = test__checkevent_pmu_events; + + ret =test_event (&e); +#undef MAX_NAME + } + +closedir (dir); +return ret; +} +int parse_events__test (void ) {int ret1, ret2 =0 ;
@@ -1036,6 +1098,12 @@ do { \if (test_pmu ())TEST_EVENTS (test__events_pmu); +if (test_pmu ()) { +int ret =test_pmu_events (); +if (ret) +return ret; + } + ret1 =test_terms (test__terms,ARRAY_SIZE (test__terms));if (!ret2) ret2 = ret1;
Signature · 1 line
1.7.11.4
PATCH v4 5/8 perf x86: Adding hardware events translations for p6 cpus
In reply to Jiri OlsaAdding support for p6 processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations.
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event_p6.c | 2 ++ include/linux/perf_event.h | 1 + 2 files changed, 3 insertions(+)
arch/x86/kernel/cpu/perf_event_p6.c +2 -0
@@ -134,6 +134,8 @@ static __initconst const struct x86_pmu p6_pmu = { .event_constraints = p6_event_constraints, .format_attrs = intel_p6_formats_attr, + .events_sysfs_show = intel_event_sysfs_show, + };__init int p6_pmu_init (void )
include/linux/perf_event.h +1 -0
@@ -1419,6 +1419,7 @@ _name##_show(struct device *dev, \ static struct device_attribute format_attr_##_name = __ATTR_RO(_name)ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event); +ssize_t intel_event_sysfs_show (char *page,u64 config);#endif /* __KERNEL__ */ #endif /* _LINUX_PERF_EVENT_H */
Signature · 1 line
1.7.11.4
PATCH v4 3/8 perf x86: Adding hardware events translations for intel cpus
In reply to Jiri OlsaAdding support for intel processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations.
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event.c | 40 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 2 ++ include/linux/perf_event.h | 2 ++ 3 files changed, 44 insertions(+)
arch/x86/kernel/cpu/perf_event.c +40 -0
@@ -1384,6 +1384,46 @@ static struct attribute_group x86_pmu_events_group = { .attrs = events_attr, }; +ssize_t x86_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ); +u64 umask = (config &ARCH_PERFMON_EVENTSEL_UMASK ) >>8 ; +u64 cmask = (config &ARCH_PERFMON_EVENTSEL_CMASK ) >>24 ; +bool edge = (config &ARCH_PERFMON_EVENTSEL_EDGE ); +bool pc = (config &ARCH_PERFMON_EVENTSEL_PIN_CONTROL ); +bool any = (config &ARCH_PERFMON_EVENTSEL_ANY ); +bool inv = (config &ARCH_PERFMON_EVENTSEL_INV ); +ssize_t ret; + +/* +* We have whole page size to spend and just little data +* to write, so we can safely use sprintf. +*/ + ret =sprintf (page,"event=0x%02llx" , event); + +if (umask) + ret +=sprintf (page + ret,",umask=0x%02llx" , umask); + +if (edge) + ret +=sprintf (page + ret,",edge" ); + +if (pc) + ret +=sprintf (page + ret,",pc" ); + +if (any) + ret +=sprintf (page + ret,",any" ); + +if (inv) + ret +=sprintf (page + ret,",inv" ); + +if (cmask) + ret +=sprintf (page + ret,",cmask=0x%02llx" , cmask); + + ret +=sprintf (page + ret,"\n" ); + +return ret; +} +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
arch/x86/kernel/cpu/perf_event_intel.c +2 -0
@@ -1628,6 +1628,7 @@ static __initconst const struct x86_pmu core_pmu = { .event_constraints = intel_core_event_constraints, .guest_get_msrs = core_guest_get_msrs, .format_attrs = intel_arch_formats_attr, + .events_sysfs_show = x86_event_sysfs_show, };struct intel_shared_regs *allocate_shared_regs (int cpu)
@@ -1766,6 +1767,7 @@ static __initconst const struct x86_pmu intel_pmu = { .pebs_aliases = intel_pebs_aliases_core2, .format_attrs = intel_arch3_formats_attr, + .events_sysfs_show = x86_event_sysfs_show, .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting,
include/linux/perf_event.h +2 -0
@@ -1418,5 +1418,7 @@ _name##_show(struct device *dev, \ \ static struct device_attribute format_attr_##_name = __ATTR_RO(_name) +ssize_t x86_event_sysfs_show (char *page,u64 config); +#endif /* __KERNEL__ */ #endif /* _LINUX_PERF_EVENT_H */
Signature · 1 line
1.7.11.4
PATCH v4 1/8 perf x86: Making hardware events translations available in sysfs
In reply to Jiri OlsaAdding support to display hardware events translations available through the sysfs. Adding 'events' group attribute under the sysfs x86 PMU record with attribute/file for each hardware event.
This patch adds only backbone for PMUs to display config under 'events' directory. The specific PMU support itself will come in next patches, however this is how the sysfs group will look like:
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
The file - hw event ID mappings is:
file hw event ID
---------------------------------------------------------------
cpu-cycles PERF_COUNT_HW_CPU_CYCLES instructions PERF_COUNT_HW_INSTRUCTIONS cache-references PERF_COUNT_HW_CACHE_REFERENCES cache-misses PERF_COUNT_HW_CACHE_MISSES branch-instructions PERF_COUNT_HW_BRANCH_INSTRUCTIONS branch-misses PERF_COUNT_HW_BRANCH_MISSES bus-cycles PERF_COUNT_HW_BUS_CYCLES stalled-cycles-frontend PERF_COUNT_HW_STALLED_CYCLES_FRONTEND stalled-cycles-backend PERF_COUNT_HW_STALLED_CYCLES_BACKEND ref-cycles PERF_COUNT_HW_REF_CPU_CYCLES
Each file in 'events' directory contains term translation for the symbolic hw event for the currently running cpu model.
# cat /sys/devices/cpu/events/stalled-cycles-backend event=0xb1,umask=0x01,inv,cmask=0x01
--- arch/x86/kernel/cpu/perf_event.c | 60 ++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 ++ 2 files changed, 62 insertions(+)
arch/x86/kernel/cpu/perf_event.c +60 -0
@@ -1308,6 +1308,62 @@ static struct attribute_group x86_pmu_format_group = { .attrs = NULL, }; +struct perf_pmu_events_attr { +struct device_attribute attr; +u64 id; +}; + +ssize_t events_sysfs_show (struct device *dev,struct device_attribute *attr, +char *page) +{ +struct perf_pmu_events_attr *pmu_attr = \ + container_of(attr, struct perf_pmu_events_attr, attr); + +u64 config = x86_pmu.event_map (pmu_attr->id); +return x86_pmu.events_sysfs_show (page, config); +} + +#define EVENT_VAR (_id) event_attr_##_id +#define EVENT_PTR (_id) &event_attr_##_id.attr.attr + +#define EVENT_ATTR (_name, _id) \ +static struct perf_pmu_events_attr EVENT_VAR(_id) = { \ + .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ + .id = PERF_COUNT_HW_##_id, \ +}; + +EVENT_ATTR (cpu-cycles,CPU_CYCLES ); +EVENT_ATTR (instructions,INSTRUCTIONS ); +EVENT_ATTR (cache-references,CACHE_REFERENCES ); +EVENT_ATTR (cache-misses,CACHE_MISSES ); +EVENT_ATTR (branch-instructions,BRANCH_INSTRUCTIONS ); +EVENT_ATTR (branch-misses,BRANCH_MISSES ); +EVENT_ATTR (bus-cycles,BUS_CYCLES ); +EVENT_ATTR (stalled-cycles-frontend,STALLED_CYCLES_FRONTEND ); +EVENT_ATTR (stalled-cycles-backend,STALLED_CYCLES_BACKEND ); +EVENT_ATTR (ref-cycles,REF_CPU_CYCLES ); + +static struct attribute *empty_attrs; + +struct attribute *events_attr[] = { +EVENT_PTR (CPU_CYCLES ), +EVENT_PTR (INSTRUCTIONS ), +EVENT_PTR (CACHE_REFERENCES ), +EVENT_PTR (CACHE_MISSES ), +EVENT_PTR (BRANCH_INSTRUCTIONS ), +EVENT_PTR (BRANCH_MISSES ), +EVENT_PTR (BUS_CYCLES ), +EVENT_PTR (STALLED_CYCLES_FRONTEND ), +EVENT_PTR (STALLED_CYCLES_BACKEND ), +EVENT_PTR (REF_CPU_CYCLES ), +NULL , +}; + +static struct attribute_group x86_pmu_events_group = { + .name ="events" , + .attrs = events_attr, +}; +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
@@ -1354,6 +1410,9 @@ static int __init init_hw_perf_events(void) x86_pmu.attr_rdpmc =1 ;/* enable userspace RDPMC usage by default */ x86_pmu_format_group.attrs = x86_pmu.format_attrs; +if (!x86_pmu.events_sysfs_show) + x86_pmu_events_group.attrs = &empty_attrs; +pr_info ("... version: %d\n" , x86_pmu.version);pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits);pr_info ("... generic registers: %d\n" , x86_pmu.num_counters);
@@ -1643,6 +1702,7 @@ static struct attribute_group x86_pmu_attr_group = {static const struct attribute_group *x86_pmu_attr_groups[] = { &x86_pmu_attr_group, &x86_pmu_format_group, + &x86_pmu_events_group,NULL , };
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -354,6 +354,8 @@ struct x86_pmu {int attr_rdpmc;struct attribute **format_attrs; +ssize_t (*events_sysfs_show)(char *page,u64 config); +/* * CPU Hotplug hooks */
Signature · 1 line
1.7.11.4
PATCH v4 2/8 perf x86: Filter out undefined events from sysfs events attribute
In reply to Jiri OlsaThe sysfs events group attribute currently shows all hw events, including also undefined ones.
This patch filters out all undefined events out of the sysfs events group attribute, so they don't even show up.
--- arch/x86/kernel/cpu/perf_event.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/x86/kernel/cpu/perf_event.c +22 -0
@@ -1313,6 +1313,26 @@ struct perf_pmu_events_attr {u64 id; }; +/* +* Remove all undefined events (x86_pmu.event_map(id) == 0) +* out of events_attr attributes. +*/ +static void __init filter_events (struct attribute **attrs) +{ +int i, j; + +for (i =0 ; attrs[i]; i++) { +if (x86_pmu.event_map (i)) +continue ; + +for (j = i; attrs[j]; j++) + attrs[j] = attrs[j +1 ]; + +/* Check the shifted attr. */ + i--; + } +} +ssize_t events_sysfs_show (struct device *dev,struct device_attribute *attr,char *page) {
@@ -1412,6 +1432,8 @@ static int __init init_hw_perf_events(void)if (!x86_pmu.events_sysfs_show) x86_pmu_events_group.attrs = &empty_attrs; +else +filter_events (x86_pmu_events_group.attrs);pr_info ("... version: %d\n" , x86_pmu.version);pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits);
Signature · 1 line
1.7.11.4
Quoted 5 lines · Jiri Olsa
hi,
here's the change to make following syntax available:
perf stat -e cpu/event=instructions/u ls perf stat -e cpu/cycles/u ls
Unless, I am mistaken but I did not see in your patch where you adjust the list of generic Hw events (and encodings) you expose via sysfs based on CPU model number. Some generic HW PMU may not have actual physical mappings. Look at IvyBridge, for instance.
Quoted 44 lines
this is identical to:
perf stat -e instructions:u ls
perf stat -e cycles:u lsv4 changes:
- kernel change is now structured differently allowing to pick up cpu differences
- added support for intel/p6/amd PMUs - intel and amd tested, did not get p6 server, but should be ok.. feel free to omitAttached patches:
1/8 perf x86: Making hardware events translations available in sysfs 2/8 perf x86: Filter out undefined events from sysfs events attribute 3/8 perf x86: Adding hardware events translations for intel cpus 4/8 perf x86: Adding hardware events translations for amd cpus 5/8 perf x86: Adding hardware events translations for p6 cpus 6/8 perf tools: Fix pmu object alias initialization
7/8 perf tools: Add support to specify hw event as pmu event term 8/8 perf test: Add automated tests for pmu sysfs translated eventsjirka
Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Jiri Olsa <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Ingo Molnar <[email protected]>Cc Paul Mackerras <[email protected]>Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Stephane Eranian <[email protected]>--- arch/x86/kernel/cpu/perf_event.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 ++ arch/x86/kernel/cpu/perf_event_amd.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_intel.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_p6.c | 2 ++ include/linux/perf_event.h | 3 +++ tools/perf/util/parse-events-test.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 18 ++++++++++++++ tools/perf/util/parse-events.h | 2 ++ tools/perf/util/parse-events.y | 18 ++++++++++++++ tools/perf/util/pmu.c | 7 +++--- 11 files changed, 256 insertions(+), 3 deletions(-)
Quoted 10 lines · Stephane Eranian
Quoted 5 lines · Jiri Olsa
hi,
here's the change to make following syntax available:
perf stat -e cpu/event=instructions/u ls perf stat -e cpu/cycles/u lsUnless, I am mistaken but I did not see in your patch where you adjust the list of generic Hw events (and encodings) you expose via sysfs based on CPU model number. Some generic HW PMU may not have actual physical mappings. Look at IvyBridge, for instance.
hm, path 2 remove any attribute that is not defined via x86_pmu.event_map, if that's what you mean..
jirka
Quoted 7 lines · Jiri Olsa
Quoted 6 lines · Stephane Eranian
Quoted 5 lines · Jiri Olsa
hi,
here's the change to make following syntax available:
perf stat -e cpu/event=instructions/u ls perf stat -e cpu/cycles/u ls
Quoted 8 lines
Quoted 4 lines
Unless, I am mistaken but I did not see in your patch where you adjust the list of generic Hw events (and encodings) you expose via sysfs based on CPU model number. Some generic HW PMU may not have actual physical mappings. Look at IvyBridge, for instance.
hm, path 2 remove any attribute that is not defined via x86_pmu.event_map, if that's what you mean..
Ok, you're right, so this should be okay then.
Thanks.
Quoted 1 line
jirka
Re: [PATCH 4/8] perf x86: Adding hardware events translations for amd cpus
In reply to Jiri Olsaarch/x86/kernel/cpu/perf_event_amd.c amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *ev · line 577
Quoted 7 lines · Jiri Olsa
arch/x86/kernel/cpu/perf_event_amd.c +7
-0+static ssize_t amd_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ) | + (config &AMD64_EVENTSEL_EVENT ) >>24 ; + +return x86_event_sysfs_show (page, config, event); +}
You'll need to filter out 0xF<<32 bits before passing them on in @config, Intel has a different meaning for them.
Re: [PATCH 4/8] perf x86: Adding hardware events translations for amd cpus
Quoted 11 lines · Peter Zijlstra
arch/x86/kernel/cpu/perf_event_amd.c amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *ev · line 577
Quoted 7 lines · Jiri Olsa
arch/x86/kernel/cpu/perf_event_amd.c +7
-0+static ssize_t amd_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ) | + (config &AMD64_EVENTSEL_EVENT ) >>24 ; + +return x86_event_sysfs_show (page, config, event); +}You'll need to filter out 0xF<<32 bits before passing them on in @config, Intel has a different meaning for them.
Right, that would be those 'intx and intx_cp' bits we discussed, right?
My thinking was to customize this once those bits are introduced and part of the format stuff. Until that time the x86_event_sysfs_show function shows proper data for both amd and intel. Or is it already on its way in?
jirka
Re: [PATCH 4/8] perf x86: Adding hardware events translations for amd cpus
Quoted 13 lines · Jiri Olsa
Quoted 11 lines · Peter Zijlstra
arch/x86/kernel/cpu/perf_event_amd.c amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *ev · line 577
Quoted 7 lines · Jiri Olsa
arch/x86/kernel/cpu/perf_event_amd.c +7
-0+static ssize_t amd_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ) | + (config &AMD64_EVENTSEL_EVENT ) >>24 ; + +return x86_event_sysfs_show (page, config, event); +}You'll need to filter out 0xF<<32 bits before passing them on in @config, Intel has a different meaning for them.
Quoted 1 line
Right, that would be those 'intx and
intx_cp' bits we discussed, right?
Right.
Quoted 4 lines
My thinking was to customize this once those bits are introduced and part of the format stuff. Until that time the
x86_event_sysfs_showfunction shows proper data for both amd and intel. Or is it already on its way in?
No thats fine, just something we shouldn't forget about. They're in Andi Kleen's HSW patches, I need to go over the v2 of that.
Quoted 7 lines · Jiri Olsa
arch/x86/kernel/cpu/perf_event.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 ++ arch/x86/kernel/cpu/perf_event_amd.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_intel.c | 9 +++++++ arch/x86/kernel/cpu/perf_event_p6.c | 2 ++ include/linux/perf_event.h | 3 +++
These bits look like they want to live in arch/x86/kernel/cpu/perf_event.h, they're rather x86 specific. I moved them over.
Quoted 7 lines
tools/perf/util/parse-events-test.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 18 ++++++++++++++ tools/perf/util/parse-events.h | 2 ++ tools/perf/util/parse-events.y | 18 ++++++++++++++ tools/perf/util/pmu.c | 7 +++--- 11 files changed, 256 insertions(+), 3 deletions(-)
Acme, you ok with these bits?
[tip:perf/core] perf/x86: Make hardware event translations available in sysfs
In reply to Jiri OlsaCommit-ID: a47473939db20e3961b200eb00acf5fcf084d755 Gitweb: http://git.kernel.org/tip/a47473939db20e3961b200eb00acf5fcf084d755 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:11 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:23 +0200
perf/x86: Make hardware event translations available in sysfs
Add support to display hardware events translations available through the sysfs. Add 'events' group attribute under the sysfs x86 PMU record with attribute/file for each hardware event.
This patch adds only backbone for PMUs to display config under 'events' directory. The specific PMU support itself will come in next patches, however this is how the sysfs group will look like:
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
The file - hw event ID mapping is:
file hw event ID
---------------------------------------------------------------
cpu-cycles PERF_COUNT_HW_CPU_CYCLES instructions PERF_COUNT_HW_INSTRUCTIONS cache-references PERF_COUNT_HW_CACHE_REFERENCES cache-misses PERF_COUNT_HW_CACHE_MISSES branch-instructions PERF_COUNT_HW_BRANCH_INSTRUCTIONS branch-misses PERF_COUNT_HW_BRANCH_MISSES bus-cycles PERF_COUNT_HW_BUS_CYCLES stalled-cycles-frontend PERF_COUNT_HW_STALLED_CYCLES_FRONTEND stalled-cycles-backend PERF_COUNT_HW_STALLED_CYCLES_BACKEND ref-cycles PERF_COUNT_HW_REF_CPU_CYCLES
Each file in the 'events' directory contains the term translation for the symbolic hw event for the currently running cpu model.
# cat /sys/devices/cpu/events/stalled-cycles-backend event=0xb1,umask=0x01,inv,cmask=0x01
--- arch/x86/kernel/cpu/perf_event.c | 60 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 + 2 files changed, 62 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_event.c +60 -0
@@ -1316,6 +1316,62 @@ static struct attribute_group x86_pmu_format_group = { .attrs = NULL, }; +struct perf_pmu_events_attr { +struct device_attribute attr; +u64 id; +}; + +ssize_t events_sysfs_show (struct device *dev,struct device_attribute *attr, +char *page) +{ +struct perf_pmu_events_attr *pmu_attr = \ + container_of(attr, struct perf_pmu_events_attr, attr); + +u64 config = x86_pmu.event_map (pmu_attr->id); +return x86_pmu.events_sysfs_show (page, config); +} + +#define EVENT_VAR (_id) event_attr_##_id +#define EVENT_PTR (_id) &event_attr_##_id.attr.attr + +#define EVENT_ATTR (_name, _id) \ +static struct perf_pmu_events_attr EVENT_VAR(_id) = { \ + .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ + .id = PERF_COUNT_HW_##_id, \ +}; + +EVENT_ATTR (cpu-cycles,CPU_CYCLES ); +EVENT_ATTR (instructions,INSTRUCTIONS ); +EVENT_ATTR (cache-references,CACHE_REFERENCES ); +EVENT_ATTR (cache-misses,CACHE_MISSES ); +EVENT_ATTR (branch-instructions,BRANCH_INSTRUCTIONS ); +EVENT_ATTR (branch-misses,BRANCH_MISSES ); +EVENT_ATTR (bus-cycles,BUS_CYCLES ); +EVENT_ATTR (stalled-cycles-frontend,STALLED_CYCLES_FRONTEND ); +EVENT_ATTR (stalled-cycles-backend,STALLED_CYCLES_BACKEND ); +EVENT_ATTR (ref-cycles,REF_CPU_CYCLES ); + +static struct attribute *empty_attrs; + +struct attribute *events_attr[] = { +EVENT_PTR (CPU_CYCLES ), +EVENT_PTR (INSTRUCTIONS ), +EVENT_PTR (CACHE_REFERENCES ), +EVENT_PTR (CACHE_MISSES ), +EVENT_PTR (BRANCH_INSTRUCTIONS ), +EVENT_PTR (BRANCH_MISSES ), +EVENT_PTR (BUS_CYCLES ), +EVENT_PTR (STALLED_CYCLES_FRONTEND ), +EVENT_PTR (STALLED_CYCLES_BACKEND ), +EVENT_PTR (REF_CPU_CYCLES ), +NULL , +}; + +static struct attribute_group x86_pmu_events_group = { + .name ="events" , + .attrs = events_attr, +}; +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
@@ -1362,6 +1418,9 @@ static int __init init_hw_perf_events(void) x86_pmu.attr_rdpmc =1 ;/* enable userspace RDPMC usage by default */ x86_pmu_format_group.attrs = x86_pmu.format_attrs; +if (!x86_pmu.events_sysfs_show) + x86_pmu_events_group.attrs = &empty_attrs; +pr_info ("... version: %d\n" , x86_pmu.version);pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits);pr_info ("... generic registers: %d\n" , x86_pmu.num_counters);
@@ -1651,6 +1710,7 @@ static struct attribute_group x86_pmu_attr_group = {static const struct attribute_group *x86_pmu_attr_groups[] = { &x86_pmu_attr_group, &x86_pmu_format_group, + &x86_pmu_events_group,NULL , };
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -354,6 +354,8 @@ struct x86_pmu {int attr_rdpmc;struct attribute **format_attrs; +ssize_t (*events_sysfs_show)(char *page,u64 config); +/* * CPU Hotplug hooks */
[tip:perf/core] perf/x86: Filter out undefined events from sysfs events attribute
In reply to Jiri OlsaCommit-ID: 8300daa26755c9a194776778bd822acf1fa2dbf6 Gitweb: http://git.kernel.org/tip/8300daa26755c9a194776778bd822acf1fa2dbf6 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:12 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:24 +0200
perf/x86: Filter out undefined events from sysfs events attribute
The sysfs events group attribute currently shows all hw events, including also undefined ones.
This patch filters out all undefined events out of the sysfs events group attribute, so they don't even show up.
--- arch/x86/kernel/cpu/perf_event.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_event.c +22 -0
@@ -1321,6 +1321,26 @@ struct perf_pmu_events_attr {u64 id; }; +/* +* Remove all undefined events (x86_pmu.event_map(id) == 0) +* out of events_attr attributes. +*/ +static void __init filter_events (struct attribute **attrs) +{ +int i, j; + +for (i =0 ; attrs[i]; i++) { +if (x86_pmu.event_map (i)) +continue ; + +for (j = i; attrs[j]; j++) + attrs[j] = attrs[j +1 ]; + +/* Check the shifted attr. */ + i--; + } +} +ssize_t events_sysfs_show (struct device *dev,struct device_attribute *attr,char *page) {
@@ -1420,6 +1440,8 @@ static int __init init_hw_perf_events(void)if (!x86_pmu.events_sysfs_show) x86_pmu_events_group.attrs = &empty_attrs; +else +filter_events (x86_pmu_events_group.attrs);pr_info ("... version: %d\n" , x86_pmu.version);pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits);
[tip:perf/core] perf/x86: Add hardware events translations for AMD cpus
In reply to Jiri OlsaCommit-ID: 0bf79d44133de42af01a70a1700b8bb4b6d3fb92 Gitweb: http://git.kernel.org/tip/0bf79d44133de42af01a70a1700b8bb4b6d3fb92 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:14 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:25 +0200
perf/x86: Add hardware events translations for AMD cpus
Add support for AMD processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations:
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event.c | 3 +-- arch/x86/kernel/cpu/perf_event.h | 2 +- arch/x86/kernel/cpu/perf_event_amd.c | 9 +++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 11 +++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event.c +1 -2
@@ -1392,9 +1392,8 @@ static struct attribute_group x86_pmu_events_group = { .attrs = events_attr, }; -ssize_t x86_event_sysfs_show (char *page,u64 config) +ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event) { -u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT );u64 umask = (config &ARCH_PERFMON_EVENTSEL_UMASK ) >>8 ;u64 cmask = (config &ARCH_PERFMON_EVENTSEL_CMASK ) >>24 ;bool edge = (config &ARCH_PERFMON_EVENTSEL_EDGE );
arch/x86/kernel/cpu/perf_event.h +1 -1
@@ -538,7 +538,7 @@ static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip) regs->ip = ip; } -ssize_t x86_event_sysfs_show (char *page,u64 config); +ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event);#ifdef CONFIG_CPU_SUP_AMD
arch/x86/kernel/cpu/perf_event_amd.c +9 -0
@@ -568,6 +568,14 @@ amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *ev } } +static ssize_t amd_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ) | + (config &AMD64_EVENTSEL_EVENT ) >>24 ; + +return x86_event_sysfs_show (page, config, event); +} +static __initconst const struct x86_pmu amd_pmu = { .name ="AMD" , .handle_irq = x86_pmu_handle_irq,
@@ -591,6 +599,7 @@ static __initconst const struct x86_pmu amd_pmu = { .put_event_constraints = amd_put_event_constraints, .format_attrs = amd_format_attr, + .events_sysfs_show = amd_event_sysfs_show, .cpu_prepare = amd_pmu_cpu_prepare, .cpu_starting = amd_pmu_cpu_starting,
arch/x86/kernel/cpu/perf_event_intel.c +9 -2
@@ -1603,6 +1603,13 @@ static struct attribute *intel_arch_formats_attr[] = { NULL, }; +ssize_t intel_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ); + +return x86_event_sysfs_show (page, config, event); +} +static __initconst const struct x86_pmu core_pmu = { .name ="core" , .handle_irq = x86_pmu_handle_irq,
@@ -1628,7 +1635,7 @@ static __initconst const struct x86_pmu core_pmu = { .event_constraints = intel_core_event_constraints, .guest_get_msrs = core_guest_get_msrs, .format_attrs = intel_arch_formats_attr, - .events_sysfs_show = x86_event_sysfs_show, + .events_sysfs_show = intel_event_sysfs_show, };struct intel_shared_regs *allocate_shared_regs (int cpu)
@@ -1767,7 +1774,7 @@ static __initconst const struct x86_pmu intel_pmu = { .pebs_aliases = intel_pebs_aliases_core2, .format_attrs = intel_arch3_formats_attr, - .events_sysfs_show = x86_event_sysfs_show, + .events_sysfs_show = intel_event_sysfs_show, .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting,
[tip:perf/core] perf/x86: Add hardware events translations for Intel cpus
In reply to Jiri OlsaCommit-ID: 43c032febde48aabcf6d59f47cdcb7b5debbdc63 Gitweb: http://git.kernel.org/tip/43c032febde48aabcf6d59f47cdcb7b5debbdc63 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:13 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:24 +0200
perf/x86: Add hardware events translations for Intel cpus
Add support for Intel processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations:
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event.c | 40 ++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event.h | 2 + arch/x86/kernel/cpu/perf_event_intel.c | 2 + 3 files changed, 44 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_event.c +40 -0
@@ -1392,6 +1392,46 @@ static struct attribute_group x86_pmu_events_group = { .attrs = events_attr, }; +ssize_t x86_event_sysfs_show (char *page,u64 config) +{ +u64 event = (config &ARCH_PERFMON_EVENTSEL_EVENT ); +u64 umask = (config &ARCH_PERFMON_EVENTSEL_UMASK ) >>8 ; +u64 cmask = (config &ARCH_PERFMON_EVENTSEL_CMASK ) >>24 ; +bool edge = (config &ARCH_PERFMON_EVENTSEL_EDGE ); +bool pc = (config &ARCH_PERFMON_EVENTSEL_PIN_CONTROL ); +bool any = (config &ARCH_PERFMON_EVENTSEL_ANY ); +bool inv = (config &ARCH_PERFMON_EVENTSEL_INV ); +ssize_t ret; + +/* +* We have whole page size to spend and just little data +* to write, so we can safely use sprintf. +*/ + ret =sprintf (page,"event=0x%02llx" , event); + +if (umask) + ret +=sprintf (page + ret,",umask=0x%02llx" , umask); + +if (edge) + ret +=sprintf (page + ret,",edge" ); + +if (pc) + ret +=sprintf (page + ret,",pc" ); + +if (any) + ret +=sprintf (page + ret,",any" ); + +if (inv) + ret +=sprintf (page + ret,",inv" ); + +if (cmask) + ret +=sprintf (page + ret,",cmask=0x%02llx" , cmask); + + ret +=sprintf (page + ret,"\n" ); + +return ret; +} +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
arch/x86/kernel/cpu/perf_event.h +2 -0
@@ -538,6 +538,8 @@ static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip) regs->ip = ip; } +ssize_t x86_event_sysfs_show (char *page,u64 config); +#ifdef CONFIG_CPU_SUP_AMD int amd_pmu_init (void );
arch/x86/kernel/cpu/perf_event_intel.c +2 -0
@@ -1628,6 +1628,7 @@ static __initconst const struct x86_pmu core_pmu = { .event_constraints = intel_core_event_constraints, .guest_get_msrs = core_guest_get_msrs, .format_attrs = intel_arch_formats_attr, + .events_sysfs_show = x86_event_sysfs_show, };struct intel_shared_regs *allocate_shared_regs (int cpu)
@@ -1766,6 +1767,7 @@ static __initconst const struct x86_pmu intel_pmu = { .pebs_aliases = intel_pebs_aliases_core2, .format_attrs = intel_arch3_formats_attr, + .events_sysfs_show = x86_event_sysfs_show, .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting,
[tip:perf/core] perf/x86: Add hardware events translations for Intel P6 cpus
In reply to Jiri OlsaCommit-ID: 20550a434583c78f8ff9a2819639e2bacbe58574 Gitweb: http://git.kernel.org/tip/20550a434583c78f8ff9a2819639e2bacbe58574 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:15 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:25 +0200
perf/x86: Add hardware events translations for Intel P6 cpus
Add support for Intel P6 processors to display 'events' sysfs directory (/sys/devices/cpu/events/) with hw event translations:
# ls /sys/devices/cpu/events/ branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles stalled-cycles-backend stalled-cycles-frontend
--- arch/x86/kernel/cpu/perf_event.h | 1 + arch/x86/kernel/cpu/perf_event_p6.c | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_event.h +1 -0
@@ -539,6 +539,7 @@ static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip) }ssize_t x86_event_sysfs_show (char *page,u64 config,u64 event); +ssize_t intel_event_sysfs_show (char *page,u64 config);#ifdef CONFIG_CPU_SUP_AMD
arch/x86/kernel/cpu/perf_event_p6.c +2 -0
@@ -134,6 +134,8 @@ static __initconst const struct x86_pmu p6_pmu = { .event_constraints = p6_event_constraints, .format_attrs = intel_p6_formats_attr, + .events_sysfs_show = intel_event_sysfs_show, + };__init int p6_pmu_init (void )
[tip:perf/core] perf tools: Fix PMU object alias initialization
In reply to Jiri OlsaCommit-ID: 3fded963cdae12ff891a55efc866437506c3f912 Gitweb: http://git.kernel.org/tip/3fded963cdae12ff891a55efc866437506c3f912 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:16 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:26 +0200
perf tools: Fix PMU object alias initialization
The pmu_lookup should return pmus that do not expose the 'events' group attribute in sysfs. Also it should fail when any other error during 'events' lookup is hit (pmu_aliases fails).
--- tools/perf/util/pmu.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
tools/perf/util/pmu.c +4 -3
@@ -164,7 +164,7 @@ static int pmu_aliases(char *name, struct list_head *head) "%s/bus/event_source/devices/%s/events", sysfs, name);if (stat (path, &st) <0 ) -return -1 ; +return 0 ;/* no error if 'events' does not exist */ if (pmu_aliases_parse (path, head))return -1 ;
@@ -296,6 +296,9 @@ static struct perf_pmu *pmu_lookup(char *name)if (pmu_format (name, &format))return NULL ; +if (pmu_aliases (name, &aliases)) +return NULL ; +if (pmu_type (name, &type))return NULL ;
@@ -305,8 +308,6 @@ static struct perf_pmu *pmu_lookup(char *name) pmu->cpus =pmu_cpumask (name); -pmu_aliases (name, &aliases); -INIT_LIST_HEAD (&pmu->format);INIT_LIST_HEAD (&pmu->aliases);list_splice (&format, &pmu->format);
[tip:perf/core] perf test: Add automated tests for pmu sysfs translated events
In reply to Jiri OlsaCommit-ID: 3f3a20648797c3ff49c6ebfe10747ef0acd37c50 Gitweb: http://git.kernel.org/tip/3f3a20648797c3ff49c6ebfe10747ef0acd37c50 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:18 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:27 +0200
perf test: Add automated tests for pmu sysfs translated events
Add automated tests for all events found under PMU/events directory. Tested events are in the 'cpu/event=xxx/u' format, where 'xxx' is substituted by every event found.
The 'event=xxx' term is translated to the cpu specific term. We only check that the event is created (not the real config numbers) and that the modifier is properly set.
--- tools/perf/util/parse-events-test.c | 68 +++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 0 deletions(-)
tools/perf/util/parse-events-test.c +68 -0
@@ -443,6 +443,23 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)return 0 ; } +static int test__checkevent_pmu_events (struct perf_evlist *evlist) +{ +struct perf_evsel *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 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 int test__checkterms_simple (struct list_head *terms) {struct parse_events__term *term;
@@ -1024,6 +1041,51 @@ static int test_pmu(void)return !ret; } +static int test_pmu_events (void ) +{ +struct stat st; +char path[PATH_MAX ]; +struct dirent *ent; +DIR *dir; +int ret; + +snprintf (path,PATH_MAX ,"%s/bus/event_source/devices/cpu/events/" , +sysfs_find_mountpoint ()); + + ret =stat (path, &st); +if (ret) { +pr_debug ("ommiting PMU cpu events tests\n" ); +return 0 ; + } + + dir =opendir (path); +if (!dir) { +pr_debug ("can't open pmu event dir" ); +return -1 ; + } + +while (!ret && (ent =readdir (dir))) { +#define MAX_NAME 100 +struct test__event_st e; +char name[MAX_NAME ]; + +if (!strcmp (ent->d_name,"." ) || + !strcmp (ent->d_name,".." )) +continue ; + +snprintf (name,MAX_NAME ,"cpu/event=%s/u" , ent->d_name); + + e.name = name; + e.check = test__checkevent_pmu_events; + + ret =test_event (&e); +#undef MAX_NAME + } + +closedir (dir); +return ret; +} +int parse_events__test (void ) {int ret1, ret2 =0 ;
@@ -1040,6 +1102,12 @@ do { \if (test_pmu ())TEST_EVENTS (test__events_pmu); +if (test_pmu ()) { +int ret =test_pmu_events (); +if (ret) +return ret; + } + ret1 =test_terms (test__terms,ARRAY_SIZE (test__terms));if (!ret2) ret2 = ret1;
[tip:perf/core] perf tools: Add support to specify hw event as PMU event term
In reply to Jiri OlsaCommit-ID: 1d33d6dce11e2c900daeca8110d56b95f1174188 Gitweb: http://git.kernel.org/tip/1d33d6dce11e2c900daeca8110d56b95f1174188 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 10 Oct 2012 14:53:17 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Oct 2012 10:41:27 +0200
perf tools: Add support to specify hw event as PMU event term
Add a way to specify hw event as PMU event term like:
'cpu/event=cpu-cycles/u'
'cpu/event=instructions,.../u'
'cpu/cycles,.../u'
The 'event=cpu-cycles' term is replaced/translated by the hw events term translation, which is exposed by sysfs 'events' group attribute.
Add parser bits, the rest is already handled by the PMU alias code.
--- tools/perf/util/parse-events.c | 18 ++++++++++++++++++ tools/perf/util/parse-events.h | 2 ++ tools/perf/util/parse-events.y | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 0 deletions(-)
tools/perf/util/parse-events.c +18 -0
@@ -1142,6 +1142,24 @@ int parse_events__term_str(struct parse_events__term **term, config, str, 0); } +int parse_events__term_sym_hw (struct parse_events__term **term, +char *config,unsigned idx) +{ +struct event_symbol *sym; + +BUG_ON (idx >=PERF_COUNT_HW_MAX ); + sym = &event_symbols_hw[idx]; + +if (config) +return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , +PARSE_EVENTS__TERM_TYPE_USER , config, + (char *) sym->symbol,0 ); +else +return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , +PARSE_EVENTS__TERM_TYPE_USER , + (char *)"event" , (char *) sym->symbol,0 ); +} +int parse_events__term_clone (struct parse_events__term **new,struct parse_events__term *term) {
tools/perf/util/parse-events.h +2 -0
@@ -76,6 +76,8 @@ int parse_events__term_num(struct parse_events__term **_term, int type_term, char *config, u64 num);int parse_events__term_str (struct parse_events__term **_term,int type_term,char *config,char *str); +int parse_events__term_sym_hw (struct parse_events__term **term, +char *config,unsigned idx);int parse_events__term_clone (struct parse_events__term **new,struct parse_events__term *term);void parse_events__free_terms (struct list_head *terms);
tools/perf/util/parse-events.y +18 -0
@@ -352,6 +352,15 @@ PE_NAME '=' PE_VALUE $$ = term; } | +PE_NAME '=' PE_VALUE_SYM_HW +{ + struct parse_events__term *term; + int config = $3 & 255; + + ABORT_ON(parse_events__term_sym_hw(&term, $1, config)); + $$ = term; +} +| PE_NAME { struct parse_events__term *term;
@@ -361,6 +370,15 @@ PE_NAME $$ = term; } | +PE_VALUE_SYM_HW +{ + struct parse_events__term *term; + int config = $1 & 255; + + ABORT_ON(parse_events__term_sym_hw(&term, NULL, config)); + $$ = term; +} +| PE_TERM '=' PE_NAME { struct parse_events__term *term;