diff mbox series

[v2,4/5] arm64: perf: Refactor PMU init callbacks

Message ID acd2f12447f8ca2fdfe2b161fc41dc84fee90471.1582312530.git.robin.murphy@arm.com (mailing list archive)
State Mainlined
Commit e424b17985262359181cce1553a1ea2cdf263941
Headers show
Series arm64 CPU DT binding updates | expand

Commit Message

Robin Murphy Feb. 21, 2020, 7:35 p.m. UTC
The PMU init callbacks are already drowning in boilerplate, so before
doubling the number of supported PMU models, give it a sensible refactor
to significantly reduce the bloat, both in source and object code.
Although nobody uses non-default sysfs attributes today, there's minimal
impact to preserving the notion that maybe, some day, somebody might, so
we may as well keep up appearances.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

v2: new

 arch/arm64/kernel/perf_event.c | 124 +++++++--------------------------
 1 file changed, 27 insertions(+), 97 deletions(-)

Comments

Mark Rutland Feb. 28, 2020, 12:15 p.m. UTC | #1
On Fri, Feb 21, 2020 at 07:35:31PM +0000, Robin Murphy wrote:
> The PMU init callbacks are already drowning in boilerplate, so before
> doubling the number of supported PMU models, give it a sensible refactor
> to significantly reduce the bloat, both in source and object code.
> Although nobody uses non-default sysfs attributes today, there's minimal
> impact to preserving the notion that maybe, some day, somebody might, so
> we may as well keep up appearances.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
> 
> v2: new
> 
>  arch/arm64/kernel/perf_event.c | 124 +++++++--------------------------
>  1 file changed, 27 insertions(+), 97 deletions(-)
> 
> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> index e40b65645c86..1e0b04da2f3a 100644
> --- a/arch/arm64/kernel/perf_event.c
> +++ b/arch/arm64/kernel/perf_event.c
> @@ -953,7 +953,10 @@ static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)
>  	return probe.present ? 0 : -ENODEV;
>  }
>  
> -static int armv8_pmu_init(struct arm_pmu *cpu_pmu)
> +static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
> +			  int (*map_event)(struct perf_event *event),
> +			  const struct attribute_group *events,
> +			  const struct attribute_group *format)
>  {
>  	int ret = armv8pmu_probe_pmu(cpu_pmu);
>  	if (ret)
> @@ -972,135 +975,62 @@ static int armv8_pmu_init(struct arm_pmu *cpu_pmu)
>  	cpu_pmu->set_event_filter	= armv8pmu_set_event_filter;
>  	cpu_pmu->filter_match		= armv8pmu_filter_match;
>  
> +	cpu_pmu->name			= name;
> +	cpu_pmu->map_event		= map_event;
> +	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = events ?
> +			events : &armv8_pmuv3_events_attr_group;
> +	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = format ?
> +			format : &armv8_pmuv3_format_attr_group;
> +
>  	return 0;
>  }
>  
>  static int armv8_pmuv3_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_pmuv3";
> -	cpu_pmu->map_event		= armv8_pmuv3_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_pmuv3",
> +			      armv8_pmuv3_map_event, NULL, NULL);
>  }
>  
>  static int armv8_a35_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cortex_a35";
> -	cpu_pmu->map_event		= armv8_a53_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a35",
> +			      armv8_a53_map_event, NULL, NULL);
>  }
>  
>  static int armv8_a53_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cortex_a53";
> -	cpu_pmu->map_event		= armv8_a53_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a53",
> +			      armv8_a53_map_event, NULL, NULL);
>  }
>  
>  static int armv8_a57_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cortex_a57";
> -	cpu_pmu->map_event		= armv8_a57_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a57",
> +			      armv8_a57_map_event, NULL, NULL);
>  }
>  
>  static int armv8_a72_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cortex_a72";
> -	cpu_pmu->map_event		= armv8_a57_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a72",
> +			      armv8_a57_map_event, NULL, NULL);
>  }
>  
>  static int armv8_a73_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cortex_a73";
> -	cpu_pmu->map_event		= armv8_a73_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a73",
> +			      armv8_a73_map_event, NULL, NULL);
>  }
>  
>  static int armv8_thunder_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_cavium_thunder";
> -	cpu_pmu->map_event		= armv8_thunder_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_cavium_thunder",
> +			      armv8_thunder_map_event, NULL, NULL);
>  }
>  
>  static int armv8_vulcan_pmu_init(struct arm_pmu *cpu_pmu)
>  {
> -	int ret = armv8_pmu_init(cpu_pmu);
> -	if (ret)
> -		return ret;
> -
> -	cpu_pmu->name			= "armv8_brcm_vulcan";
> -	cpu_pmu->map_event		= armv8_vulcan_map_event;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
> -		&armv8_pmuv3_events_attr_group;
> -	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
> -		&armv8_pmuv3_format_attr_group;
> -
> -	return 0;
> +	return armv8_pmu_init(cpu_pmu, "armv8_brcm_vulcan",
> +			      armv8_vulcan_map_event, NULL, NULL);
>  }
>  
>  static const struct of_device_id armv8_pmu_of_device_ids[] = {
> -- 
> 2.23.0.dirty
>
diff mbox series

Patch

diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index e40b65645c86..1e0b04da2f3a 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -953,7 +953,10 @@  static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)
 	return probe.present ? 0 : -ENODEV;
 }
 
