linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/9] perf/x86: Add update attribute groups
@ 2019-05-12 15:55 Jiri Olsa
  2019-05-12 15:55 ` [PATCH 1/9] sysfs: Add sysfs_update_groups function Jiri Olsa
                   ` (9 more replies)
  0 siblings, 10 replies; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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/20190318182116.17388-1-jolsa@kernel.org/
---
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(-)

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/9] sysfs: Add sysfs_update_groups function
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 2/9] perf: Add attr_groups_update into struct pmu Jiri Olsa
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Greg Kroah-Hartman, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Peter Zijlstra, Andi Kleen

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.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 fs/sysfs/group.c      | 54 +++++++++++++++++++++++++++++++------------
 include/linux/sysfs.h |  2 ++
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 57038604d4a8..d41c21fef138 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -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
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 786816cf4aa5..d13db254fb99 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -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,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/9] perf: Add attr_groups_update into struct pmu
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
  2019-05-12 15:55 ` [PATCH 1/9] sysfs: Add sysfs_update_groups function Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:26   ` [tip:perf/core] perf/core: " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 3/9] perf/x86: Get rid of x86_pmu::event_attrs Jiri Olsa
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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,
  };

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/perf_event.h | 1 +
 kernel/events/core.c       | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f3864e1c5569..cb5f07d50edb 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -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;
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index abbd4b3b96c2..21ef9b843af0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -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;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 3/9] perf/x86: Get rid of x86_pmu::event_attrs
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
  2019-05-12 15:55 ` [PATCH 1/9] sysfs: Add sysfs_update_groups function Jiri Olsa
  2019-05-12 15:55 ` [PATCH 2/9] perf: Add attr_groups_update into struct pmu Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 4/9] perf/x86: Use the new pmu::update_attrs attribute group Jiri Olsa
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

Nobody is using that.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/events/core.c       | 3 ---
 arch/x86/events/perf_event.h | 1 -
 2 files changed, 4 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index de1a924a4914..f2be5d2a62fe 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 07fc84bb85c1..3f87cb4d7585 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 4/9] perf/x86: Use the new pmu::update_attrs attribute group
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (2 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 3/9] perf/x86: Get rid of x86_pmu::event_attrs Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 5/9] perf/x86: Add is_visible attribute_group callback for base events Jiri Olsa
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index f2be5d2a62fe..a43d8d1e8590 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 4b4dac089635..fd7d36611e22 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4265,13 +4265,6 @@ static struct attribute *icl_tsx_events_attrs[] = {
 	NULL,
 };
 
-static __init struct attribute **get_icl_events_attrs(void)
-{
-	return boot_cpu_has(X86_FEATURE_RTM) ?
-		merge_attr(icl_events_attrs, icl_tsx_events_attrs) :
-		icl_events_attrs;
-}
-
 static ssize_t freeze_on_smi_show(struct device *cdev,
 				  struct device_attribute *attr,
 				  char *buf)
@@ -4397,32 +4390,47 @@ static struct attribute *intel_pmu_attrs[] = {
 	NULL,
 };
 
-static __init struct attribute **
-get_events_attrs(struct attribute **base,
-		 struct attribute **mem,
-		 struct attribute **tsx)
+static umode_t
+tsx_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 {
-	struct attribute **attrs = base;
-	struct attribute **old;
+	return boot_cpu_has(X86_FEATURE_RTM) ? attr->mode : 0;
+}
 
-	if (mem && x86_pmu.pebs)
-		attrs = merge_attr(attrs, mem);
+static umode_t
+pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.pebs ? attr->mode : 0;
+}
 
-	if (tsx && boot_cpu_has(X86_FEATURE_RTM)) {
-		old = attrs;
-		attrs = merge_attr(attrs, tsx);
-		if (old != base)
-			kfree(old);
-	}
+static struct attribute_group group_events_td  = {
+	.name = "events",
+};
 
