Skip to contentSkip to conversation

perf/x86: Add update attribute groups

PATCH In review Jiri Olsa 4 participants 26 messages May 12, 2019 – Jun 17, 2019

Subsystems (3)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

v2 cover perf/x86: Add update attribute groups

hi,
following up on [1], this patchset adds update attribute groups to pmu and gets rid of the 'creative' attribute handling code.

In x86 pmu we mainly add attributes into following directories:
events, format, caps

so it seems like we could have just 3 attribute groups, but most of the attributes presence depends on HW, which ends up with attributes merging and all that 'creative' code we have now.

Currently, we have 'struct pmu::attr_groups', which is in its final shape (merged) and it's added via sysfs_create_groups call when registering the pmu:

perf_pmu_register
pmu_dev_alloc
device_add
device_add_attrs
device_add_groups
sysfs_create_groups(pmu::attr_groups)

This interface does not provide a way to have multiple attribute groups, which could add files into same directory, all has to be prepared ahead.

This patchset adds 'update attribute group', which is added via new sysfs_update_groups function, after the initial set of attributes is created. The group's is_visible function will cover its HW dependency/visibility.

This will allow us to update "events" or "format" directories with attributes that depend on various HW config.

For example having group_format_extra group, that updates "format" directory, only if pmu version is 2 and higher:

  static umode_t
  lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
  {
         return x86_pmu.lbr_nr ? attr->mode : 0;
  }

  static struct attribute_group group_caps_lbr = {
         .name       = "caps",
         .attrs      = lbr_attrs,
         .is_visible = lbr_is_visible,
  };

Note that some of the groups are defined without 'attrs' set, which is assigned later based on the detected cpu model.

And finally we'll end up with just a single set of attribute groups:

  static const struct attribute_group *attr_update[] = {
          &group_events_td,
          &group_events_mem,
          &group_events_tsx,
          &group_caps_gen,
          &group_caps_lbr,
          &group_format_extra,
          &group_format_extra_skl,
          &group_default,
          NULL,
  };

that is passed to struct pmu.

v2 changes:
- updated changelogs
- added Greg's Reviewed-by tag for sysfs change
- split "caps" update change into 2 patches

Also available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/x86_attrs

thanks,
jirka

[1] https://lore.kernel.org/lkml/[email protected]/
---
Jiri Olsa (9):
sysfs: Add sysfs_update_groups function
perf: Add attr_groups_update into struct pmu
perf/x86: Get rid of x86_pmu::event_attrs
perf/x86: Use the new pmu::update_attrs attribute group perf/x86: Add is_visible attribute_group callback for base events perf/x86: Use update attribute groups for caps perf/x86: Use update attribute groups for extra format perf/x86/intel: Use update attributes for skylake format perf/x86: Use update attribute groups for default attributes

 arch/x86/events/core.c       | 106 +++++++++++++------------------------------------------------------------------------
 arch/x86/events/intel/core.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------
 arch/x86/events/perf_event.h |   7 +-----
 fs/sysfs/group.c             |  54 +++++++++++++++++++++++++++++++-------------
 include/linux/perf_event.h   |   1 +
 include/linux/sysfs.h        |   2 ++
 kernel/events/core.c         |   6 +++++
 7 files changed, 161 insertions(+), 166 deletions(-)
author reviewer
#1 lore raw

PATCH v2 1/9 sysfs: Add sysfs_update_groups function

Adding sysfs_update_groups function to update
multiple groups.

sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
@kobj: The kobject to update the group on
@groups: The attribute groups to update, NULL terminated

This function update a bunch of attribute groups. If an error occurs when updating a group, all previously updated groups will be removed together with already existing (not updated) attributes.

---
 fs/sysfs/group.c      | 54 +++++++++++++++++++++++++++++++------------
 include/linux/sysfs.h |  2 ++
 2 files changed, 41 insertions(+), 15 deletions(-)
fs/sysfs/group.c +39 -15
index 57038604d4a8..d41c21fef138 100644
@@ -175,6 +175,26 @@ int sysfs_create_group(struct kobject *kobj,
 }
 EXPORT_SYMBOL_GPL(sysfs_create_group);
 
