public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Gowthami Thiagarajan <gthiagarajan@marvell.com>
Cc: <will@kernel.org>, <mark.rutland@arm.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <gcherian@marvell.com>,
	<bbhushan2@marvell.com>, <sgoutham@marvell.com>
Subject: Re: [PATCH v8 3/6] perf/marvell: Refactor to add version - no functional change
Date: Tue, 24 Sep 2024 17:23:32 +0100	[thread overview]
Message-ID: <20240924172332.00003dbf@Huawei.com> (raw)
In-Reply-To: <20240919074717.3276854-4-gthiagarajan@marvell.com>

On Thu, 19 Sep 2024 13:17:14 +0530
Gowthami Thiagarajan <gthiagarajan@marvell.com> wrote:

> This change is aimed at improving the maintainability of the code and
> laying the groundwork for versioning within the driver.
> 
> No functional changes are introduced in this commit; the driver's
> behavior and performance remain unchanged.
> 
> Signed-off-by: Gowthami Thiagarajan <gthiagarajan@marvell.com>

Versioning like this tends to scale badly as more versions turn up.
Can you just use more data in your pdata instead?
A template of the struct pmu that you copy and a callback for necessary
init that is version specific.

> ---
>  drivers/perf/marvell_cn10k_ddr_pmu.c | 63 ++++++++++++++++++----------
>  1 file changed, 42 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/perf/marvell_cn10k_ddr_pmu.c b/drivers/perf/marvell_cn10k_ddr_pmu.c
> index 648ad3a740bf..65422fd5ddd2 100644
> --- a/drivers/perf/marvell_cn10k_ddr_pmu.c
> +++ b/drivers/perf/marvell_cn10k_ddr_pmu.c
> @@ -124,10 +124,19 @@
>  #define CN10K_DDRC_PERF_CNT_VALUE_WR_OP		0x80D0
>  #define CN10K_DDRC_PERF_CNT_VALUE_RD_OP		0x80D8
>  
> +enum mrvl_ddr_pmu_version {
> +	DDR_PMU_V1 = 1,
> +};
> +
> +struct ddr_pmu_data {
> +	int id;
I don't see the point in this. Use the pdata structure
for this purpose and push anything else necessary into there.
Don't have an ID. That scales very badly as more device
types turn up over time.

> +};
> +
>  struct cn10k_ddr_pmu {
>  	struct pmu pmu;
>  	void __iomem *base;
>  	const struct ddr_pmu_platform_data *p_data;
> +	int version;
>  	unsigned int cpu;
>  	struct	device *dev;
>  	int active_events;
> @@ -738,12 +747,19 @@ static const struct ddr_pmu_platform_data cn10k_ddr_pmu_pdata = {
>  	.ops = &ddr_pmu_ops,
>  };
>  
> +#if defined(CONFIG_ACPI) || defined(CONFIG_OF)
> +static const struct ddr_pmu_data ddr_pmu_data = {
> +	.id   = DDR_PMU_V1,
> +};
> +#endif
> +
>  static int cn10k_ddr_perf_probe(struct platform_device *pdev)
>  {
>  	const struct ddr_pmu_data *dev_data;
>  	struct cn10k_ddr_pmu *ddr_pmu;
>  	struct resource *res;
>  	void __iomem *base;
> +	int version;
>  	char *name;
>  	int ret;
>  
> @@ -760,31 +776,36 @@ static int cn10k_ddr_perf_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> +	version = dev_data->id;
> +	ddr_pmu->version = version;
> +
>  	base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
>  	if (IS_ERR(base))
>  		return PTR_ERR(base);
>  
>  	ddr_pmu->base = base;
>  
> -	ddr_pmu->p_data = &cn10k_ddr_pmu_pdata;
> -	/* Setup the PMU counter to work in manual mode */
> -	writeq_relaxed(OP_MODE_CTRL_VAL_MANUAL, ddr_pmu->base +
> -		       ddr_pmu->p_data->ddrc_perf_cnt_op_mode_ctrl);
> -
> -	ddr_pmu->pmu = (struct pmu) {
> -		.module	      = THIS_MODULE,
> -		.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
> -		.task_ctx_nr = perf_invalid_context,
> -		.attr_groups = cn10k_attr_groups,
> -		.event_init  = cn10k_ddr_perf_event_init,
> -		.add	     = cn10k_ddr_perf_event_add,
> -		.del	     = cn10k_ddr_perf_event_del,
> -		.start	     = cn10k_ddr_perf_event_start,
> -		.stop	     = cn10k_ddr_perf_event_stop,
> -		.read	     = cn10k_ddr_perf_event_update,
> -		.pmu_enable  = cn10k_ddr_perf_pmu_enable,
> -		.pmu_disable = cn10k_ddr_perf_pmu_disable,
> -	};
> +	if (version == DDR_PMU_V1) {
> +		ddr_pmu->p_data = &cn10k_ddr_pmu_pdata;
> +		/* Setup the PMU counter to work in manual mode */
> +		writeq_relaxed(OP_MODE_CTRL_VAL_MANUAL, ddr_pmu->base +
> +			       ddr_pmu->p_data->ddrc_perf_cnt_op_mode_ctrl);
> +
> +		ddr_pmu->pmu = (struct pmu) {
> +			.module	      = THIS_MODULE,
> +			.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
> +			.task_ctx_nr = perf_invalid_context,
> +			.attr_groups = cn10k_attr_groups,
> +			.event_init  = cn10k_ddr_perf_event_init,
> +			.add	     = cn10k_ddr_perf_event_add,
> +			.del	     = cn10k_ddr_perf_event_del,
> +			.start	     = cn10k_ddr_perf_event_start,
> +			.stop	     = cn10k_ddr_perf_event_stop,
> +			.read	     = cn10k_ddr_perf_event_update,
> +			.pmu_enable  = cn10k_ddr_perf_pmu_enable,
> +			.pmu_disable = cn10k_ddr_perf_pmu_disable,
> +		};
> +	}
>  
>  	/* Choose this cpu to collect perf data */
>  	ddr_pmu->cpu = raw_smp_processor_id();
> @@ -827,7 +848,7 @@ static void cn10k_ddr_perf_remove(struct platform_device *pdev)
>  
>  #ifdef CONFIG_OF
>  static const struct of_device_id cn10k_ddr_pmu_of_match[] = {
> -	{ .compatible = "marvell,cn10k-ddr-pmu", },
> +	{ .compatible = "marvell,cn10k-ddr-pmu", .data = &ddr_pmu_data},
>  	{ },
>  };
>  MODULE_DEVICE_TABLE(of, cn10k_ddr_pmu_of_match);
> @@ -835,7 +856,7 @@ MODULE_DEVICE_TABLE(of, cn10k_ddr_pmu_of_match);
>  
>  #ifdef CONFIG_ACPI
>  static const struct acpi_device_id cn10k_ddr_pmu_acpi_match[] = {
> -	{"MRVL000A", 0},
> +	{"MRVL000A", (kernel_ulong_t)&ddr_pmu_data},

Use the pdata itself for this, not a structure just used to get an ID
to then look it up in code.

>  	{},
>  };
>  MODULE_DEVICE_TABLE(acpi, cn10k_ddr_pmu_acpi_match);


  reply	other threads:[~2024-09-24 16:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-19  7:47 [PATCH v8 0/6] Marvell Odyssey uncore performance monitor support Gowthami Thiagarajan
2024-09-19  7:47 ` [PATCH v8 1/6] perf/marvell: Refactor to extract platform data - no functional change Gowthami Thiagarajan
2024-09-24 16:18   ` Jonathan Cameron
2024-09-19  7:47 ` [PATCH v8 2/6] perf/marvell: Refactor to extract platform specific ops " Gowthami Thiagarajan
2024-09-24 16:19   ` Jonathan Cameron
2024-09-19  7:47 ` [PATCH v8 3/6] perf/marvell: Refactor to add version " Gowthami Thiagarajan
2024-09-24 16:23   ` Jonathan Cameron [this message]
2024-09-19  7:47 ` [PATCH v8 4/6] perf/marvell: Odyssey DDR Performance monitor support Gowthami Thiagarajan
2024-09-24 16:28   ` Jonathan Cameron
2024-09-19  7:47 ` [PATCH v8 5/6] perf/marvell : Refactor to extract platform data - no functional change Gowthami Thiagarajan
2024-09-19  7:47 ` [PATCH v8 6/6] perf/marvell : Odyssey LLC-TAD performance monitor support Gowthami Thiagarajan

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=20240924172332.00003dbf@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=bbhushan2@marvell.com \
    --cc=gcherian@marvell.com \
    --cc=gthiagarajan@marvell.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=sgoutham@marvell.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