-	return attrs;
-}
+static struct attribute_group group_events_mem = {
+	.name       = "events",
+	.is_visible = pebs_is_visible,
+};
+
+static struct attribute_group group_events_tsx = {
+	.name       = "events",
+	.is_visible = tsx_is_visible,
+};
+
+static const struct attribute_group *attr_update[] = {
+	&group_events_td,
+	&group_events_mem,
+	&group_events_tsx,
+	NULL,
+};
+
+static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
-	struct attribute **extra_attr = NULL;
-	struct attribute **mem_attr = NULL;
-	struct attribute **tsx_attr = NULL;
+	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;
@@ -4587,7 +4595,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_slm_extra_regs;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
-		x86_pmu.cpu_events = slm_events_attrs;
+		td_attr = slm_events_attrs;
 		extra_attr = slm_format_attr;
 		pr_cont("Silvermont events, ");
 		name = "silvermont";
@@ -4615,7 +4623,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_prec_dist = true;
 		x86_pmu.lbr_pt_coexist = true;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
-		x86_pmu.cpu_events = glm_events_attrs;
+		td_attr = glm_events_attrs;
 		extra_attr = slm_format_attr;
 		pr_cont("Goldmont events, ");
 		name = "goldmont";
@@ -4642,7 +4650,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_PEBS_ALL;
 		x86_pmu.get_event_constraints = glp_get_event_constraints;
-		x86_pmu.cpu_events = glm_events_attrs;
+		td_attr = glm_events_attrs;
 		/* Goldmont Plus has 4-wide pipeline */
 		event_attr_td_total_slots_scale_glm.event_str = "4";
 		extra_attr = slm_format_attr;
@@ -4731,7 +4739,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
-		x86_pmu.cpu_events = snb_events_attrs;
+		td_attr  = snb_events_attrs;
 		mem_attr = snb_mem_events_attrs;
 
 		/* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
@@ -4772,7 +4780,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
-		x86_pmu.cpu_events = snb_events_attrs;
+		td_attr  = snb_events_attrs;
 		mem_attr = snb_mem_events_attrs;
 
 		/* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
@@ -4809,10 +4817,10 @@ __init int intel_pmu_init(void)
 
 		x86_pmu.hw_config = hsw_hw_config;
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
-		x86_pmu.cpu_events = hsw_events_attrs;
 		x86_pmu.lbr_double_abort = true;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		pr_cont("Haswell events, ");
@@ -4851,10 +4859,10 @@ __init int intel_pmu_init(void)
 
 		x86_pmu.hw_config = hsw_hw_config;
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
-		x86_pmu.cpu_events = hsw_events_attrs;
 		x86_pmu.limit_period = bdw_limit_period;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		pr_cont("Broadwell events, ");
@@ -4913,7 +4921,7 @@ __init int intel_pmu_init(void)
 			hsw_format_attr : nhm_format_attr;
 		extra_attr = merge_attr(extra_attr, skl_format_attr);
 		to_free = extra_attr;
-		x86_pmu.cpu_events = hsw_events_attrs;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		intel_pmu_pebs_data_source_skl(
@@ -4951,7 +4959,8 @@ __init int intel_pmu_init(void)
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
 		extra_attr = merge_attr(extra_attr, skl_format_attr);
-		x86_pmu.cpu_events = get_icl_events_attrs();
+		mem_attr = icl_events_attrs;
+		tsx_attr = icl_tsx_events_attrs;
 		x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xca, .umask=0x02);
 		x86_pmu.lbr_pt_coexist = true;
 		intel_pmu_pebs_data_source_skl(false);
@@ -4985,8 +4994,11 @@ __init int intel_pmu_init(void)
 		WARN_ON(!x86_pmu.format_attrs);
 	}
 
-	x86_pmu.cpu_events = get_events_attrs(x86_pmu.cpu_events,
-					      mem_attr, tsx_attr);
+	group_events_td.attrs  = td_attr;
+	group_events_mem.attrs = mem_attr;
+	group_events_tsx.attrs = tsx_attr;
+
+	x86_pmu.attr_update = attr_update;
 
 	if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
 		WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 3f87cb4d7585..7dd91607b5fa 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 5/9] perf/x86: Add is_visible attribute_group callback for base events
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (3 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 4/9] perf/x86: Use the new pmu::update_attrs attribute group Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:28   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 6/9] perf/x86: Use update attribute groups for caps Jiri Olsa
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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 | 53 ++++++++++++------------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index a43d8d1e8590..a7aa72afcc7f 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,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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 6/9] perf/x86: Use update attribute groups for caps
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (4 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 5/9] perf/x86: Add is_visible attribute_group callback for base events Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:28   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 7/9] perf/x86: Use update attribute groups for extra format Jiri Olsa
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index a7aa72afcc7f..7f1bb5fd1fc4 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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;
 
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index fd7d36611e22..fff73623cf80 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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.
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 7dd91607b5fa..1e3a7d74ea49 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 7/9] perf/x86: Use update attribute groups for extra format
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (5 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 6/9] perf/x86: Use update attribute groups for caps Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:29   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 8/9] perf/x86/intel: Use update attributes for skylake format Jiri Olsa
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/events/intel/core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index fff73623cf80..524b390a2c26 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 8/9] perf/x86/intel: Use update attributes for skylake format
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (6 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 7/9] perf/x86: Use update attribute groups for extra format Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-06-03 13:30   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2019-05-12 15:55 ` [PATCH 9/9] perf/x86: Use update attribute groups for default attributes Jiri Olsa
  2019-05-13  9:38 ` [PATCHv2 0/9] perf/x86: Add update attribute groups Peter Zijlstra
  9 siblings, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/events/intel/core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 524b390a2c26..7db858c3bbec 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 9/9] perf/x86: Use update attribute groups for default attributes
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (7 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 8/9] perf/x86/intel: Use update attributes for skylake format Jiri Olsa
@ 2019-05-12 15:55 ` Jiri Olsa
  2019-05-13  9:35   ` Peter Zijlstra
  2019-06-03 13:31   ` [tip:perf/core] perf/x86: Use update attribute groups for default attributes tip-bot for Jiri Olsa
  2019-05-13  9:38 ` [PATCHv2 0/9] perf/x86: Add update attribute groups Peter Zijlstra
  9 siblings, 2 replies; 26+ messages in thread
From: Jiri Olsa @ 2019-05-12 15:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Greg Kroah-Hartman

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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 7f1bb5fd1fc4..ce26da2ef11e 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 7db858c3bbec..e721be25abfb 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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,
 };
 
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 1e3a7d74ea49..7ae2912f16de 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] perf/x86: Use update attribute groups for default attributes
  2019-05-12 15:55 ` [PATCH 9/9] perf/x86: Use update attribute groups for default attributes Jiri Olsa
@ 2019-05-13  9:35   ` Peter Zijlstra
  2019-05-13 10:13     ` Jiri Olsa
  2019-05-24 13:21     ` [PATCH] perf/x86/intel: Use is_visible callback for default group Jiri Olsa
  2019-06-03 13:31   ` [tip:perf/core] perf/x86: Use update attribute groups for default attributes tip-bot for Jiri Olsa
  1 sibling, 2 replies; 26+ messages in thread
From: Peter Zijlstra @ 2019-05-13  9:35 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

On Sun, May 12, 2019 at 05:55:18PM +0200, Jiri Olsa wrote:
> Using the new pmu::update_attrs attribute group for default
> attributes - freeze_on_smi, allow_tsx_force_abort.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 7db858c3bbec..e721be25abfb 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -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,
>  };


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?

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCHv2 0/9] perf/x86: Add update attribute groups
  2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
                   ` (8 preceding siblings ...)
  2019-05-12 15:55 ` [PATCH 9/9] perf/x86: Use update attribute groups for default attributes Jiri Olsa
@ 2019-05-13  9:38 ` Peter Zijlstra
  9 siblings, 0 replies; 26+ messages in thread
From: Peter Zijlstra @ 2019-05-13  9:38 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

On Sun, May 12, 2019 at 05:55:09PM +0200, Jiri Olsa wrote:
> following up on [1], this patchset adds update attribute groups
> to pmu and gets rid of the 'creative' attribute handling code.

Thanks! Queued them.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] perf/x86: Use update attribute groups for default attributes
  2019-05-13  9:35   ` Peter Zijlstra
@ 2019-05-13 10:13     ` Jiri Olsa
  2019-05-24 13:21     ` [PATCH] perf/x86/intel: Use is_visible callback for default group Jiri Olsa
  1 sibling, 0 replies; 26+ messages in thread
From: Jiri Olsa @ 2019-05-13 10:13 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

On Mon, May 13, 2019 at 11:35:45AM +0200, Peter Zijlstra wrote:
> On Sun, May 12, 2019 at 05:55:18PM +0200, Jiri Olsa wrote:
> > Using the new pmu::update_attrs attribute group for default
> > attributes - freeze_on_smi, allow_tsx_force_abort.
> > 
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> 
> > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> > index 7db858c3bbec..e721be25abfb 100644
> > --- a/arch/x86/events/intel/core.c
> > +++ b/arch/x86/events/intel/core.c
> > @@ -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,
> >  };
> 
> 
> 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?

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

thanks,
jirka

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH] perf/x86/intel: Use is_visible callback for default group
  2019-05-13  9:35   ` Peter Zijlstra
  2019-05-13 10:13     ` Jiri Olsa
@ 2019-05-24 13:21     ` Jiri Olsa
  2019-06-14 10:20       ` Jiri Olsa
  2019-06-17 14:40       ` [tip:perf/core] perf/x86/intel: Use ->is_visible " tip-bot for Jiri Olsa
  1 sibling, 2 replies; 26+ messages in thread
From: Jiri Olsa @ 2019-05-24 13:21 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

On Mon, May 13, 2019 at 11:35:45AM +0200, Peter Zijlstra wrote:
> On Sun, May 12, 2019 at 05:55:18PM +0200, Jiri Olsa wrote:
> > Using the new pmu::update_attrs attribute group for default
> > attributes - freeze_on_smi, allow_tsx_force_abort.
> > 
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> 
> > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> > index 7db858c3bbec..e721be25abfb 100644
> > --- a/arch/x86/events/intel/core.c
> > +++ b/arch/x86/events/intel/core.c
> > @@ -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,
> >  };
> 
> 
> 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?

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 <eranian@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 85afe7e98c7d..cfd61b71136d 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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, ");
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] sysfs: Add sysfs_update_groups function
  2019-05-12 15:55 ` [PATCH 1/9] sysfs: Add sysfs_update_groups function Jiri Olsa
@ 2019-06-03 13:25   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: gregkh, jolsa, peterz, tglx, linux-kernel, hpa,
	alexander.shishkin, mingo, torvalds, acme, namhyung

Commit-ID:  aac1f7f95f115d5a5329be05b80022e72df7d080
Gitweb:     https://git.kernel.org/tip/aac1f7f95f115d5a5329be05b80022e72df7d080
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:10 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-2-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 fs/sysfs/group.c      | 54 +++++++++++++++++++++++++++++++++++++--------------
 include/linux/sysfs.h |  8 ++++++++
 2 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 57038604d4a8..d41c21fef138 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -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
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 786816cf4aa5..965236795750 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -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)
 {

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/core: Add attr_groups_update into struct pmu
  2019-05-12 15:55 ` [PATCH 2/9] perf: Add attr_groups_update into struct pmu Jiri Olsa
@ 2019-06-03 13:26   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, acme, alexander.shishkin, namhyung, torvalds, gregkh,
	peterz, tglx, jolsa, linux-kernel, hpa

Commit-ID:  f3a3a8257e5a1a5e67cbb1afdbc4c1c6a26f1b22
Gitweb:     https://git.kernel.org/tip/f3a3a8257e5a1a5e67cbb1afdbc4c1c6a26f1b22
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:11 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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,
  };

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-3-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/perf_event.h | 1 +
 kernel/events/core.c       | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 0ab99c7b652d..3dc01cf98e16 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -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;
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 3005c80f621d..118ad1aef6af 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -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;
 

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Get rid of x86_pmu::event_attrs
  2019-05-12 15:55 ` [PATCH 3/9] perf/x86: Get rid of x86_pmu::event_attrs Jiri Olsa
@ 2019-06-03 13:26   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, hpa, tglx, gregkh, namhyung, torvalds, acme, jolsa,
	peterz, linux-kernel, alexander.shishkin

Commit-ID:  21b0dbc5e8b050e40a93a1f8cdef277502a4fc90
Gitweb:     https://git.kernel.org/tip/21b0dbc5e8b050e40a93a1f8cdef277502a4fc90
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:12 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 3 Jun 2019 11:58:22 +0200

perf/x86: Get rid of x86_pmu::event_attrs

Nobody is using that.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-4-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/core.c       | 3 ---
 arch/x86/events/perf_event.h | 1 -
 2 files changed, 4 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index f315425d8468..0c5a2c783374 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index a6ac2f4f76fc..1599008f156a 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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);

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Use the new pmu::update_attrs attribute group
  2019-05-12 15:55 ` [PATCH 4/9] perf/x86: Use the new pmu::update_attrs attribute group Jiri Olsa
@ 2019-06-03 13:27   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, alexander.shishkin, namhyung, torvalds, hpa, gregkh, tglx,
	peterz, jolsa, linux-kernel, mingo

Commit-ID:  baa0c83363c7aafb04734acf4ac252be8e13bd88
Gitweb:     https://git.kernel.org/tip/baa0c83363c7aafb04734acf4ac252be8e13bd88
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:13 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-5-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 0c5a2c783374..db815ceb5017 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a5436cee20b1..600e87055ba9 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4274,13 +4274,6 @@ static struct attribute *icl_tsx_events_attrs[] = {
 	NULL,
 };
 
-static __init struct attribute **get_icl_events_attrs(void)
-{
-	return boot_cpu_has(X86_FEATURE_RTM) ?
-		merge_attr(icl_events_attrs, icl_tsx_events_attrs) :
-		icl_events_attrs;
-}
-
 static ssize_t freeze_on_smi_show(struct device *cdev,
 				  struct device_attribute *attr,
 				  char *buf)
@@ -4406,32 +4399,47 @@ static struct attribute *intel_pmu_attrs[] = {
 	NULL,
 };
 
-static __init struct attribute **
-get_events_attrs(struct attribute **base,
-		 struct attribute **mem,
-		 struct attribute **tsx)
+static umode_t
+tsx_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 {
-	struct attribute **attrs = base;
-	struct attribute **old;
+	return boot_cpu_has(X86_FEATURE_RTM) ? attr->mode : 0;
+}
 
-	if (mem && x86_pmu.pebs)
-		attrs = merge_attr(attrs, mem);
+static umode_t
+pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+	return x86_pmu.pebs ? attr->mode : 0;
+}
 
-	if (tsx && boot_cpu_has(X86_FEATURE_RTM)) {
-		old = attrs;
-		attrs = merge_attr(attrs, tsx);
-		if (old != base)
-			kfree(old);
-	}
+static struct attribute_group group_events_td  = {
+	.name = "events",
+};
 
-	return attrs;
-}
+static struct attribute_group group_events_mem = {
+	.name       = "events",
+	.is_visible = pebs_is_visible,
+};
+
+static struct attribute_group group_events_tsx = {
+	.name       = "events",
+	.is_visible = tsx_is_visible,
+};
+
+static const struct attribute_group *attr_update[] = {
+	&group_events_td,
+	&group_events_mem,
+	&group_events_tsx,
+	NULL,
+};
+
+static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
-	struct attribute **extra_attr = NULL;
-	struct attribute **mem_attr = NULL;
-	struct attribute **tsx_attr = NULL;
+	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;
@@ -4596,7 +4604,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_slm_extra_regs;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
-		x86_pmu.cpu_events = slm_events_attrs;
+		td_attr = slm_events_attrs;
 		extra_attr = slm_format_attr;
 		pr_cont("Silvermont events, ");
 		name = "silvermont";
@@ -4624,7 +4632,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_prec_dist = true;
 		x86_pmu.lbr_pt_coexist = true;
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
-		x86_pmu.cpu_events = glm_events_attrs;
+		td_attr = glm_events_attrs;
 		extra_attr = slm_format_attr;
 		pr_cont("Goldmont events, ");
 		name = "goldmont";
@@ -4651,7 +4659,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_PEBS_ALL;
 		x86_pmu.get_event_constraints = glp_get_event_constraints;
-		x86_pmu.cpu_events = glm_events_attrs;
+		td_attr = glm_events_attrs;
 		/* Goldmont Plus has 4-wide pipeline */
 		event_attr_td_total_slots_scale_glm.event_str = "4";
 		extra_attr = slm_format_attr;