+static int internal_create_groups(struct kobject *kobj, int update,
+				  const struct attribute_group **groups)
+{
+	int error = 0;
+	int i;
+
+	if (!groups)
+		return 0;
+
+	for (i = 0; groups[i]; i++) {
+		error = internal_create_group(kobj, update, groups[i]);
+		if (error) {
+			while (--i >= 0)
+				sysfs_remove_group(kobj, groups[i]);
+			break;
+		}
+	}
+	return error;
+}
+
 /**
  * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
  * @kobj:	The kobject to create the group on
@@ -191,24 +211,28 @@ EXPORT_SYMBOL_GPL(sysfs_create_group);
 int sysfs_create_groups(struct kobject *kobj,
 			const struct attribute_group **groups)
 {
-	int error = 0;
-	int i;
-
-	if (!groups)
-		return 0;
-
-	for (i = 0; groups[i]; i++) {
-		error = sysfs_create_group(kobj, groups[i]);
-		if (error) {
-			while (--i >= 0)
-				sysfs_remove_group(kobj, groups[i]);
-			break;
-		}
-	}
-	return error;
+	return internal_create_groups(kobj, 0, groups);
 }
 EXPORT_SYMBOL_GPL(sysfs_create_groups);
 
+/**
+ * sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
+ * @kobj:	The kobject to update the group on
+ * @groups:	The attribute groups to update, NULL terminated
+ *
+ * This function update a bunch of attribute groups.  If an error occurs when
+ * updating a group, all previously updated groups will be removed together
+ * with already existing (not updated) attributes.
+ *
+ * Returns 0 on success or error code from sysfs_update_group on failure.
+ */
+int sysfs_update_groups(struct kobject *kobj,
+			const struct attribute_group **groups)
+{
+	return internal_create_groups(kobj, 1, groups);
+}
+EXPORT_SYMBOL_GPL(sysfs_update_groups);
+
 /**
  * sysfs_update_group - given a directory kobject, update an attribute group
  * @kobj:	The kobject to update the group on
include/linux/sysfs.h +2 -0
index 786816cf4aa5..d13db254fb99 100644
@@ -268,6 +268,8 @@ int __must_check sysfs_create_group(struct kobject *kobj,
 				    const struct attribute_group *grp);
 int __must_check sysfs_create_groups(struct kobject *kobj,
 				     const struct attribute_group **groups);
+int __must_check sysfs_update_groups(struct kobject *kobj,
+				     const struct attribute_group **groups);
 int sysfs_update_group(struct kobject *kobj,
 		       const struct attribute_group *grp);
 void sysfs_remove_group(struct kobject *kobj,
Signature · 1 line
2.20.1
#2 lore raw

[tip:perf/core] sysfs: Add sysfs_update_groups function

sysfs: Add sysfs_update_groups function
Commit-ID:  aac1f7f95f115d5a5329be05b80022e72df7d080
Gitweb:     https://git.kernel.org/tip/aac1f7f95f115d5a5329be05b80022e72df7d080
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:20 +0200

sysfs: Add sysfs_update_groups function

Adding sysfs_update_groups function to update
multiple groups.

sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
@kobj: The kobject to update the group on
@groups: The attribute groups to update, NULL terminated

This function update a bunch of attribute groups. If an error occurs when updating a group, all previously updated groups will be removed together with already existing (not updated) attributes.

---
 fs/sysfs/group.c      | 54 +++++++++++++++++++++++++++++++++++++--------------
 include/linux/sysfs.h |  8 ++++++++
 2 files changed, 47 insertions(+), 15 deletions(-)
fs/sysfs/group.c +39 -15
index 57038604d4a8..d41c21fef138 100644
@@ -175,6 +175,26 @@ int sysfs_create_group(struct kobject *kobj,
 }
 EXPORT_SYMBOL_GPL(sysfs_create_group);
 
+static int internal_create_groups(struct kobject *kobj, int update,
+				  const struct attribute_group **groups)
+{
+	int error = 0;
+	int i;
+
+	if (!groups)
+		return 0;
+
+	for (i = 0; groups[i]; i++) {
+		error = internal_create_group(kobj, update, groups[i]);
+		if (error) {
+			while (--i >= 0)
+				sysfs_remove_group(kobj, groups[i]);
+			break;
+		}
+	}
+	return error;
+}
+
 /**
  * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
  * @kobj:	The kobject to create the group on
@@ -191,24 +211,28 @@ EXPORT_SYMBOL_GPL(sysfs_create_group);
 int sysfs_create_groups(struct kobject *kobj,
 			const struct attribute_group **groups)
 {
-	int error = 0;
-	int i;
-
-	if (!groups)
-		return 0;
-
-	for (i = 0; groups[i]; i++) {
-		error = sysfs_create_group(kobj, groups[i]);
-		if (error) {
-			while (--i >= 0)
-				sysfs_remove_group(kobj, groups[i]);
-			break;
-		}
-	}
-	return error;
+	return internal_create_groups(kobj, 0, groups);
 }
 EXPORT_SYMBOL_GPL(sysfs_create_groups);
 
+/**
+ * sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
+ * @kobj:	The kobject to update the group on
+ * @groups:	The attribute groups to update, NULL terminated
+ *
+ * This function update a bunch of attribute groups.  If an error occurs when
+ * updating a group, all previously updated groups will be removed together
+ * with already existing (not updated) attributes.
+ *
+ * Returns 0 on success or error code from sysfs_update_group on failure.
+ */
+int sysfs_update_groups(struct kobject *kobj,
+			const struct attribute_group **groups)
+{
+	return internal_create_groups(kobj, 1, groups);
+}
+EXPORT_SYMBOL_GPL(sysfs_update_groups);
+
 /**
  * sysfs_update_group - given a directory kobject, update an attribute group
  * @kobj:	The kobject to update the group on
include/linux/sysfs.h +8 -0
index 786816cf4aa5..965236795750 100644
@@ -268,6 +268,8 @@ int __must_check sysfs_create_group(struct kobject *kobj,
 				    const struct attribute_group *grp);
 int __must_check sysfs_create_groups(struct kobject *kobj,
 				     const struct attribute_group **groups);
+int __must_check sysfs_update_groups(struct kobject *kobj,
+				     const struct attribute_group **groups);
 int sysfs_update_group(struct kobject *kobj,
 		       const struct attribute_group *grp);
 void sysfs_remove_group(struct kobject *kobj,
@@ -433,6 +435,12 @@ static inline int sysfs_create_groups(struct kobject *kobj,
 	return 0;
 }
 
+static inline int sysfs_update_groups(struct kobject *kobj,
+				      const struct attribute_group **groups)
+{
+	return 0;
+}
+
 static inline int sysfs_update_group(struct kobject *kobj,
 				const struct attribute_group *grp)
 {
author reviewer
#3 lore raw

PATCH v2 2/9 perf: Add attr_groups_update into struct pmu

In reply to Jiri Olsa

Adding attr_update attribute group into pmu, to allow having multiple attribute groups for same group name.

This will allow us to update "events" or "format" directories with attributes that depend on various HW conditions.

For example having group_format_extra group that updates "format" directory only if pmu version is 2 and higher:

  static umode_t
  exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
  {
         return x86_pmu.version >= 2 ? attr->mode : 0;
  }

  static struct attribute_group group_format_extra = {
         .name       = "format",
         .is_visible = exra_is_visible,
  };
---
 include/linux/perf_event.h | 1 +
 kernel/events/core.c       | 6 ++++++
 2 files changed, 7 insertions(+)
include/linux/perf_event.h +1 -0
index f3864e1c5569..cb5f07d50edb 100644
@@ -255,6 +255,7 @@ struct pmu {
 	struct module			*module;
 	struct device			*dev;
 	const struct attribute_group	**attr_groups;
+	const struct attribute_group	**attr_update;
 	const char			*name;
 	int				type;
 
kernel/events/core.c +6 -0
index abbd4b3b96c2..21ef9b843af0 100644
@@ -9874,6 +9874,12 @@ static int pmu_dev_alloc(struct pmu *pmu)
 	if (ret)
 		goto del_dev;
 
+	if (pmu->attr_update)
+		ret = sysfs_update_groups(&pmu->dev->kobj, pmu->attr_update);
+
+	if (ret)
+		goto del_dev;
+
 out:
 	return ret;
 
Signature · 1 line
2.20.1
#4 lore raw

[tip:perf/core] perf/core: Add attr_groups_update into struct pmu

perf/core: Add attr_groups_update into struct pmu
Commit-ID:  f3a3a8257e5a1a5e67cbb1afdbc4c1c6a26f1b22
Gitweb:     https://git.kernel.org/tip/f3a3a8257e5a1a5e67cbb1afdbc4c1c6a26f1b22
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:11 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:21 +0200

perf/core: Add attr_groups_update into struct pmu

Adding attr_update attribute group into pmu, to allow having multiple attribute groups for same group name.

This will allow us to update "events" or "format" directories with attributes that depend on various HW conditions.

For example having group_format_extra group that updates "format" directory only if pmu version is 2 and higher:

  static umode_t
  exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
  {
         return x86_pmu.version >= 2 ? attr->mode : 0;
  }

  static struct attribute_group group_format_extra = {
         .name       = "format",
         .is_visible = exra_is_visible,
  };
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/perf_event.h | 1 +
 kernel/events/core.c       | 6 ++++++
 2 files changed, 7 insertions(+)
include/linux/perf_event.h +1 -0
index 0ab99c7b652d..3dc01cf98e16 100644
@@ -255,6 +255,7 @@ struct pmu {
 	struct module			*module;
 	struct device			*dev;
 	const struct attribute_group	**attr_groups;
+	const struct attribute_group	**attr_update;
 	const char			*name;
 	int				type;
 
kernel/events/core.c +6 -0
index 3005c80f621d..118ad1aef6af 100644
@@ -9874,6 +9874,12 @@ static int pmu_dev_alloc(struct pmu *pmu)
 	if (ret)
 		goto del_dev;
 
+	if (pmu->attr_update)
+		ret = sysfs_update_groups(&pmu->dev->kobj, pmu->attr_update);
+
+	if (ret)
+		goto del_dev;
+
 out:
 	return ret;
 
author reviewer
#5 lore raw

PATCH v2 3/9 perf/x86: Get rid of x86_pmu::event_attrs

In reply to Jiri Olsa

Nobody is using that.

---
 arch/x86/events/core.c       | 3 ---
 arch/x86/events/perf_event.h | 1 -
 2 files changed, 4 deletions(-)
arch/x86/events/core.c +0 -3
index de1a924a4914..f2be5d2a62fe 100644
@@ -1850,9 +1850,6 @@ static int __init init_hw_perf_events(void)
 			x86_pmu_caps_group.attrs = tmp;
 	}
 
-	if (x86_pmu.event_attrs)
-		x86_pmu_events_group.attrs = x86_pmu.event_attrs;
-
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 	else
arch/x86/events/perf_event.h +0 -1
index 07fc84bb85c1..3f87cb4d7585 100644
@@ -631,7 +631,6 @@ struct x86_pmu {
 	int		attr_rdpmc_broken;
 	int		attr_rdpmc;
 	struct attribute **format_attrs;
-	struct attribute **event_attrs;
 	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
Signature · 1 line
2.20.1
#6 lore raw

[tip:perf/core] perf/x86: Get rid of x86_pmu::event_attrs

perf/x86: Get rid of x86_pmu::event_attrs
Commit-ID:  21b0dbc5e8b050e40a93a1f8cdef277502a4fc90
Gitweb:     https://git.kernel.org/tip/21b0dbc5e8b050e40a93a1f8cdef277502a4fc90
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:12 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:22 +0200

perf/x86: Get rid of x86_pmu::event_attrs

Nobody is using that.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/core.c       | 3 ---
 arch/x86/events/perf_event.h | 1 -
 2 files changed, 4 deletions(-)
arch/x86/events/core.c +0 -3
index f315425d8468..0c5a2c783374 100644
@@ -1850,9 +1850,6 @@ static int __init init_hw_perf_events(void)
 			x86_pmu_caps_group.attrs = tmp;
 	}
 
-	if (x86_pmu.event_attrs)
-		x86_pmu_events_group.attrs = x86_pmu.event_attrs;
-
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 	else
arch/x86/events/perf_event.h +0 -1
index a6ac2f4f76fc..1599008f156a 100644
@@ -631,7 +631,6 @@ struct x86_pmu {
 	int		attr_rdpmc_broken;
 	int		attr_rdpmc;
 	struct attribute **format_attrs;
-	struct attribute **event_attrs;
 	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
author reviewer
#7 lore raw

PATCH v2 4/9 perf/x86: Use the new pmu::update_attrs attribute group

In reply to Jiri Olsa

Using the new pmu::update_attrs attribute group to create detected events for x86_pmu.

Moving the topdown/memory/tsx attributes to separate attribute groups with specific is_visible functions.

---
 arch/x86/events/core.c       | 10 +----
 arch/x86/events/intel/core.c | 86 ++++++++++++++++++++----------------
 arch/x86/events/perf_event.h |  2 +-
 3 files changed, 52 insertions(+), 46 deletions(-)
arch/x86/events/core.c +2 -8
index f2be5d2a62fe..a43d8d1e8590 100644
@@ -1855,14 +1855,6 @@ static int __init init_hw_perf_events(void)
 	else
 		filter_events(x86_pmu_events_group.attrs);
 
-	if (x86_pmu.cpu_events) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_events_group.attrs, x86_pmu.cpu_events);
-		if (!WARN_ON(!tmp))
-			x86_pmu_events_group.attrs = tmp;
-	}
-
 	if (x86_pmu.attrs) {
 		struct attribute **tmp;
 
@@ -1871,6 +1863,8 @@ static int __init init_hw_perf_events(void)
 			x86_pmu_attr_group.attrs = tmp;
 	}
 
+	pmu.attr_update = x86_pmu.attr_update;
+
 	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);
arch/x86/events/intel/core.c +49 -37

171 lines not on this page · raw message

arch/x86/events/perf_event.h +1 -1
index 3f87cb4d7585..7dd91607b5fa 100644
@@ -634,7 +634,7 @@ struct x86_pmu {
 	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
-	struct attribute **cpu_events;
+	const struct attribute_group **attr_update;
 
 	unsigned long	attr_freeze_on_smi;
 	struct attribute **attrs;
Signature · 1 line
2.20.1
#8 lore raw

[tip:perf/core] perf/x86: Use the new pmu::update_attrs attribute group

perf/x86: Use the new pmu::update_attrs attribute group
Commit-ID:  baa0c83363c7aafb04734acf4ac252be8e13bd88
Gitweb:     https://git.kernel.org/tip/baa0c83363c7aafb04734acf4ac252be8e13bd88
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:13 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:23 +0200

perf/x86: Use the new pmu::update_attrs attribute group

Using the new pmu::update_attrs attribute group to create detected events for x86_pmu.

Moving the topdown/memory/tsx attributes to separate attribute groups with specific is_visible functions.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/core.c       | 10 ++----
 arch/x86/events/intel/core.c | 86 +++++++++++++++++++++++++-------------------
 arch/x86/events/perf_event.h |  2 +-
 3 files changed, 52 insertions(+), 46 deletions(-)
arch/x86/events/core.c +2 -8
index 0c5a2c783374..db815ceb5017 100644
@@ -1855,14 +1855,6 @@ static int __init init_hw_perf_events(void)
 	else
 		filter_events(x86_pmu_events_group.attrs);
 
-	if (x86_pmu.cpu_events) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_events_group.attrs, x86_pmu.cpu_events);
-		if (!WARN_ON(!tmp))
-			x86_pmu_events_group.attrs = tmp;
-	}
-
 	if (x86_pmu.attrs) {
 		struct attribute **tmp;
 
@@ -1871,6 +1863,8 @@ static int __init init_hw_perf_events(void)
 			x86_pmu_attr_group.attrs = tmp;
 	}
 
+	pmu.attr_update = x86_pmu.attr_update;
+
 	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);
arch/x86/events/intel/core.c +49 -37

171 lines not on this page · raw message

arch/x86/events/perf_event.h +1 -1
index 1599008f156a..629b313d8b8b 100644
@@ -634,7 +634,7 @@ struct x86_pmu {
 	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
-	struct attribute **cpu_events;
+	const struct attribute_group **attr_update;
 
 	unsigned long	attr_freeze_on_smi;
 	struct attribute **attrs;
author reviewer
#9 lore raw

PATCH v2 5/9 perf/x86: Add is_visible attribute_group callback for base events

In reply to Jiri Olsa

We dont need to pre-filter out unsupported base events, we can just use its group's is_visible function to do this.

---
 arch/x86/events/core.c | 53 ++++++++++++------------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)
arch/x86/events/core.c +15 -38
index a43d8d1e8590..a7aa72afcc7f 100644
@@ -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,24 @@ 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);
+	/* str trumps id */
+	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 +1831,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;
Signature · 1 line
2.20.1
#10 lore raw

