Skip to content

Commit e784116

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

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "aie2_pci.h"
7+
#include <linux/amd-pmf-io.h>
78

89
#define SMU_RESULT_OK 1
910

@@ -51,6 +52,22 @@ static int aie2_smu_exec(struct amdxdna_dev_hdl *ndev, u32 reg_cmd,
5152
return 0;
5253
}
5354

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

110127
int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev)
111128
{
129+
#if LINUX_VERSION_CODE > KERNEL_VERSION(6, 18, 0)
130+
int ret = aie2_smu_get_npu_metrics(ndev);
131+
132+
if (ret)
133+
return -EINVAL;
134+
135+
return ndev->npu_metrics_info.mpnpuclk_freq;
136+
#endif
112137
return ndev->npuclk_freq;
113138
}
114139

115140
int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev)
116141
{
142+
#if LINUX_VERSION_CODE > KERNEL_VERSION(6, 18, 0)
143+
int ret = aie2_smu_get_npu_metrics(ndev);
144+
145+
if (ret)
146+
return -EINVAL;
147+
148+
return ndev->npu_metrics_info.npuclk_freq;
149+
#endif
150+
117151
return ndev->hclk_freq;
118152
}
119153

0 commit comments

Comments
 (0)