mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: peterz@infradead.org, robert.richter@amd.org, acme@redhat.com
Cc: linux-kernel@vger.kernel.org, sukadev@linux.vnet.ibm.com
Subject: [PATCH] perf: x86 filter_events() - use hw event id ?
Date: Tue, 30 Oct 2012 23:31:33 -0700	[thread overview]
Message-ID: <20121031063133.GA12037@us.ibm.com> (raw)


>From c3b53a5733fdea35807f4513255bca05e3aee5c5 Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Date: Tue, 30 Oct 2012 23:05:05 -0700
Subject: [PATCH] perf: x86 filter_events() - use hw event id ?

The ->event_map() operation expects to index through the _hardware event id_.
But filter_events() function is calling ->event_map() with a loop index i.

Suppose a processor does not implement say PERF_COUNT_HW_BUS_CYCLES (6),
but implements, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND (7).

->event_map() for "bus cycles" returns 0, we push the "stalled-cycles-frontend"
event up by one in the events_attr[].

The index of "stalled-cycles-frontend" in the events_attr[] is 6 which
is different from its hardware event id 7.

The next and subsequent calls to ->event_map() will use this index in the
modified events_attr[] table. All subsequent event ids appear unimplemented
because they continue to check the same index (6 in this case).

Should'nt we be checking the hardware event id instead ?

I have not tested this on x86 - only on my port of the sysfs events to Power.
---
 arch/x86/kernel/cpu/perf_event.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 0a55ab2..ae88512 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1325,12 +1325,21 @@ struct perf_pmu_events_attr {
  * Remove all undefined events (x86_pmu.event_map(id) == 0)
  * out of events_attr attributes.
  */
+#define PMU_ATTR(a) container_of((a), struct perf_pmu_events_attr, attr)
+#define DEV_ATTR(a) container_of((a), struct device_attribute, attr)
+
 static void __init filter_events(struct attribute **attrs)
 {
 	int i, j;
+	struct perf_pmu_events_attr *pmu_attr;
+	struct device_attribute *dev_attr;
+	
 
 	for (i = 0; attrs[i]; i++) {
-		if (x86_pmu.event_map(i))
+		dev_attr = DEV_ATTR(attrs[i]);
+		pmu_attr = PMU_ATTR(dev_attr);
+
+		if (x86_pmu.event_map(pmu_attr->id))
 			continue;
 
 		for (j = i; attrs[j]; j++)
-- 
1.7.1


                 reply	other threads:[~2012-10-31  6:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121031063133.GA12037@us.ibm.com \
    --to=sukadev@linux.vnet.ibm.com \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=robert.richter@amd.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome