* [PATCH v2] perf/x86: fix filter_events() bug with event mappings
@ 2015-12-07 19:33 Stephane Eranian
2015-12-08 9:13 ` Peter Zijlstra
2016-01-06 18:51 ` [tip:perf/core] perf/x86: Fix " tip-bot for Stephane Eranian
0 siblings, 2 replies; 3+ messages in thread
From: Stephane Eranian @ 2015-12-07 19:33 UTC (permalink / raw)
To: linux-kernel; +Cc: acme, peterz, mingo, ak, kan.liang, jolsa
This patch fixes a bug in the filter_events() function.
The patch fixes the bug whereby if some mappings did not
exist, e.g., STALLED_CYCLES_FRONTEND, then any event after it
in the attrs array would disappear from the published list of
events in /sys/devices/cpu/events. This could be verified
easily on any system post SNB (which do not publish
STALLED_CYCLES_FRONTEND):
$ ./perf stat -e cycles,ref-cycles true
Performance counter stats for 'true':
1,217,348 cycles
<not supported> ref-cycles
The problem is that in filter_events() there is an assumption
that the argument (attrs) is organized in increasing continuous
event indexes related to the event_map(). But if we remove the
non-supported events by shifing the position in the array, then
the lookup x86_pmu.event_map() needs to compensate for it, otherwise
we are looking up the wrong index. This patch corrects this problem
by compensating for the deleted events and with that ref-cycles
reappears (here shown on Haswell):
$ perf stat -e ref-cycles,cycles true
Performance counter stats for 'true':
4,525,910 ref-cycles
1,064,920 cycles
0.002943888 seconds time elapsed
This problem was introduced into commit 8300daa26.
Fixes: 8300daa26 ("perf/x86: Filter out undefined events from sysfs events attribute")
In V2, we dropped the attrs[j] = NULL fix because it was superfluous.
Signed-off-by: Stephane Eranian <eranian@google.com>
---
arch/x86/kernel/cpu/perf_event.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index e7e63a9..1b443db 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1534,6 +1534,7 @@ static void __init filter_events(struct attribute **attrs)
{
struct device_attribute *d;
struct perf_pmu_events_attr *pmu_attr;
+ int offset = 0;
int i, j;
for (i = 0; attrs[i]; i++) {
@@ -1542,7 +1543,7 @@ static void __init filter_events(struct attribute **attrs)
/* str trumps id */
if (pmu_attr->event_str)
continue;
- if (x86_pmu.event_map(i))
+ if (x86_pmu.event_map(i + offset))
continue;
for (j = i; attrs[j]; j++)
@@ -1550,6 +1551,14 @@ static void __init filter_events(struct attribute **attrs)
/* Check the shifted attr. */
i--;
+
+ /*
+ * event_map() is index based, the attrs array is organized
+ * by increasing event index. If we shift the events, then
+ * we need to compensate for the event_map(), otherwise
+ * we are looking up the wrong event in the map
+ */
+ offset++;
}
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] perf/x86: fix filter_events() bug with event mappings
2015-12-07 19:33 [PATCH v2] perf/x86: fix filter_events() bug with event mappings Stephane Eranian
@ 2015-12-08 9:13 ` Peter Zijlstra
2016-01-06 18:51 ` [tip:perf/core] perf/x86: Fix " tip-bot for Stephane Eranian
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2015-12-08 9:13 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, acme, mingo, ak, kan.liang, jolsa
On Mon, Dec 07, 2015 at 08:33:25PM +0100, Stephane Eranian wrote:
> Fixes: 8300daa26 ("perf/x86: Filter out undefined events from sysfs events attribute")
Please put the below in your .gitconfig, the alias is just a convenient
helper to generate the right string, but the abbrev is the important
part, we've already had hash collisions with the short thingies.
[core]
abbrev = 12
[alias]
one = show -s --pretty='format:%h (\"%s\")'
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:perf/core] perf/x86: Fix filter_events() bug with event mappings
2015-12-07 19:33 [PATCH v2] perf/x86: fix filter_events() bug with event mappings Stephane Eranian
2015-12-08 9:13 ` Peter Zijlstra
@ 2016-01-06 18:51 ` tip-bot for Stephane Eranian
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Stephane Eranian @ 2016-01-06 18:51 UTC (permalink / raw)
To: linux-tip-commits
Cc: jolsa, mingo, torvalds, vincent.weaver, hpa, eranian, acme,
peterz, linux-kernel, tglx
Commit-ID: 61b87cae6361ea6af161c1ffa549898892707b19
Gitweb: http://git.kernel.org/tip/61b87cae6361ea6af161c1ffa549898892707b19
Author: Stephane Eranian <eranian@google.com>
AuthorDate: Mon, 7 Dec 2015 20:33:25 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jan 2016 11:15:33 +0100
perf/x86: Fix filter_events() bug with event mappings
This patch fixes a bug in the filter_events() function.
The patch fixes the bug whereby if some mappings did not
exist, e.g., STALLED_CYCLES_FRONTEND, then any event after it
in the attrs array would disappear from the published list of
events in /sys/devices/cpu/events. This could be verified
easily on any system post SNB (which do not publish
STALLED_CYCLES_FRONTEND):
$ ./perf stat -e cycles,ref-cycles true
Performance counter stats for 'true':
1,217,348 cycles
<not supported> ref-cycles
The problem is that in filter_events() there is an assumption
that the argument (attrs) is organized in increasing continuous
event indexes related to the event_map(). But if we remove the
non-supported events by shifing the position in the array, then
the lookup x86_pmu.event_map() needs to compensate for it, otherwise
we are looking up the wrong index. This patch corrects this problem
by compensating for the deleted events and with that ref-cycles
reappears (here shown on Haswell):
$ perf stat -e ref-cycles,cycles true
Performance counter stats for 'true':
4,525,910 ref-cycles
1,064,920 cycles
0.002943888 seconds time elapsed
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: jolsa@kernel.org
Cc: kan.liang@intel.com
Fixes: 8300daa26755 ("perf/x86: Filter out undefined events from sysfs events attribute")
Link: http://lkml.kernel.org/r/1449516805-6637-1-git-send-email-eranian@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/cpu/perf_event.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index e7e63a9..1b443db 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1534,6 +1534,7 @@ static void __init filter_events(struct attribute **attrs)
{
struct device_attribute *d;
struct perf_pmu_events_attr *pmu_attr;
+ int offset = 0;
int i, j;
for (i = 0; attrs[i]; i++) {
@@ -1542,7 +1543,7 @@ static void __init filter_events(struct attribute **attrs)
/* str trumps id */
if (pmu_attr->event_str)
continue;
- if (x86_pmu.event_map(i))
+ if (x86_pmu.event_map(i + offset))
continue;
for (j = i; attrs[j]; j++)
@@ -1550,6 +1551,14 @@ static void __init filter_events(struct attribute **attrs)
/* Check the shifted attr. */
i--;
+
+ /*
+ * event_map() is index based, the attrs array is organized
+ * by increasing event index. If we shift the events, then
+ * we need to compensate for the event_map(), otherwise
+ * we are looking up the wrong event in the map
+ */
+ offset++;
}
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-01-06 18:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-07 19:33 [PATCH v2] perf/x86: fix filter_events() bug with event mappings Stephane Eranian
2015-12-08 9:13 ` Peter Zijlstra
2016-01-06 18:51 ` [tip:perf/core] perf/x86: Fix " tip-bot for Stephane Eranian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).