X86 platform drivers
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>,
	hansg@kernel.org, ilpo.jarvinen@linux.intel.com
Cc: platform-driver-x86@vger.kernel.org, Patil.Reddy@amd.com
Subject: Re: [PATCH 4/5] platform/x86/amd/pmf: Refactor NPU metrics for platform extensibility
Date: Fri, 10 Jul 2026 14:11:28 -0500	[thread overview]
Message-ID: <54e8969b-df1a-482e-8635-b6b8635a06b0@amd.com> (raw)
In-Reply-To: <20260710174219.2522269-5-Shyam-sundar.S-k@amd.com>



On 7/10/26 12:42, Shyam Sundar S K wrote:
> Refactor the NPU metrics retrieval code to use a switch-case structure
> based on CPU ID, preparing the driver for supporting additional
> platforms with different metrics table formats.
> 
> This change restructures amd_pmf_get_smu_metrics() to handle
> platform-specific metrics retrieval paths. The existing logic for
> 1AH_M20H and 1AH_M60H platforms is preserved within the switch-case
> block.
> 
> No functional changes.
> 
> Co-developed-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
> Signed-off-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
> Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

> ---
>   drivers/platform/x86/amd/pmf/metrics.c | 42 +++++++++++++++-----------
>   1 file changed, 24 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/metrics.c b/drivers/platform/x86/amd/pmf/metrics.c
> index bb4f9127c655..5a8ebacbc3b3 100644
> --- a/drivers/platform/x86/amd/pmf/metrics.c
> +++ b/drivers/platform/x86/amd/pmf/metrics.c
> @@ -9,6 +9,7 @@
>    *	    Patil Rajesh Reddy <Patil.Reddy@amd.com>
>    */
>   
> +#include <linux/array_size.h>
>   #include <linux/bits.h>
>   #include <linux/cleanup.h>
>   #include <linux/container_of.h>
> @@ -134,28 +135,33 @@ static int amd_pmf_get_smu_metrics(struct amd_pmf_dev *dev, struct amd_pmf_npu_m
>   	if (ret)
>   		return ret;
>   
> -	ret = amd_pmf_set_dram_addr(dev, true);
> -	if (ret)
> -		return ret;
> +	switch (dev->cpu_id) {
> +	case PCI_DEVICE_ID_AMD_1AH_M20H_ROOT:
> +	case PCI_DEVICE_ID_AMD_1AH_M60H_ROOT:
> +		ret = amd_pmf_set_dram_addr(dev, true);
> +		if (ret)
> +			return ret;
>   
> -	memset(dev->buf, 0, dev->mtable_size);
> +		memset(dev->buf, 0, dev->mtable_size);
>   
> -	/* Send SMU command to get NPU metrics */
> -	ret = amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, SET_CMD, METRICS_TABLE_ID, NULL);
> -	if (ret) {
> -		dev_err(dev->dev, "SMU command failed to get NPU metrics: %d\n", ret);
> -		return ret;
> -	}
> +		/* Send SMU command to get NPU metrics */
> +		ret = amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, SET_CMD, METRICS_TABLE_ID, NULL);
> +		if (ret) {
> +			dev_err(dev->dev, "SMU command failed to get NPU metrics: %d\n", ret);
> +			return ret;
> +		}
>   
> -	memcpy(&dev->m_table_v2, dev->buf, dev->mtable_size);
> +		memcpy(&dev->m_table_v2, dev->buf, dev->mtable_size);
>   
> -	data->npuclk_freq = dev->m_table_v2.npuclk_freq;
> -	for (i = 0; i < ARRAY_SIZE(data->npu_busy); i++)
> -		data->npu_busy[i] = dev->m_table_v2.npu_busy[i];
> -	data->npu_power = dev->m_table_v2.npu_power;
> -	data->mpnpuclk_freq = dev->m_table_v2.mpnpuclk_freq;
> -	data->npu_reads = dev->m_table_v2.npu_reads;
> -	data->npu_writes = dev->m_table_v2.npu_writes;
> +		data->npuclk_freq = dev->m_table_v2.npuclk_freq;
> +		for (i = 0; i < ARRAY_SIZE(data->npu_busy); i++)
> +			data->npu_busy[i] = dev->m_table_v2.npu_busy[i];
> +		data->npu_power = dev->m_table_v2.npu_power;
> +		data->mpnpuclk_freq = dev->m_table_v2.mpnpuclk_freq;
> +		data->npu_reads = dev->m_table_v2.npu_reads;
> +		data->npu_writes = dev->m_table_v2.npu_writes;
> +		break;
> +	}
>   
>   	return 0;
>   }


  reply	other threads:[~2026-07-10 19:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 17:42 [PATCH 0/5] platform/x86/amd/pmf: Add 1AH_M80H support and accumulator based NPU metrics Shyam Sundar S K
2026-07-10 17:42 ` [PATCH 1/5] platform/x86/amd/pmf: Use per-SoC smu_regs struct for SMU mailbox registers Shyam Sundar S K
2026-07-10 19:07   ` Mario Limonciello
2026-07-10 17:42 ` [PATCH 2/5] platform/x86/amd/pmf: Add 1AH_M80H device IDs and extended " Shyam Sundar S K
2026-07-10 19:10   ` Mario Limonciello
2026-07-13 18:37     ` Shyam Sundar S K
2026-07-13 18:40       ` Mario Limonciello
2026-07-10 17:42 ` [PATCH 3/5] platform/x86/amd/pmf: Move metrics code to dedicated file Shyam Sundar S K
2026-07-10 18:04   ` Ilpo Järvinen
2026-07-10 18:07     ` Ilpo Järvinen
2026-07-10 19:10   ` Mario Limonciello
2026-07-10 17:42 ` [PATCH 4/5] platform/x86/amd/pmf: Refactor NPU metrics for platform extensibility Shyam Sundar S K
2026-07-10 19:11   ` Mario Limonciello [this message]
2026-07-10 17:42 ` [PATCH 5/5] platform/x86/amd/pmf: Add 1AH_M80H metrics table and NPU metrics support Shyam Sundar S K
2026-07-10 18:16   ` Ilpo Järvinen
2026-07-13 18:39     ` Shyam Sundar S K
2026-07-10 18:21   ` Mario Limonciello

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=54e8969b-df1a-482e-8635-b6b8635a06b0@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Patil.Reddy@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=platform-driver-x86@vger.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