[tip:perf/core] perf/x86: Add is_visible attribute_group callback for base events

perf/x86: Add is_visible attribute_group callback for base events
Commit-ID:  3d5672735b2348f5b13679a27f90c0847d22125d
Gitweb:     https://git.kernel.org/tip/3d5672735b2348f5b13679a27f90c0847d22125d
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:14 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:23 +0200

perf/x86: Add is_visible attribute_group callback for base events

We dont need to pre-filter out unsupported base events, we can just use its group's is_visible function to do this.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/core.c | 53 ++++++++++++++------------------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)
arch/x86/events/core.c +15 -38
index db815ceb5017..b831091d4c10 100644
@@ -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,24 @@ 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);
+	/* str trumps id */
+	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 +1831,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;
author reviewer
#11 lore raw

PATCH v2 6/9 perf/x86: Use update attribute groups for caps

In reply to Jiri Olsa

Using the new pmu::update_attrs attribute group for "caps" directory.

---
 arch/x86/events/core.c       |  8 --------
 arch/x86/events/intel/core.c | 25 ++++++++++++++++++++-----
 arch/x86/events/perf_event.h |  1 -
 3 files changed, 20 insertions(+), 14 deletions(-)
arch/x86/events/core.c +0 -8
index a7aa72afcc7f..7f1bb5fd1fc4 100644
@@ -1821,14 +1821,6 @@ static int __init init_hw_perf_events(void)
 
 	x86_pmu_format_group.attrs = x86_pmu.format_attrs;
 
