From: Jiri Olsa <jolsa@kernel.org>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: lkml <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Andi Kleen <ak@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 5/8] perf/x86: Add is_visible attribute_group callback for base events
Date: Sat, 4 May 2019 14:52:04 +0200 [thread overview]
Message-ID: <20190504125207.24662-6-jolsa@kernel.org> (raw)
In-Reply-To: <20190504125207.24662-1-jolsa@kernel.org>
We dont need to pre-filter out unsupported base events,
we can just use its group's is_visible function to do this.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/x86/events/core.c | 52 ++++++++++++------------------------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index a43d8d1e8590..1889e45e6742 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1618,42 +1618,6 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {
.attrs = NULL,
};
-/*
- * Remove all undefined events (x86_pmu.event_map(id) == 0)
- * out of events_attr attributes.
- */
-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++) {
- d = (struct device_attribute *)attrs[i];
- pmu_attr = container_of(d, struct perf_pmu_events_attr, attr);
- /* str trumps id */
- if (pmu_attr->event_str)
- continue;
- if (x86_pmu.event_map(i + offset))
- continue;
-
- for (j = i; attrs[j]; j++)
- attrs[j] = attrs[j + 1];
-
- /* 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++;
- }
-}
-
/* Merge two pointer arrays */
__init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
{
@@ -1744,9 +1708,23 @@ static struct attribute *events_attr[] = {
NULL,
};
+/*
+ * Remove all undefined events (x86_pmu.event_map(id) == 0)
+ * out of events_attr attributes.
+ */
+static umode_t
+is_visible(struct kobject *kobj, struct attribute *attr, int idx)
+{
+ struct perf_pmu_events_attr *pmu_attr;
+
+ pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
+ return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;
+}
+
static struct attribute_group x86_pmu_events_group __ro_after_init = {
.name = "events",
.attrs = events_attr,
+ .is_visible = is_visible,
};
ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event)
@@ -1852,8 +1830,6 @@ 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);
if (x86_pmu.attrs) {
struct attribute **tmp;
--
2.20.1
next prev parent reply other threads:[~2019-05-04 12:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-04 12:51 [RFC 0/8] perf/x86: Add update attribute groups Jiri Olsa
2019-05-04 12:52 ` [PATCH 1/8] sysfs: Add sysfs_update_groups function Jiri Olsa
2019-05-04 13:53 ` Greg Kroah-Hartman
2019-05-09 15:23 ` Jiri Olsa
2019-05-04 12:52 ` [PATCH 2/8] perf: Add attr_groups_update into struct pmu Jiri Olsa
2019-05-04 12:52 ` [PATCH 3/8] perf/x86: Get rid of x86_pmu::event_attrs Jiri Olsa
2019-05-04 12:52 ` [PATCH 4/8] perf/x86: Use the new pmu::update_attrs attribute group Jiri Olsa
2019-05-04 12:52 ` Jiri Olsa [this message]
2019-05-04 12:52 ` [PATCH 6/8] perf/x86: Use update attribute groups for caps Jiri Olsa
2019-05-04 12:52 ` [PATCH 7/8] perf/x86/intel: Use update attributes for skylake format Jiri Olsa
2019-05-04 12:52 ` [PATCH 8/8] perf/x86: Use update attribute groups for default attributes Jiri Olsa
2019-05-04 13:53 ` Greg Kroah-Hartman
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=20190504125207.24662-6-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.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