perf tests: Adding precise event attribute test
Subsystems (2)
cover perf tests: Adding precise event attribute test
hi,
as per issues with precise attribute [1], adding simple test to catch it next time.
Patch 2 adds sysfs 'precise' attribute containing maximum value for perf_event_attr::precise_ip.
Patch 3 adds simple test checking the attribute and creating cycle events with all possible precise values.
I based this on revert (Patch 1) discussed in [1]. I'm not sure this revert will tak place at the end, but I wanted to get some feedback on the 'precise' attribute first.
Attached patches:
1/3 Revert "perf: Require exclude_guest to use PEBS - kernel side enforcement" 2/3 perf x86: Add precise sysfs attribute
3/3 perf tests: Add precise event attribute test
thanks,
jirka
[1] http://marc.info/?l=linux-kernel&m=135536724805356&w=2
--- arch/x86/kernel/cpu/perf_event.c | 38 ++++++++++++++++++++++++-------------- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/precise.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 5 files changed, 109 insertions(+), 14 deletions(-)
PATCH 1/3 Revert "perf: Require exclude_guest to use PEBS - kernel side enforcement"
This reverts commit 20b279ddb38ca42f8863cec07b4d45ec24589f13.
--- arch/x86/kernel/cpu/perf_event.c | 6 ------ 1 file changed, 6 deletions(-)
arch/x86/kernel/cpu/perf_event.c +0 -6
@@ -340,9 +340,6 @@ int x86_setup_perfctr(struct perf_event *event)/* BTS is currently only allowed for user-mode. */ if (!attr->exclude_kernel)return -EOPNOTSUPP ; - -if (!attr->exclude_guest) -return -EOPNOTSUPP ; } hwc->config |= config;
@@ -385,9 +382,6 @@ int x86_pmu_hw_config(struct perf_event *event)if (event->attr.precise_ip) {int precise =0 ; -if (!event->attr.exclude_guest) -return -EOPNOTSUPP ; -/* Support for constant skid */ if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) { precise++;
Signature · 1 line
1.7.11.7
Re: [PATCH 1/3] Revert "perf: Require exclude_guest to use PEBS - kernel side enforcement"
Quoted 9 lines · Jiri Olsa
This reverts commit
20b279ddb38ca42f8863cec07b4d45ec24589f13.Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>
As a courtesy please CC people involved in a commit on any revert request.
Arnaldo: please do not take this patch; I have proposed an alternative. Just waiting to hear back on its acceptability.
David
Re: [PATCH 1/3] Revert "perf: Require exclude_guest to use PEBS - kernel side enforcement"
Quoted 11 lines · David Ahern
Quoted 9 lines · Jiri Olsa
This reverts commit
20b279ddb38ca42f8863cec07b4d45ec24589f13.Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>
Quoted 6 lines
As a courtesy please CC people involved in a commit on any revert request.
Arnaldo: please do not take this patch; I have proposed an alternative. Just waiting to hear back on its acceptability.
David
this one was not meant to be applied.. just wanted the precise to work, so I could test other stuff.. I did mention that in:
[RFC 0/3] perf tests: Adding precise event attribute test
---
I based this on revert (Patch 1) discussed in [1]. I'm not sure this revert will tak place at the end, but I wanted to get some feedback on the 'precise' attribute first.
...
[1] http://marc.info/?l=linux-kernel&m=135536724805356&w=2
---
jirka
PATCH 2/3 perf x86: Add precise sysfs attribute
In reply to Jiri OlsaAdding sysfs precise attribute for cpu device (/sys/devices/cpu) to show the maximum value for perf event precise attribute.
This will be initialy used for automated precise event perf test and could be helpful otherwise. Arnaldo suggested to use this as a guide for default adding of precise attribute for HW events.
--- arch/x86/kernel/cpu/perf_event.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/perf_event.c +25 -9
@@ -377,19 +377,26 @@ static inline int precise_br_compat(struct perf_event *event)return m == b; } -int x86_pmu_hw_config (struct perf_event *event) +static int x86_get_precise (void ) { -if (event->attr.precise_ip) { -int precise =0 ; +int precise =0 ; -/* Support for constant skid */ -if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) { +/* Support for constant skid */ +if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) { + precise++; + +/* Support for IP fixup */ +if (x86_pmu.lbr_nr) precise++; + } -/* Support for IP fixup */ -if (x86_pmu.lbr_nr) - precise++; - } +return precise; +} + +int x86_pmu_hw_config (struct perf_event *event) +{ +if (event->attr.precise_ip) { +int precise =x86_get_precise ();if (event->attr.precise_ip > precise)return -EOPNOTSUPP ;
@@ -1700,6 +1707,13 @@ static int x86_pmu_event_init(struct perf_event *event)return err; } +static ssize_t get_attr_precise (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,10 ,"%d\n" ,x86_get_precise ()); +} +static int x86_pmu_event_idx (struct perf_event *event) {int idx = event->hw.idx;
@@ -1752,9 +1766,11 @@ static ssize_t set_attr_rdpmc(struct device *cdev, } static DEVICE_ATTR(rdpmc, S_IRUSR | S_IWUSR, get_attr_rdpmc, set_attr_rdpmc); +static DEVICE_ATTR(precise, S_IRUGO, get_attr_precise, NULL);static struct attribute *x86_pmu_attrs[] = { &dev_attr_rdpmc.attr, + &dev_attr_precise.attr,NULL , };
Signature · 1 line
1.7.11.7
Re: [PATCH 2/3] perf x86: Add precise sysfs attribute
Quoted 15 lines · Jiri Olsa
Adding sysfs precise attribute for cpu device (
/sys/devices/cpu) to show the maximum value for perf event precise attribute.This will be initialy used for automated precise event perf test and could be helpful otherwise. Arnaldo suggested to use this as a guide for default adding of precise attribute for HW events.
Signed-off-by Jiri Olsa <[email protected]>Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>
Quoted 3 lines
--- arch/x86/kernel/cpu/perf_event.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
As you are adding a new sysfs file, you must also document it with an entry in Documentation/ABI/
thanks,
greg k-h
Re: [PATCH 2/3] perf x86: Add precise sysfs attribute
Quoted 20 lines · Greg KH
Quoted 15 lines · Jiri Olsa
Adding sysfs precise attribute for cpu device (
/sys/devices/cpu) to show the maximum value for perf event precise attribute.This will be initialy used for automated precise event perf test and could be helpful otherwise. Arnaldo suggested to use this as a guide for default adding of precise attribute for HW events.
Signed-off-by Jiri Olsa <[email protected]>Cc Corey Ashford <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Quoted 3 lines
--- arch/x86/kernel/cpu/perf_event.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
Quoted 2 lines
As you are adding a new sysfs file, you must also document it with an entry in
Documentation/ABI/
will do, thanks
jirka
Namhyung Kim
maintainerRe: [PATCH 2/3] perf x86: Add precise sysfs attribute
In reply to Jiri OlsaQuoted 6 lines · Jiri Olsa
Adding sysfs precise attribute for cpu device (
/sys/devices/cpu) to show the maximum value for perf event precise attribute.This will be initialy used for automated precise event perf test and could be helpful otherwise. Arnaldo suggested to use this as a guide for default adding of precise attribute for HW events.
Although I'm not aware of which architectures support precise feature, wouldn't it better putting this on architecture independent rather than just for x86 with fallback routine returning 0?
Thanks,
Namhyung
Re: [PATCH 2/3] perf x86: Add precise sysfs attribute
Quoted 11 lines · Namhyung Kim
Quoted 6 lines · Jiri Olsa
Adding sysfs precise attribute for cpu device (
/sys/devices/cpu) to show the maximum value for perf event precise attribute.This will be initialy used for automated precise event perf test and could be helpful otherwise. Arnaldo suggested to use this as a guide for default adding of precise attribute for HW events.
Although I'm not aware of which architectures support precise feature, wouldn't it better putting this on architecture independent rather than just for x86 with fallback routine returning 0?
same here.. :) no idea if there's same concept in other archs
Anyway, I'd say it's not big change so once other archs get interested, it's easy to make it global one.
Same like for event aliases moving to ppc now:
http://marc.info/?l=linux-kernel&m=135590210618224&w=2
thanks,
jirka
PATCH 3/3 perf tests: Add precise event attribute test
In reply to Jiri OlsaFrom: "[email protected]" <[email protected]>
The test detects the precise attribute availability and try to open perf event with each allowed precise attribute value.
--- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 4 +++ tools/perf/tests/precise.c | 79 +++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 85 insertions(+) create mode 100644 tools/perf/tests/precise.c
tools/perf/Makefile +1 -0
@@ -489,6 +489,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o LIB_OBJS += $(OUTPUT)tests/pmu.o LIB_OBJS += $(OUTPUT)tests/hists_link.o LIB_OBJS += $(OUTPUT)tests/python-use.o +LIB_OBJS += $(OUTPUT)tests/precise.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
@@ -77,6 +77,10 @@ static struct test { .func = test__python_use, }, { + .desc = "Test precise event attribute", + .func = test__precise, + }, + { .func = NULL, }, };
tools/perf/tests/precise.c new file +79 -0
79 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -23,5 +23,6 @@ int test__dso_data(void);int test__parse_events (void );int test__hists_link (void );int test__python_use (void ); +int test__precise (void );#endif /* TESTS_H */
Signature · 1 line
1.7.11.7