Skip to content

Commit 45112e7

Browse files
committed
Add realtime pmf npu metrics.
Signed-off-by: vinit shukla <[email protected]>
1 parent c5e45a7 commit 45112e7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/driver/amdxdna/aie2_pci.h

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

263+
struct npu_metrics {
264+
u16 npuclk_freq;
265+
u16 npu_busy[8];
266+
u16 npu_power;
267+
u16 mpnpuclk_freq;
268+
u16 npu_reads;
269+
u16 npu_writes;
270+
};
271+
263272
struct aie2_partition {
264273
#define CTX_RQ_REALTIME 0
265274
#define CTX_RQ_HIGH 1
@@ -325,6 +334,7 @@ struct amdxdna_dev_hdl {
325334
u32 total_col;
326335
struct aie_version version;
327336
struct aie_metadata metadata;
337+
struct npu_metrics npu_metrics_info;
328338

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

src/driver/amdxdna/aie2_smu.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
*/
55

66
#include "aie2_pci.h"
7+
#include <linux/version.h>
8+
#include <linux/amd-pmf-io.h>
9+
10+
#if KERNEL_VERSION(6, 18, 0) < LINUX_VERSION_CODE
11+
#define PMF_NPU_METRICS
12+
#endif
713

814
#define SMU_RESULT_OK 1
915

@@ -51,6 +57,22 @@ static int aie2_smu_exec(struct amdxdna_dev_hdl *ndev, u32 reg_cmd,
5157
return 0;
5258
}
5359

60+
#ifdef PMF_NPU_METRICS
61+
static int aie2_smu_get_npu_metrics(struct amdxdna_dev_hdl *ndev)
62+
{
63+
struct amd_pmf_npu_metrics data;
64+
int ret;
65+
66+
/* Get NPU metrics from the PMF interface */
67+
ret = amd_pmf_get_npu_data(&data);
68+
if (ret)
69+
return ret;
70+
71+
memcpy(&ndev->npu_metrics_info, &data, sizeof(data));
72+
return 0;
73+
}
74+
#endif
75+
5476
int npu1_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level)
5577
{
5678
u32 freq;
@@ -109,11 +131,28 @@ int npu4_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level)
109131

110132
int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev)
111133
{
134+
#ifdef PMF_NPU_METRICS
135+
int ret = aie2_smu_get_npu_metrics(ndev);
136+
137+
if (ret)
138+
return ret;
139+
140+
return ndev->npu_metrics_info.mpnpuclk_freq;
141+
#endif
112142
return ndev->npuclk_freq;
113143
}
114144

115145
int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev)
116146
{
147+
#ifdef PMF_NPU_METRICS
148+
int ret = aie2_smu_get_npu_metrics(ndev);
149+
150+
if (ret)
151+
return ret;
152+
153+
return ndev->npu_metrics_info.npuclk_freq;
154+
#endif
155+
117156
return ndev->hclk_freq;
118157
}
119158

0 commit comments

Comments
 (0)