-	if (x86_pmu.caps_attrs) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_caps_group.attrs, x86_pmu.caps_attrs);
-		if (!WARN_ON(!tmp))
-			x86_pmu_caps_group.attrs = tmp;
-	}
-
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 
arch/x86/events/intel/core.c +20 -5
index fd7d36611e22..fff73623cf80 100644
@@ -4402,6 +4402,12 @@ pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.pebs ? attr->mode : 0;
 }
 
+static umode_t
+lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.lbr_nr ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4416,10 +4422,23 @@ static struct attribute_group group_events_tsx = {
 	.is_visible = tsx_is_visible,
 };
 
+static struct attribute_group group_caps_gen = {
+	.name  = "caps",
+	.attrs = intel_pmu_caps_attrs,
+};
+
+static struct attribute_group group_caps_lbr = {
+	.name       = "caps",
+	.attrs	    = lbr_attrs,
+	.is_visible = lbr_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
 	&group_events_tsx,
+	&group_caps_gen,
+	&group_caps_lbr,
 	NULL,
 };
 
@@ -5046,12 +5065,8 @@ __init int intel_pmu_init(void)
 			x86_pmu.lbr_nr = 0;
 	}
 
-	x86_pmu.caps_attrs = intel_pmu_caps_attrs;
-
-	if (x86_pmu.lbr_nr) {
-		x86_pmu.caps_attrs = merge_attr(x86_pmu.caps_attrs, lbr_attrs);
+	if (x86_pmu.lbr_nr)
 		pr_cont("%d-deep LBR, ", x86_pmu.lbr_nr);
-	}
 
 	/*
 	 * Access extra MSR may cause #GP under certain circumstances.
arch/x86/events/perf_event.h +0 -1
index 7dd91607b5fa..1e3a7d74ea49 100644
@@ -631,7 +631,6 @@ struct x86_pmu {
 	int		attr_rdpmc_broken;
 	int		attr_rdpmc;
 	struct attribute **format_attrs;
-	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
 	const struct attribute_group **attr_update;
Signature · 1 line
2.20.1
#12 lore raw

[tip:perf/core] perf/x86: Use update attribute groups for caps

perf/x86: Use update attribute groups for caps
Commit-ID:  1f157286829c78c0bd8e495951a5c098d88e3d1a
Gitweb:     https://git.kernel.org/tip/1f157286829c78c0bd8e495951a5c098d88e3d1a
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:15 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:24 +0200

perf/x86: Use update attribute groups for caps

Using the new pmu::update_attrs attribute group for "caps" directory.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/core.c       |  8 --------
 arch/x86/events/intel/core.c | 25 ++++++++++++++++++++-----
 arch/x86/events/perf_event.h |  1 -
 3 files changed, 20 insertions(+), 14 deletions(-)
arch/x86/events/core.c +0 -8
index b831091d4c10..dd0996ba75c3 100644
@@ -1821,14 +1821,6 @@ static int __init init_hw_perf_events(void)
 
 	x86_pmu_format_group.attrs = x86_pmu.format_attrs;
 
-	if (x86_pmu.caps_attrs) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_caps_group.attrs, x86_pmu.caps_attrs);
-		if (!WARN_ON(!tmp))
-			x86_pmu_caps_group.attrs = tmp;
-	}
-
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 
arch/x86/events/intel/core.c +20 -5
index 600e87055ba9..d4002e71a0b8 100644
@@ -4411,6 +4411,12 @@ pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.pebs ? attr->mode : 0;
 }
 
+static umode_t
+lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.lbr_nr ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4425,10 +4431,23 @@ static struct attribute_group group_events_tsx = {
 	.is_visible = tsx_is_visible,
 };
 
+static struct attribute_group group_caps_gen = {
+	.name  = "caps",
+	.attrs = intel_pmu_caps_attrs,
+};
+
+static struct attribute_group group_caps_lbr = {
+	.name       = "caps",
+	.attrs	    = lbr_attrs,
+	.is_visible = lbr_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
 	&group_events_tsx,
+	&group_caps_gen,
+	&group_caps_lbr,
 	NULL,
 };
 
@@ -5055,12 +5074,8 @@ __init int intel_pmu_init(void)
 			x86_pmu.lbr_nr = 0;
 	}
 
-	x86_pmu.caps_attrs = intel_pmu_caps_attrs;
-
-	if (x86_pmu.lbr_nr) {
-		x86_pmu.caps_attrs = merge_attr(x86_pmu.caps_attrs, lbr_attrs);
+	if (x86_pmu.lbr_nr)
 		pr_cont("%d-deep LBR, ", x86_pmu.lbr_nr);
-	}
 
 	/*
 	 * Access extra MSR may cause #GP under certain circumstances.
arch/x86/events/perf_event.h +0 -1
index 629b313d8b8b..1da9b6f0b279 100644
@@ -631,7 +631,6 @@ struct x86_pmu {
 	int		attr_rdpmc_broken;
 	int		attr_rdpmc;
 	struct attribute **format_attrs;
-	struct attribute **caps_attrs;
 
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
 	const struct attribute_group **attr_update;
author reviewer
#13 lore raw

PATCH v2 7/9 perf/x86: Use update attribute groups for extra format

In reply to Jiri Olsa

Using the new pmu::update_attrs attribute group for extra "format" directory.

---
 arch/x86/events/intel/core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
arch/x86/events/intel/core.c +13 -5
index fff73623cf80..524b390a2c26 100644
@@ -4408,6 +4408,12 @@ lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.lbr_nr ? attr->mode : 0;
 }
 
+static umode_t
+exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.version >= 2 ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4433,12 +4439,18 @@ static struct attribute_group group_caps_lbr = {
 	.is_visible = lbr_is_visible,
 };
 
+static struct attribute_group group_format_extra = {
+	.name       = "format",
+	.is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
 	&group_events_tsx,
 	&group_caps_gen,
 	&group_caps_lbr,
+	&group_format_extra,
 	NULL,
 };
 
@@ -5007,15 +5019,11 @@ __init int intel_pmu_init(void)
 
 	snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name);
 
-	if (version >= 2 && extra_attr) {
-		x86_pmu.format_attrs = merge_attr(intel_arch3_formats_attr,
-						  extra_attr);
-		WARN_ON(!x86_pmu.format_attrs);
-	}
 
 	group_events_td.attrs  = td_attr;
 	group_events_mem.attrs = mem_attr;
 	group_events_tsx.attrs = tsx_attr;
+	group_format_extra.attrs = extra_attr;
 
 	x86_pmu.attr_update = attr_update;
 
Signature · 1 line
2.20.1
#14 lore raw

[tip:perf/core] perf/x86: Use update attribute groups for extra format

perf/x86: Use update attribute groups for extra format
Commit-ID:  3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Gitweb:     https://git.kernel.org/tip/3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:16 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:25 +0200

perf/x86: Use update attribute groups for extra format

Using the new pmu::update_attrs attribute group for extra "format" directory.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/intel/core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
arch/x86/events/intel/core.c +13 -5
index d4002e71a0b8..de4779f44737 100644
@@ -4417,6 +4417,12 @@ lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.lbr_nr ? attr->mode : 0;
 }
 
+static umode_t
+exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.version >= 2 ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4442,12 +4448,18 @@ static struct attribute_group group_caps_lbr = {
 	.is_visible = lbr_is_visible,
 };
 
+static struct attribute_group group_format_extra = {
+	.name       = "format",
+	.is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
 	&group_events_tsx,
 	&group_caps_gen,
 	&group_caps_lbr,
+	&group_format_extra,
 	NULL,
 };
 
@@ -5016,15 +5028,11 @@ __init int intel_pmu_init(void)
 
 	snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name);
 
-	if (version >= 2 && extra_attr) {
-		x86_pmu.format_attrs = merge_attr(intel_arch3_formats_attr,
-						  extra_attr);
-		WARN_ON(!x86_pmu.format_attrs);
-	}
 
 	group_events_td.attrs  = td_attr;
 	group_events_mem.attrs = mem_attr;
 	group_events_tsx.attrs = tsx_attr;
+	group_format_extra.attrs = extra_attr;
 
 	x86_pmu.attr_update = attr_update;
 
author reviewer
#15 lore raw

PATCH v2 8/9 perf/x86/intel: Use update attributes for skylake format

In reply to Jiri Olsa

Using the new pmu::update_attrs attribute group for skylake specific format attributes.

---
 arch/x86/events/intel/core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/x86/events/intel/core.c +10 -5
index 524b390a2c26..7db858c3bbec 100644
@@ -4444,6 +4444,11 @@ static struct attribute_group group_format_extra = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_format_extra_skl = {
+	.name       = "format",
+	.is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
@@ -4451,6 +4456,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_gen,
 	&group_caps_lbr,
 	&group_format_extra,
+	&group_format_extra_skl,
 	NULL,
 };
 
@@ -4458,11 +4464,11 @@ static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
+	struct attribute **extra_skl_attr = &empty_attrs;
 	struct attribute **extra_attr = &empty_attrs;
 	struct attribute **td_attr    = &empty_attrs;
 	struct attribute **mem_attr   = &empty_attrs;
 	struct attribute **tsx_attr   = &empty_attrs;
-	struct attribute **to_free = NULL;
 	union cpuid10_edx edx;
 	union cpuid10_eax eax;
 	union cpuid10_ebx ebx;
@@ -4950,8 +4956,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
-		extra_attr = merge_attr(extra_attr, skl_format_attr);
-		to_free = extra_attr;
+		extra_skl_attr = skl_format_attr;
 		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
@@ -4989,7 +4994,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.get_event_constraints = icl_get_event_constraints;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
-		extra_attr = merge_attr(extra_attr, skl_format_attr);
+		extra_skl_attr = skl_format_attr;
 		mem_attr = icl_events_attrs;
 		tsx_attr = icl_tsx_events_attrs;
 		x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xca, .umask=0x02);
@@ -5024,6 +5029,7 @@ __init int intel_pmu_init(void)
 	group_events_mem.attrs = mem_attr;
 	group_events_tsx.attrs = tsx_attr;
 	group_format_extra.attrs = extra_attr;
+	group_format_extra_skl.attrs = extra_skl_attr;
 
 	x86_pmu.attr_update = attr_update;
 
@@ -5104,7 +5110,6 @@ __init int intel_pmu_init(void)
 	if (x86_pmu.counter_freezing)
 		x86_pmu.handle_irq = intel_pmu_handle_irq_v4;
 
-	kfree(to_free);
 	return 0;
 }
 
Signature · 1 line
2.20.1
#16 lore raw

[tip:perf/core] perf/x86/intel: Use update attributes for skylake format

perf/x86/intel: Use update attributes for skylake format
Commit-ID:  b657688069a24c3c81b6de22e0e57e1785d9211f
Gitweb:     https://git.kernel.org/tip/b657688069a24c3c81b6de22e0e57e1785d9211f
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:17 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:26 +0200

perf/x86/intel: Use update attributes for skylake format

Using the new pmu::update_attrs attribute group for skylake specific format attributes.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/intel/core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/x86/events/intel/core.c +10 -5
index de4779f44737..3bc967be7c7b 100644
@@ -4453,6 +4453,11 @@ static struct attribute_group group_format_extra = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_format_extra_skl = {
+	.name       = "format",
+	.is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
@@ -4460,6 +4465,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_gen,
 	&group_caps_lbr,
 	&group_format_extra,
+	&group_format_extra_skl,
 	NULL,
 };
 
@@ -4467,11 +4473,11 @@ static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
+	struct attribute **extra_skl_attr = &empty_attrs;
 	struct attribute **extra_attr = &empty_attrs;
 	struct attribute **td_attr    = &empty_attrs;
 	struct attribute **mem_attr   = &empty_attrs;
 	struct attribute **tsx_attr   = &empty_attrs;
-	struct attribute **to_free = NULL;
 	union cpuid10_edx edx;
 	union cpuid10_eax eax;
 	union cpuid10_ebx ebx;
@@ -4959,8 +4965,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
-		extra_attr = merge_attr(extra_attr, skl_format_attr);
-		to_free = extra_attr;
+		extra_skl_attr = skl_format_attr;
 		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
@@ -4998,7 +5003,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.get_event_constraints = icl_get_event_constraints;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
-		extra_attr = merge_attr(extra_attr, skl_format_attr);
+		extra_skl_attr = skl_format_attr;
 		mem_attr = icl_events_attrs;
 		tsx_attr = icl_tsx_events_attrs;
 		x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xca, .umask=0x02);
@@ -5033,6 +5038,7 @@ __init int intel_pmu_init(void)
 	group_events_mem.attrs = mem_attr;
 	group_events_tsx.attrs = tsx_attr;
 	group_format_extra.attrs = extra_attr;
+	group_format_extra_skl.attrs = extra_skl_attr;
 
 	x86_pmu.attr_update = attr_update;
 
@@ -5113,7 +5119,6 @@ __init int intel_pmu_init(void)
 	if (x86_pmu.counter_freezing)
 		x86_pmu.handle_irq = intel_pmu_handle_irq_v4;
 
-	kfree(to_free);
 	return 0;
 }
 
author reviewer
#17 lore raw

PATCH v2 9/9 perf/x86: Use update attribute groups for default attributes

In reply to Jiri Olsa

Using the new pmu::update_attrs attribute group for default attributes - freeze_on_smi, allow_tsx_force_abort.

---
 arch/x86/events/core.c       | 34 ----------------------------------
 arch/x86/events/intel/core.c |  9 +++++----
 arch/x86/events/perf_event.h |  3 ---
 3 files changed, 5 insertions(+), 41 deletions(-)
arch/x86/events/core.c +0 -34
index 7f1bb5fd1fc4..ce26da2ef11e 100644
@@ -1618,32 +1618,6 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {
 	.attrs = NULL,
 };
 
-/* Merge two pointer arrays */
-__init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
-{
-	struct attribute **new;
-	int j, i;
-
-	for (j = 0; a && a[j]; j++)
-		;
-	for (i = 0; b && b[i]; i++)
-		j++;
-	j++;
-
-	new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
-	if (!new)
-		return NULL;
-
-	j = 0;
-	for (i = 0; a && a[i]; i++)
-		new[j++] = a[i];
-	for (i = 0; b && b[i]; i++)
-		new[j++] = b[i];
-	new[j] = NULL;
-
-	return new;
-}
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
 {
 	struct perf_pmu_events_attr *pmu_attr = \
@@ -1824,14 +1798,6 @@ static int __init init_hw_perf_events(void)
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 
-	if (x86_pmu.attrs) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_attr_group.attrs, x86_pmu.attrs);
-		if (!WARN_ON(!tmp))
-			x86_pmu_attr_group.attrs = tmp;
-	}
-
 	pmu.attr_update = x86_pmu.attr_update;
 
 	pr_info("... version:                %d\n",     x86_pmu.version);