-static int armv8_pmu_init(struct arm_pmu *cpu_pmu)
+static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
+			  int (*map_event)(struct perf_event *event),
+			  const struct attribute_group *events,
+			  const struct attribute_group *format)
 {
 	int ret = armv8pmu_probe_pmu(cpu_pmu);
 	if (ret)
@@ -972,135 +975,62 @@  static int armv8_pmu_init(struct arm_pmu *cpu_pmu)
 	cpu_pmu->set_event_filter	= armv8pmu_set_event_filter;
 	cpu_pmu->filter_match		= armv8pmu_filter_match;
 
+	cpu_pmu->name			= name;
+	cpu_pmu->map_event		= map_event;
+	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = events ?
+			events : &armv8_pmuv3_events_attr_group;
+	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = format ?
+			format : &armv8_pmuv3_format_attr_group;
+
 	return 0;
 }
 
 static int armv8_pmuv3_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_pmuv3";
-	cpu_pmu->map_event		= armv8_pmuv3_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_pmuv3",
+			      armv8_pmuv3_map_event, NULL, NULL);
 }
 
 static int armv8_a35_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cortex_a35";
-	cpu_pmu->map_event		= armv8_a53_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a35",
+			      armv8_a53_map_event, NULL, NULL);
 }
 
 static int armv8_a53_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cortex_a53";
-	cpu_pmu->map_event		= armv8_a53_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a53",
+			      armv8_a53_map_event, NULL, NULL);
 }
 
 static int armv8_a57_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cortex_a57";
-	cpu_pmu->map_event		= armv8_a57_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a57",
+			      armv8_a57_map_event, NULL, NULL);
 }
 
 static int armv8_a72_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cortex_a72";
-	cpu_pmu->map_event		= armv8_a57_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a72",
+			      armv8_a57_map_event, NULL, NULL);
 }
 
 static int armv8_a73_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cortex_a73";
-	cpu_pmu->map_event		= armv8_a73_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cortex_a73",
+			      armv8_a73_map_event, NULL, NULL);
 }
 
 static int armv8_thunder_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_cavium_thunder";
-	cpu_pmu->map_event		= armv8_thunder_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_cavium_thunder",
+			      armv8_thunder_map_event, NULL, NULL);
 }
 
 static int armv8_vulcan_pmu_init(struct arm_pmu *cpu_pmu)
 {
-	int ret = armv8_pmu_init(cpu_pmu);
-	if (ret)
-		return ret;
-
-	cpu_pmu->name			= "armv8_brcm_vulcan";
-	cpu_pmu->map_event		= armv8_vulcan_map_event;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] =
-		&armv8_pmuv3_events_attr_group;
-	cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] =
-		&armv8_pmuv3_format_attr_group;
-
-	return 0;
+	return armv8_pmu_init(cpu_pmu, "armv8_brcm_vulcan",
+			      armv8_vulcan_map_event, NULL, NULL);
 }
 
 static const struct of_device_id armv8_pmu_of_device_ids[] = {