Skip to content

Commit 8c62136

Browse files
committed
Add realtime pmf npu metrics.
Signed-off-by: vinit shukla <[email protected]>
1 parent 6e2c124 commit 8c62136

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/driver/amdxdna/aie2_pci.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ enum aie2_power_state {
259259
SMU_POWER_ON,
260260
};
261261

262+
struct npu_metrics {
263+
u16 npuclk_freq;
264+
u16 npu_busy[8];
265+
u16 npu_power;
266+
u16 mpnpuclk_freq;
267+
u16 npu_reads;
268+
u16 npu_writes;
269+
};
270+
262271
struct aie2_partition {
263272
#define CTX_RQ_REALTIME 0
264273
#define CTX_RQ_HIGH 1
@@ -324,6 +333,7 @@ struct amdxdna_dev_hdl {
324333
u32 total_col;
325334
struct aie_version version;
326335
struct aie_metadata metadata;
336+
struct npu_metrics npu_metrics_info;
327337

328338
/*power management and clock */
329339
int pw_mode;

src/driver/amdxdna/aie2_smu.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include "aie2_pci.h"
77

8+
#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE
9+
#include <linux/amd-pmf-io.h>
10+
#endif
11+
812
#define SMU_RESULT_OK 1
913

1014
/* SMU commands */
@@ -51,6 +55,22 @@ static int aie2_smu_exec(struct amdxdna_dev_hdl *ndev, u32 reg_cmd,
5155
return 0;
5256
}
5357

58+
#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE
59+
static int aie2_smu_get_npu_metrics(struct amdxdna_dev_hdl *ndev)
60+
{
61+
struct amd_pmf_npu_metrics data;
62+
int ret;
63+
64+
/* Get NPU metrics from the PMF interface */
65+
ret = amd_pmf_get_npu_data(&data);
66+
if (ret)
67+
return ret;
68+
69+
memcpy(&ndev->npu_metrics_info, &data, sizeof(data));
70+
return 0;
71+
}
72+
#endif
73+
5474
int npu1_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level)
5575
{
5676
u32 freq;
@@ -109,11 +129,28 @@ int npu4_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level)
109129

110130
int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev)
111131
{
132+
133+
#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE
134+
int ret = aie2_smu_get_npu_metrics(ndev);
135+
if (ret)
136+
return -EINVAL;
137+
138+
return ndev->npu_metrics_info.mpnpuclk_freq;
139+
#endif
112140
return ndev->npuclk_freq;
113141
}
114142

115143
int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev)
116144
{
145+
146+
#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE
147+
int ret = aie2_smu_get_npu_metrics(ndev);
148+
if (ret)
149+
return -EINVAL;
150+
151+
return ndev->npu_metrics_info.npuclk_freq;
152+
#endif
153+
117154
return ndev->hclk_freq;
118155
}
119156

0 commit comments

Comments
 (0)