arch/x86/events/intel/core.c +5 -4
index 7db858c3bbec..e721be25abfb 100644
@@ -3888,8 +3888,6 @@ static __initconst const struct x86_pmu core_pmu = {
 	.check_period		= intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -3921,8 +3919,6 @@ static __initconst const struct x86_pmu intel_pmu = {
 	.format_attrs		= intel_arch3_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
 
-	.attrs			= intel_pmu_attrs,
-
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
@@ -4449,6 +4445,10 @@ static struct attribute_group group_format_extra_skl = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+	.attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
@@ -4457,6 +4457,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_lbr,
 	&group_format_extra,
 	&group_format_extra_skl,
+	&group_default,
 	NULL,
 };
 
arch/x86/events/perf_event.h +0 -3
index 1e3a7d74ea49..7ae2912f16de 100644
@@ -636,7 +636,6 @@ struct x86_pmu {
 	const struct attribute_group **attr_update;
 
 	unsigned long	attr_freeze_on_smi;
-	struct attribute **attrs;
 
 	/*
 	 * CPU Hotplug hooks
@@ -903,8 +902,6 @@ 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);
 
-struct attribute **merge_attr(struct attribute **a, struct attribute **b);
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
 			  char *page);
 ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.20.1
maintainer
#18 lore raw

Re: [PATCH 9/9] perf/x86: Use update attribute groups for default attributes

Quoted 39 lines · Jiri Olsa

Using the new pmu::update_attrs attribute group for default attributes - freeze_on_smi, allow_tsx_force_abort.

arch/x86/events/intel/core.c +4 -4
index 7db858c3bbec..e721be25abfb 100644
@@ -3888,8 +3888,6 @@ static __initconst const struct x86_pmu core_pmu = {
 	.check_period		= intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -3921,8 +3919,6 @@ static __initconst const struct x86_pmu intel_pmu = {
 	.format_attrs		= intel_arch3_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
 
-	.attrs			= intel_pmu_attrs,
-
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
@@ -4449,6 +4445,10 @@ static struct attribute_group group_format_extra_skl = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+	.attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,

arch/x86/events/intel/core.c static const struct attribute_group *attr_update[] = { · line 4462

Quoted 6 lines
arch/x86/events/intel/core.c +1 -0
@@ -4457,6 +4457,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_lbr,
 	&group_format_extra,
 	&group_format_extra_skl,
+	&group_default,
 	NULL,
 };

Ah, I would have expected to see this somewhat dodgy hack go away too:

	static struct attribute *intel_pmu_attrs[] = {
		&dev_attr_freeze_on_smi.attr,
		NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
		NULL,
	};

	intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;

That just begs for a .visislbe too, right?

#19 lore raw

Re: [PATCH 9/9] perf/x86: Use update attribute groups for default attributes

Quoted 59 lines · Peter Zijlstra
Quoted 39 lines · Jiri Olsa

Using the new pmu::update_attrs attribute group for default attributes - freeze_on_smi, allow_tsx_force_abort.

arch/x86/events/intel/core.c +4 -4
index 7db858c3bbec..e721be25abfb 100644
@@ -3888,8 +3888,6 @@ static __initconst const struct x86_pmu core_pmu = {
 	.check_period		= intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -3921,8 +3919,6 @@ static __initconst const struct x86_pmu intel_pmu = {
 	.format_attrs		= intel_arch3_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
 
-	.attrs			= intel_pmu_attrs,
-
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
@@ -4449,6 +4445,10 @@ static struct attribute_group group_format_extra_skl = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+	.attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,

arch/x86/events/intel/core.c static const struct attribute_group *attr_update[] = { · line 4462

Quoted 6 lines
arch/x86/events/intel/core.c +1 -0
@@ -4457,6 +4457,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_lbr,
 	&group_format_extra,
 	&group_format_extra_skl,
+	&group_default,
 	NULL,
 };

Ah, I would have expected to see this somewhat dodgy hack go away too:

	static struct attribute *intel_pmu_attrs[] = {
		&dev_attr_freeze_on_smi.attr,
		NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
		NULL,
	};

	intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
Quoted 1 line

That just begs for a .visislbe too, right?

right, we could do that.. I'll check on it and send separate patch

thanks,
jirka

#20 lore raw

PATCH 1/1 perf/x86/intel: Use is_visible callback for default group

In reply to Peter Zijlstra
Quoted 59 lines · Peter Zijlstra
Quoted 39 lines · Jiri Olsa

Using the new pmu::update_attrs attribute group for default attributes - freeze_on_smi, allow_tsx_force_abort.

arch/x86/events/intel/core.c +4 -4
index 7db858c3bbec..e721be25abfb 100644
@@ -3888,8 +3888,6 @@ static __initconst const struct x86_pmu core_pmu = {
 	.check_period		= intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -3921,8 +3919,6 @@ static __initconst const struct x86_pmu intel_pmu = {
 	.format_attrs		= intel_arch3_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
 
-	.attrs			= intel_pmu_attrs,
-
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
@@ -4449,6 +4445,10 @@ static struct attribute_group group_format_extra_skl = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+	.attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,

arch/x86/events/intel/core.c static const struct attribute_group *attr_update[] = { · line 4462

Quoted 6 lines
arch/x86/events/intel/core.c +1 -0
@@ -4457,6 +4457,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_lbr,
 	&group_format_extra,
 	&group_format_extra_skl,
+	&group_default,
 	NULL,
 };

Ah, I would have expected to see this somewhat dodgy hack go away too:

	static struct attribute *intel_pmu_attrs[] = {
		&dev_attr_freeze_on_smi.attr,
		NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
		NULL,
	};

	intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
Quoted 1 line

That just begs for a .visislbe too, right?

hi,
I added the is_visible callback (below), but I dont have the skylake to test this, so I only verified this wouldn't break freeze_on_smi on my server..

any chance you could test this?

thanks,
jirka

---
It's preffered to use group's is_visible callback, so we do not need to use condition attribute assignment.

Cc Stephane Eranian <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
arch/x86/events/intel/core.c +12 -3
index 85afe7e98c7d..cfd61b71136d 100644
@@ -4386,7 +4386,7 @@ static DEVICE_ATTR(allow_tsx_force_abort, 0644,
 
 static struct attribute *intel_pmu_attrs[] = {
 	&dev_attr_freeze_on_smi.attr,
-	NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
+	&dev_attr_allow_tsx_force_abort.attr,
 	NULL,
 };
 
@@ -4414,6 +4414,15 @@ exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.version >= 2 ? attr->mode : 0;
 }
 
+static umode_t
+default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	if (attr == &dev_attr_allow_tsx_force_abort.attr)
+		return x86_pmu.flags & PMU_FL_TFA ? attr->mode : 0;
+
+	return attr->mode;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4450,7 +4459,8 @@ static struct attribute_group group_format_extra_skl = {
 };
 
 static struct attribute_group group_default = {
-	.attrs = intel_pmu_attrs,
+	.attrs      = intel_pmu_attrs,
+	.is_visible = default_is_visible,
 };
 
 static const struct attribute_group *attr_update[] = {
@@ -4973,7 +4983,6 @@ __init int intel_pmu_init(void)
 			x86_pmu.get_event_constraints = tfa_get_event_constraints;
 			x86_pmu.enable_all = intel_tfa_pmu_enable_all;
 			x86_pmu.commit_scheduling = intel_tfa_commit_scheduling;
-			intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
 		}
 
 		pr_cont("Skylake events, ");
Signature · 1 line
2.20.1
#21 lore raw

Re: [PATCH] perf/x86/intel: Use is_visible callback for default group

On Fri, May 24, 2019 at 03:21:52PM +0200, Jiri Olsa wrote:

SNIP

ping

jirka

Quoted 62 lines

---
It's preffered to use group's is_visible callback, so we do not need to use condition attribute assignment.

Cc Stephane Eranian <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
arch/x86/events/intel/core.c +12 -3
index 85afe7e98c7d..cfd61b71136d 100644
@@ -4386,7 +4386,7 @@ static DEVICE_ATTR(allow_tsx_force_abort, 0644,
 
 static struct attribute *intel_pmu_attrs[] = {
 	&dev_attr_freeze_on_smi.attr,
-	NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
+	&dev_attr_allow_tsx_force_abort.attr,
 	NULL,
 };
 
@@ -4414,6 +4414,15 @@ exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.version >= 2 ? attr->mode : 0;
 }
 
+static umode_t
+default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	if (attr == &dev_attr_allow_tsx_force_abort.attr)
+		return x86_pmu.flags & PMU_FL_TFA ? attr->mode : 0;
+
+	return attr->mode;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4450,7 +4459,8 @@ static struct attribute_group group_format_extra_skl = {
 };
 
 static struct attribute_group group_default = {
-	.attrs = intel_pmu_attrs,
+	.attrs      = intel_pmu_attrs,
+	.is_visible = default_is_visible,
 };
 
 static const struct attribute_group *attr_update[] = {
@@ -4973,7 +4983,6 @@ __init int intel_pmu_init(void)
 			x86_pmu.get_event_constraints = tfa_get_event_constraints;
 			x86_pmu.enable_all = intel_tfa_pmu_enable_all;
 			x86_pmu.commit_scheduling = intel_tfa_commit_scheduling;
-			intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
 		}
 
 		pr_cont("Skylake events, ");
Signature · 1 line
2.20.1
maintainer
#22 lore raw

Re: [PATCH] perf/x86/intel: Use is_visible callback for default group

Quoted 5 lines · Jiri Olsa

On Fri, May 24, 2019 at 03:21:52PM +0200, Jiri Olsa wrote:

SNIP

ping

Well, it looks about right; but last time you asked if someone could test, and I've no idea. I don't think I have any testboxes that are affected by this stuff.

I can just merge it I suppose, we'll see if anybody complains :-)

Quoted 62 lines
Quoted 62 lines

---
It's preffered to use group's is_visible callback, so we do not need to use condition attribute assignment.

Cc Stephane Eranian <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
arch/x86/events/intel/core.c +12 -3
index 85afe7e98c7d..cfd61b71136d 100644
@@ -4386,7 +4386,7 @@ static DEVICE_ATTR(allow_tsx_force_abort, 0644,
 
 static struct attribute *intel_pmu_attrs[] = {
 	&dev_attr_freeze_on_smi.attr,
-	NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
+	&dev_attr_allow_tsx_force_abort.attr,
 	NULL,
 };
 
@@ -4414,6 +4414,15 @@ exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.version >= 2 ? attr->mode : 0;
 }
 
+static umode_t
+default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	if (attr == &dev_attr_allow_tsx_force_abort.attr)
+		return x86_pmu.flags & PMU_FL_TFA ? attr->mode : 0;
+
+	return attr->mode;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4450,7 +4459,8 @@ static struct attribute_group group_format_extra_skl = {
 };
 
 static struct attribute_group group_default = {
-	.attrs = intel_pmu_attrs,
+	.attrs      = intel_pmu_attrs,
+	.is_visible = default_is_visible,
 };
 
 static const struct attribute_group *attr_update[] = {
@@ -4973,7 +4983,6 @@ __init int intel_pmu_init(void)
 			x86_pmu.get_event_constraints = tfa_get_event_constraints;
 			x86_pmu.enable_all = intel_tfa_pmu_enable_all;
 			x86_pmu.commit_scheduling = intel_tfa_commit_scheduling;
-			intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
 		}
 
 		pr_cont("Skylake events, ");
Signature · 1 line
2.20.1
#23 lore raw

[tip:perf/core] perf/x86/intel: Use ->is_visible callback for default group

In reply to Jiri Olsa
perf/x86/intel: Use ->is_visible callback for default group
Commit-ID:  b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Gitweb:     https://git.kernel.org/tip/b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Author:     Jiri Olsa <[email protected]>
AuthorDate: Fri, 24 May 2019 15:21:52 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 17 Jun 2019 12:36:23 +0200

perf/x86/intel: Use ->is_visible callback for default group

It's preffered to use group's ->is_visible callback, so we do not need to use condition attribute assignment.

---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
arch/x86/events/intel/core.c +12 -3
index 4377bf6a6f82..5e6ae481dee7 100644
@@ -4391,7 +4391,7 @@ static DEVICE_ATTR(allow_tsx_force_abort, 0644,
 
 static struct attribute *intel_pmu_attrs[] = {
 	&dev_attr_freeze_on_smi.attr,
-	NULL, /* &dev_attr_allow_tsx_force_abort.attr.attr */
+	&dev_attr_allow_tsx_force_abort.attr,
 	NULL,
 };
 
@@ -4419,6 +4419,15 @@ exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 	return x86_pmu.version >= 2 ? attr->mode : 0;
 }
 