@@ -4740,7 +4748,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
-		x86_pmu.cpu_events = snb_events_attrs;
+		td_attr  = snb_events_attrs;
 		mem_attr = snb_mem_events_attrs;
 
 		/* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
@@ -4781,7 +4789,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
-		x86_pmu.cpu_events = snb_events_attrs;
+		td_attr  = snb_events_attrs;
 		mem_attr = snb_mem_events_attrs;
 
 		/* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
@@ -4818,10 +4826,10 @@ __init int intel_pmu_init(void)
 
 		x86_pmu.hw_config = hsw_hw_config;
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
-		x86_pmu.cpu_events = hsw_events_attrs;
 		x86_pmu.lbr_double_abort = true;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		pr_cont("Haswell events, ");
@@ -4860,10 +4868,10 @@ __init int intel_pmu_init(void)
 
 		x86_pmu.hw_config = hsw_hw_config;
 		x86_pmu.get_event_constraints = hsw_get_event_constraints;
-		x86_pmu.cpu_events = hsw_events_attrs;
 		x86_pmu.limit_period = bdw_limit_period;
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		pr_cont("Broadwell events, ");
@@ -4922,7 +4930,7 @@ __init int intel_pmu_init(void)
 			hsw_format_attr : nhm_format_attr;
 		extra_attr = merge_attr(extra_attr, skl_format_attr);
 		to_free = extra_attr;
-		x86_pmu.cpu_events = hsw_events_attrs;
+		td_attr  = hsw_events_attrs;
 		mem_attr = hsw_mem_events_attrs;
 		tsx_attr = hsw_tsx_events_attrs;
 		intel_pmu_pebs_data_source_skl(
@@ -4960,7 +4968,8 @@ __init int intel_pmu_init(void)
 		extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
 			hsw_format_attr : nhm_format_attr;
 		extra_attr = merge_attr(extra_attr, skl_format_attr);
-		x86_pmu.cpu_events = get_icl_events_attrs();
+		mem_attr = icl_events_attrs;
+		tsx_attr = icl_tsx_events_attrs;
 		x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xca, .umask=0x02);
 		x86_pmu.lbr_pt_coexist = true;
 		intel_pmu_pebs_data_source_skl(false);
@@ -4994,8 +5003,11 @@ __init int intel_pmu_init(void)
 		WARN_ON(!x86_pmu.format_attrs);
 	}
 
-	x86_pmu.cpu_events = get_events_attrs(x86_pmu.cpu_events,
-					      mem_attr, tsx_attr);
+	group_events_td.attrs  = td_attr;
+	group_events_mem.attrs = mem_attr;
+	group_events_tsx.attrs = tsx_attr;
+
+	x86_pmu.attr_update = attr_update;
 
 	if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
 		WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 1599008f156a..629b313d8b8b 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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;

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Add is_visible attribute_group callback for base events
  2019-05-12 15:55 ` [PATCH 5/9] perf/x86: Add is_visible attribute_group callback for base events Jiri Olsa
@ 2019-06-03 13:28   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, hpa, gregkh, mingo, namhyung, alexander.shishkin, acme,
	tglx, linux-kernel, jolsa, torvalds

Commit-ID:  3d5672735b2348f5b13679a27f90c0847d22125d
Gitweb:     https://git.kernel.org/tip/3d5672735b2348f5b13679a27f90c0847d22125d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:14 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-6-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/core.c | 53 ++++++++++++++------------------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index db815ceb5017..b831091d4c10 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,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;

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Use update attribute groups for caps
  2019-05-12 15:55 ` [PATCH 6/9] perf/x86: Use update attribute groups for caps Jiri Olsa
@ 2019-06-03 13:28   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, peterz, torvalds, linux-kernel, alexander.shishkin, jolsa,
	namhyung, gregkh, hpa, tglx, mingo

Commit-ID:  1f157286829c78c0bd8e495951a5c098d88e3d1a
Gitweb:     https://git.kernel.org/tip/1f157286829c78c0bd8e495951a5c098d88e3d1a
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:15 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-7-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index b831091d4c10..dd0996ba75c3 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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;
 
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 600e87055ba9..d4002e71a0b8 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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.
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 629b313d8b8b..1da9b6f0b279 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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;

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Use update attribute groups for extra format
  2019-05-12 15:55 ` [PATCH 7/9] perf/x86: Use update attribute groups for extra format Jiri Olsa
@ 2019-06-03 13:29   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, gregkh, jolsa, hpa, torvalds, peterz, acme, linux-kernel,
	namhyung, mingo, alexander.shishkin

Commit-ID:  3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Gitweb:     https://git.kernel.org/tip/3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:16 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-8-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index d4002e71a0b8..de4779f44737 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86/intel: Use update attributes for skylake format
  2019-05-12 15:55 ` [PATCH 8/9] perf/x86/intel: Use update attributes for skylake format Jiri Olsa
@ 2019-06-03 13:30   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, torvalds, acme, tglx, gregkh, alexander.shishkin, jolsa,
	peterz, mingo, linux-kernel, namhyung

Commit-ID:  b657688069a24c3c81b6de22e0e57e1785d9211f
Gitweb:     https://git.kernel.org/tip/b657688069a24c3c81b6de22e0e57e1785d9211f
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:17 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-9-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index de4779f44737..3bc967be7c7b 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 }
 

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86: Use update attribute groups for default attributes
  2019-05-12 15:55 ` [PATCH 9/9] perf/x86: Use update attribute groups for default attributes Jiri Olsa
  2019-05-13  9:35   ` Peter Zijlstra
@ 2019-06-03 13:31   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-03 13:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, hpa, acme, peterz, tglx, gregkh, namhyung,
	jolsa, mingo, linux-kernel, torvalds

Commit-ID:  6a9f4efe78af6069a11946c64d3d4c86cb42046b
Gitweb:     https://git.kernel.org/tip/6a9f4efe78af6069a11946c64d3d4c86cb42046b
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sun, 12 May 2019 17:55:18 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-10-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index dd0996ba75c3..f0e4804515d8 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -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);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 3bc967be7c7b..71001f005bfe 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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,
 };
 
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 1da9b6f0b279..9bcec3f99e4a 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -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,

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH] perf/x86/intel: Use is_visible callback for default group
  2019-05-24 13:21     ` [PATCH] perf/x86/intel: Use is_visible callback for default group Jiri Olsa
@ 2019-06-14 10:20       ` Jiri Olsa
  2019-06-14 12:34         ` Peter Zijlstra
  2019-06-17 14:40       ` [tip:perf/core] perf/x86/intel: Use ->is_visible " tip-bot for Jiri Olsa
  1 sibling, 1 reply; 26+ messages in thread
From: Jiri Olsa @ 2019-06-14 10:20 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

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

SNIP

ping

jirka

> ---
> It's preffered to use group's is_visible callback, so
> we do not need to use condition attribute assignment.
> 
> Cc: Stephane Eranian <eranian@google.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  arch/x86/events/intel/core.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 85afe7e98c7d..cfd61b71136d 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -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, ");
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] perf/x86/intel: Use is_visible callback for default group
  2019-06-14 10:20       ` Jiri Olsa
@ 2019-06-14 12:34         ` Peter Zijlstra
  0 siblings, 0 replies; 26+ messages in thread
From: Peter Zijlstra @ 2019-06-14 12:34 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Andi Kleen, Greg Kroah-Hartman

On Fri, Jun 14, 2019 at 12:20:17PM +0200, Jiri Olsa wrote:
> 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 :-)

> > ---
> > It's preffered to use group's is_visible callback, so
> > we do not need to use condition attribute assignment.
> > 
> > Cc: Stephane Eranian <eranian@google.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Suggested-by: Peter Zijlstra <peterz@infradead.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  arch/x86/events/intel/core.c | 15 ++++++++++++---
> >  1 file changed, 12 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> > index 85afe7e98c7d..cfd61b71136d 100644
> > --- a/arch/x86/events/intel/core.c
> > +++ b/arch/x86/events/intel/core.c
> > @@ -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, ");
> > -- 
> > 2.20.1
> > 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [tip:perf/core] perf/x86/intel: Use ->is_visible callback for default group
  2019-05-24 13:21     ` [PATCH] perf/x86/intel: Use is_visible callback for default group Jiri Olsa
  2019-06-14 10:20       ` Jiri Olsa
@ 2019-06-17 14:40       ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 26+ messages in thread
From: tip-bot for Jiri Olsa @ 2019-06-17 14:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, hpa, torvalds, jolsa, alexander.shishkin, peterz,
	linux-kernel, gregkh, mingo, acme, tglx, jolsa

Commit-ID:  b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Gitweb:     https://git.kernel.org/tip/b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Fri, 24 May 2019 15:21:52 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190524132152.GB26617@krava
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 4377bf6a6f82..5e6ae481dee7 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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, ");

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-06-17 14:41 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-12 15:55 [PATCHv2 0/9] perf/x86: Add update attribute groups Jiri Olsa
2019-05-12 15:55 ` [PATCH 1/9] sysfs: Add sysfs_update_groups function Jiri Olsa
2019-06-03 13:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 2/9] perf: Add attr_groups_update into struct pmu Jiri Olsa
2019-06-03 13:26   ` [tip:perf/core] perf/core: " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 3/9] perf/x86: Get rid of x86_pmu::event_attrs Jiri Olsa
2019-06-03 13:26   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 4/9] perf/x86: Use the new pmu::update_attrs attribute group Jiri Olsa
2019-06-03 13:27   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 5/9] perf/x86: Add is_visible attribute_group callback for base events Jiri Olsa
2019-06-03 13:28   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 6/9] perf/x86: Use update attribute groups for caps Jiri Olsa
2019-06-03 13:28   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 7/9] perf/x86: Use update attribute groups for extra format Jiri Olsa
2019-06-03 13:29   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 8/9] perf/x86/intel: Use update attributes for skylake format Jiri Olsa
2019-06-03 13:30   ` [tip:perf/core] " tip-bot for Jiri Olsa
2019-05-12 15:55 ` [PATCH 9/9] perf/x86: Use update attribute groups for default attributes Jiri Olsa
2019-05-13  9:35   ` Peter Zijlstra
2019-05-13 10:13     ` Jiri Olsa
2019-05-24 13:21     ` [PATCH] perf/x86/intel: Use is_visible callback for default group Jiri Olsa
2019-06-14 10:20       ` Jiri Olsa
2019-06-14 12:34         ` Peter Zijlstra
2019-06-17 14:40       ` [tip:perf/core] perf/x86/intel: Use ->is_visible " tip-bot for Jiri Olsa
2019-06-03 13:31   ` [tip:perf/core] perf/x86: Use update attribute groups for default attributes tip-bot for Jiri Olsa
2019-05-13  9:38 ` [PATCHv2 0/9] perf/x86: Add update attribute groups Peter Zijlstra

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).