From: Ilkka Koskinen <ilkka@os.amperecomputing.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: will@kernel.org, mark.rutland@arm.com,
linux-arm-kernel@lists.infradead.org,
devicetree@vger.kernel.org, suzuki.poulose@arm.com,
ilkka@os.amperecomputing.com, bwicaksono@nvidia.com,
YWan@nvidia.com, rwiley@nvidia.com
Subject: Re: [PATCH 2/5] perf/arm_cspmu: Simplify attribute groups
Date: Wed, 6 Dec 2023 18:47:01 -0800 (PST) [thread overview]
Message-ID: <5ee6f058-a8eb-4b5b-4b0-3123e77a998b@os.amperecomputing.com> (raw)
In-Reply-To: <f75cacb440011df35fc476cf4be37484fd044b92.1701793996.git.robin.murphy@arm.com>
On Tue, 5 Dec 2023, Robin Murphy wrote:
> The attribute group array itself is always the same, so there's no
> need to allocate it separately. Storing it directly in our instance
> data saves memory and gives us one less point of failure.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cheers, Ilkka
> ---
> drivers/perf/arm_cspmu/arm_cspmu.c | 26 +++++++++-----------------
> drivers/perf/arm_cspmu/arm_cspmu.h | 1 +
> 2 files changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/perf/arm_cspmu/arm_cspmu.c b/drivers/perf/arm_cspmu/arm_cspmu.c
> index a3347b1287e6..f7aa2ac5fd88 100644
> --- a/drivers/perf/arm_cspmu/arm_cspmu.c
> +++ b/drivers/perf/arm_cspmu/arm_cspmu.c
> @@ -501,23 +501,16 @@ arm_cspmu_alloc_format_attr_group(struct arm_cspmu *cspmu)
> return format_group;
> }
>
> -static struct attribute_group **
> -arm_cspmu_alloc_attr_group(struct arm_cspmu *cspmu)
> +static int arm_cspmu_alloc_attr_groups(struct arm_cspmu *cspmu)
> {
> - struct attribute_group **attr_groups = NULL;
> - struct device *dev = cspmu->dev;
> + const struct attribute_group **attr_groups = cspmu->attr_groups;
> const struct arm_cspmu_impl_ops *impl_ops = &cspmu->impl.ops;
>
> cspmu->identifier = impl_ops->get_identifier(cspmu);
> cspmu->name = impl_ops->get_name(cspmu);
>
> if (!cspmu->identifier || !cspmu->name)
> - return NULL;
> -
> - attr_groups = devm_kcalloc(dev, 5, sizeof(struct attribute_group *),
> - GFP_KERNEL);
> - if (!attr_groups)
> - return NULL;
> + return -ENOMEM;
>
> attr_groups[0] = arm_cspmu_alloc_event_attr_group(cspmu);
> attr_groups[1] = arm_cspmu_alloc_format_attr_group(cspmu);
> @@ -525,9 +518,9 @@ arm_cspmu_alloc_attr_group(struct arm_cspmu *cspmu)
> attr_groups[3] = &arm_cspmu_cpumask_attr_group;
>
> if (!attr_groups[0] || !attr_groups[1])
> - return NULL;
> + return -ENOMEM;
>
> - return attr_groups;
> + return 0;
> }
>
> static inline void arm_cspmu_reset_counters(struct arm_cspmu *cspmu)
> @@ -1166,11 +1159,10 @@ static int arm_cspmu_get_cpus(struct arm_cspmu *cspmu)
> static int arm_cspmu_register_pmu(struct arm_cspmu *cspmu)
> {
> int ret, capabilities;
> - struct attribute_group **attr_groups;
>
> - attr_groups = arm_cspmu_alloc_attr_group(cspmu);
> - if (!attr_groups)
> - return -ENOMEM;
> + ret = arm_cspmu_alloc_attr_groups(cspmu);
> + if (ret)
> + return ret;
>
> ret = cpuhp_state_add_instance(arm_cspmu_cpuhp_state,
> &cspmu->cpuhp_node);
> @@ -1192,7 +1184,7 @@ static int arm_cspmu_register_pmu(struct arm_cspmu *cspmu)
> .start = arm_cspmu_start,
> .stop = arm_cspmu_stop,
> .read = arm_cspmu_read,
> - .attr_groups = (const struct attribute_group **)attr_groups,
> + .attr_groups = cspmu->attr_groups,
> .capabilities = capabilities,
> };
>
> diff --git a/drivers/perf/arm_cspmu/arm_cspmu.h b/drivers/perf/arm_cspmu/arm_cspmu.h
> index 2fe723555a6b..c9163acfe810 100644
> --- a/drivers/perf/arm_cspmu/arm_cspmu.h
> +++ b/drivers/perf/arm_cspmu/arm_cspmu.h
> @@ -157,6 +157,7 @@ struct arm_cspmu {
> int cycle_counter_logical_idx;
>
> struct arm_cspmu_hw_events hw_events;
> + const struct attribute_group *attr_groups[5];
>
> struct arm_cspmu_impl impl;
> };
> --
> 2.39.2.101.g768bb238c484.dirty
>
>
next prev parent reply other threads:[~2023-12-07 2:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 16:51 [PATCH 0/5] perf/arm_cspmu: Add devicetree support Robin Murphy
2023-12-05 16:51 ` [PATCH 1/5] perf/arm_cspmu: Simplify initialisation Robin Murphy
2023-12-07 2:16 ` Ilkka Koskinen
2023-12-05 16:51 ` [PATCH 2/5] perf/arm_cspmu: Simplify attribute groups Robin Murphy
2023-12-07 2:47 ` Ilkka Koskinen [this message]
2023-12-05 16:51 ` [PATCH 3/5] perf/arm_cspmu: Simplify counter reset Robin Murphy
2023-12-07 2:15 ` Ilkka Koskinen
2023-12-05 16:51 ` [PATCH 4/5] dt-bindings/perf: Add Arm CoreSight PMU Robin Murphy
2023-12-08 19:33 ` Rob Herring
2023-12-08 21:56 ` Robin Murphy
2023-12-05 16:51 ` [PATCH 5/5] perf/arm_cspmu: Add devicetree support Robin Murphy
2023-12-06 23:43 ` Ilkka Koskinen
2023-12-07 9:43 ` Robin Murphy
2023-12-08 6:35 ` Ilkka Koskinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5ee6f058-a8eb-4b5b-4b0-3123e77a998b@os.amperecomputing.com \
--to=ilkka@os.amperecomputing.com \
--cc=YWan@nvidia.com \
--cc=bwicaksono@nvidia.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=robin.murphy@arm.com \
--cc=rwiley@nvidia.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).