+static umode_t
+default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	if (attr == &dev_attr_allow_tsx_force_abort.attr)
+		return x86_pmu.flags & PMU_FL_TFA ? attr->mode : 0;
+
+	return attr->mode;
+}
+
 static struct attribute_group group_events_td  = {
 	.name = "events",
 };
@@ -4455,7 +4464,8 @@ static struct attribute_group group_format_extra_skl = {
 };
 
 static struct attribute_group group_default = {
-	.attrs = intel_pmu_attrs,
+	.attrs      = intel_pmu_attrs,
+	.is_visible = default_is_visible,
 };
 
 static const struct attribute_group *attr_update[] = {
@@ -4979,7 +4989,6 @@ __init int intel_pmu_init(void)
 			x86_pmu.get_event_constraints = tfa_get_event_constraints;
 			x86_pmu.enable_all = intel_tfa_pmu_enable_all;
 			x86_pmu.commit_scheduling = intel_tfa_commit_scheduling;
-			intel_pmu_attrs[1] = &dev_attr_allow_tsx_force_abort.attr;
 		}
 
 		pr_cont("Skylake events, ");
#24 lore raw

[tip:perf/core] perf/x86: Use update attribute groups for default attributes

In reply to Jiri Olsa
perf/x86: Use update attribute groups for default attributes
Commit-ID:  6a9f4efe78af6069a11946c64d3d4c86cb42046b
Gitweb:     https://git.kernel.org/tip/6a9f4efe78af6069a11946c64d3d4c86cb42046b
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 12 May 2019 17:55:18 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 3 Jun 2019 11:58:27 +0200

