The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lizhi Hou" <lizhi.hou@amd.com>
Cc: Hans de Goede <hansg@kernel.org>,
	ogabbay@kernel.org, quic_jhugo@quicinc.com,
	maciej.falkowski@linux.intel.com,
	LKML <linux-kernel@vger.kernel.org>,
	max.zhen@amd.com, sonal.santan@amd.com,
	mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org,
	dri-devel@lists.freedesktop.org, VinitKumar.Shukla@amd.com,
	Patil Rajesh Reddy <Patil.Reddy@amd.com>
Subject: Re: [PATCH V1 1/2] platform/x86/amd/pmf: Introduce new interface to export NPU metrics
Date: Fri, 12 Dec 2025 11:30:29 +0530	[thread overview]
Message-ID: <b3ed5b11-c0cb-46c5-a498-95e6ba6f4e01@amd.com> (raw)
In-Reply-To: <5217a9b3-8489-fd18-051a-46a497ff56bd@linux.intel.com>



On 12/11/2025 23:58, Ilpo Järvinen wrote:
> On Thu, 11 Dec 2025, Lizhi Hou wrote:
> 
>> From: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
>>
>> The PMF driver retrieves NPU metrics data from the PMFW. Introduce a new
>> interface to make NPU metrics accessible to other drivers like AMDXDNA
>> driver, which can access and utilize this information as needed.
>>
>> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
>> 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>
>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
>> ---
>>  drivers/platform/x86/amd/pmf/core.c | 75 +++++++++++++++++++++++++++++
>>  drivers/platform/x86/amd/pmf/pmf.h  |  2 +
>>  include/linux/amd-pmf-io.h          | 21 ++++++++
>>  3 files changed, 98 insertions(+)
>>
>> diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
>> index a6a5d416edf9..8e4ce91b3527 100644
>> --- a/drivers/platform/x86/amd/pmf/core.c
>> +++ b/drivers/platform/x86/amd/pmf/core.c
>> @@ -8,12 +8,15 @@
>>   * Author: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
>>   */
>>  
>> +#include <linux/array_size.h>
>> +#include <linux/cleanup.h>
>>  #include <linux/debugfs.h>
>>  #include <linux/iopoll.h>
>>  #include <linux/module.h>
>>  #include <linux/pci.h>
>>  #include <linux/platform_device.h>
>>  #include <linux/power_supply.h>
>> +#include <linux/string.h>
>>  #include <asm/amd/node.h>
>>  #include "pmf.h"
>>  
>> @@ -53,6 +56,8 @@ static bool force_load;
>>  module_param(force_load, bool, 0444);
>>  MODULE_PARM_DESC(force_load, "Force load this driver on supported older platforms (experimental)");
>>  
>> +static struct device *pmf_device;
>> +
>>  static int amd_pmf_pwr_src_notify_call(struct notifier_block *nb, unsigned long event, void *data)
>>  {
>>  	struct amd_pmf_dev *pmf = container_of(nb, struct amd_pmf_dev, pwr_src_notifier);
>> @@ -314,6 +319,70 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
>>  	return 0;
>>  }
>>  
>> +static int is_npu_metrics_supported(struct amd_pmf_dev *pdev)
>> +{
>> +	switch (pdev->cpu_id) {
>> +	case PCI_DEVICE_ID_AMD_1AH_M20H_ROOT:
>> +	case PCI_DEVICE_ID_AMD_1AH_M60H_ROOT:
>> +		return 0;
>> +	default:
>> +		return -EOPNOTSUPP;
>> +	}
>> +}
>> +
>> +static int amd_pmf_get_smu_metrics(struct amd_pmf_dev *dev, struct amd_pmf_npu_metrics *data)
>> +{
>> +	int ret, i;
>> +
>> +	guard(mutex)(&dev->metrics_mutex);
>> +
>> +	if (is_npu_metrics_supported(dev))
>> +		return -EOPNOTSUPP;
>> +
>> +	ret = amd_pmf_set_dram_addr(dev, true);
>> +	if (ret)
>> +		return ret;
>> +
>> +	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;
>> +	}
>> +
>> +	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;
>> +
>> +	return 0;
>> +}
>> +
>> +int amd_pmf_get_npu_data(struct amd_pmf_npu_metrics *info)
>> +{
>> +	struct amd_pmf_dev *pdev;
>> +
>> +	if (!info)
>> +		return -EINVAL;
>> +
>> +	if (!pmf_device)
>> +		return -ENODEV;
>> +
>> +	pdev = dev_get_drvdata(pmf_device);
>> +	if (!pdev)
>> +		return -ENODEV;
>> +
>> +	return amd_pmf_get_smu_metrics(pdev, info);
>> +}
>> +EXPORT_SYMBOL_GPL(amd_pmf_get_npu_data);
>> +
>>  static int amd_pmf_suspend_handler(struct device *dev)
>>  {
>>  	struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
>> @@ -469,6 +538,10 @@ static int amd_pmf_probe(struct platform_device *pdev)
>>  	mutex_init(&dev->update_mutex);
>>  	mutex_init(&dev->cb_mutex);
>>  
>> +	err = devm_mutex_init(dev->dev, &dev->metrics_mutex);
>> +	if (err)
>> +		return err;
>> +
>>  	apmf_acpi_init(dev);
>>  	platform_set_drvdata(pdev, dev);
>>  	amd_pmf_dbgfs_register(dev);
>> @@ -477,6 +550,8 @@ static int amd_pmf_probe(struct platform_device *pdev)
>>  	if (is_apmf_func_supported(dev, APMF_FUNC_SBIOS_HEARTBEAT_V2))
>>  		amd_pmf_notify_sbios_heartbeat_event_v2(dev, ON_LOAD);
>>  
>> +	pmf_device = dev->dev;
>> +
>>  	dev_info(dev->dev, "registered PMF device successfully\n");
>>  
>>  	return 0;
>> diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
>> index f07e9f4c660a..0354cc5dc79e 100644
>> --- a/drivers/platform/x86/amd/pmf/pmf.h
>> +++ b/drivers/platform/x86/amd/pmf/pmf.h
>> @@ -12,6 +12,7 @@
>>  #define PMF_H
>>  
>>  #include <linux/acpi.h>
>> +#include <linux/amd-pmf-io.h>
>>  #include <linux/input.h>
>>  #include <linux/platform_device.h>
>>  #include <linux/platform_profile.h>
>> @@ -412,6 +413,7 @@ struct amd_pmf_dev {
>>  	struct apmf_sbios_req_v1 req1;
>>  	struct pmf_bios_inputs_prev cb_prev; /* To preserve custom BIOS inputs */
>>  	bool cb_flag;			     /* To handle first custom BIOS input */
>> +	struct mutex metrics_mutex;
> 
> This files seems to lack include for struct mutex (despite using them 
> already so please add it finally there :-)).

This is already taken care in one of the patch already in queue.

https://patchwork.kernel.org/project/platform-driver-x86/patch/20251202042219.245173-1-Shyam-sundar.S-k@amd.com/

Thanks,
Shyam


  parent reply	other threads:[~2025-12-12  6:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 17:58 [PATCH V1 0/2] Get real time power input via AMD PMF Lizhi Hou
2025-12-11 17:58 ` [PATCH V1 1/2] platform/x86/amd/pmf: Introduce new interface to export NPU metrics Lizhi Hou
2025-12-11 18:28   ` Ilpo Järvinen
2025-12-11 19:07     ` Lizhi Hou
2025-12-12  6:00     ` Shyam Sundar S K [this message]
2025-12-11 17:58 ` [PATCH V2 2/2] accel/amdxdna: Add IOCTL to retrieve realtime NPU power estimate Lizhi Hou
2025-12-11 18:20   ` Mario Limonciello
2025-12-11 18:24   ` Ilpo Järvinen
2025-12-11 19:06     ` Lizhi Hou
2025-12-12  6:01   ` Shyam Sundar S K
2025-12-11 18:22 ` [PATCH V1 0/2] Get real time power input via AMD PMF Mario Limonciello
2025-12-11 19:16   ` Lizhi Hou

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=b3ed5b11-c0cb-46c5-a498-95e6ba6f4e01@amd.com \
    --to=shyam-sundar.s-k@amd.com \
    --cc=Patil.Reddy@amd.com \
    --cc=VinitKumar.Shukla@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=maciej.falkowski@linux.intel.com \
    --cc=mario.limonciello@amd.com \
    --cc=max.zhen@amd.com \
    --cc=ogabbay@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=quic_jhugo@quicinc.com \
    --cc=sonal.santan@amd.com \
    /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