perf/x86: Use update attribute groups for default attributes

Using the new pmu::update_attrs attribute group for default attributes - freeze_on_smi, allow_tsx_force_abort.

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/events/core.c       | 34 ----------------------------------
 arch/x86/events/intel/core.c |  9 +++++----
 arch/x86/events/perf_event.h |  3 ---
 3 files changed, 5 insertions(+), 41 deletions(-)
arch/x86/events/core.c +0 -34
index dd0996ba75c3..f0e4804515d8 100644
@@ -1618,32 +1618,6 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {
 	.attrs = NULL,
 };
 
-/* Merge two pointer arrays */
-__init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
-{
-	struct attribute **new;
-	int j, i;
-
-	for (j = 0; a && a[j]; j++)
-		;
-	for (i = 0; b && b[i]; i++)
-		j++;
-	j++;
-
-	new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
-	if (!new)
-		return NULL;
-
-	j = 0;
-	for (i = 0; a && a[i]; i++)
-		new[j++] = a[i];
-	for (i = 0; b && b[i]; i++)
-		new[j++] = b[i];
-	new[j] = NULL;
-
-	return new;
-}
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
 {
 	struct perf_pmu_events_attr *pmu_attr = \
@@ -1824,14 +1798,6 @@ static int __init init_hw_perf_events(void)
 	if (!x86_pmu.events_sysfs_show)
 		x86_pmu_events_group.attrs = &empty_attrs;
 
-	if (x86_pmu.attrs) {
-		struct attribute **tmp;
-
-		tmp = merge_attr(x86_pmu_attr_group.attrs, x86_pmu.attrs);
-		if (!WARN_ON(!tmp))
-			x86_pmu_attr_group.attrs = tmp;
-	}
-
 	pmu.attr_update = x86_pmu.attr_update;
 
 	pr_info("... version:                %d\n",     x86_pmu.version);
arch/x86/events/intel/core.c +5 -4
index 3bc967be7c7b..71001f005bfe 100644
@@ -3897,8 +3897,6 @@ static __initconst const struct x86_pmu core_pmu = {
 	.check_period		= intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
@@ -3930,8 +3928,6 @@ static __initconst const struct x86_pmu intel_pmu = {
 	.format_attrs		= intel_arch3_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
 
-	.attrs			= intel_pmu_attrs,
-
 	.cpu_prepare		= intel_pmu_cpu_prepare,
 	.cpu_starting		= intel_pmu_cpu_starting,
 	.cpu_dying		= intel_pmu_cpu_dying,
@@ -4458,6 +4454,10 @@ static struct attribute_group group_format_extra_skl = {
 	.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+	.attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
 	&group_events_td,
 	&group_events_mem,
@@ -4466,6 +4466,7 @@ static const struct attribute_group *attr_update[] = {
 	&group_caps_lbr,
 	&group_format_extra,
 	&group_format_extra_skl,
+	&group_default,
 	NULL,
 };
 
arch/x86/events/perf_event.h +0 -3
index 1da9b6f0b279..9bcec3f99e4a 100644
@@ -636,7 +636,6 @@ struct x86_pmu {
 	const struct attribute_group **attr_update;
 
 	unsigned long	attr_freeze_on_smi;
-	struct attribute **attrs;
 
 	/*
 	 * CPU Hotplug hooks
@@ -903,8 +902,6 @@ 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);
 
-struct attribute **merge_attr(struct attribute **a, struct attribute **b);
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
 			  char *page);
 ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
maintainer
#25 lore raw
In reply to Jiri Olsa
Quoted 2 lines · Jiri Olsa

following up on [1], this patchset adds update attribute groups to pmu and gets rid of the 'creative' attribute handling code.

Thanks! Queued them.