[PATCH v2 1/2] drm/amd/pm: Add gpu_metrics_v1_7

Wang, Yang(Kevin) KevinYang.Wang at amd.com
Wed Nov 13 08:35:15 UTC 2024


[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Asad Kamal
Sent: Wednesday, November 13, 2024 16:25
To: amd-gfx at lists.freedesktop.org; Lazar, Lijo <Lijo.Lazar at amd.com>
Cc: Ma, Le <Le.Ma at amd.com>; Zhang, Hawking <Hawking.Zhang at amd.com>; Zhang, Morris <Shiwu.Zhang at amd.com>; Kamal, Asad <Asad.Kamal at amd.com>; Poag, Charis <Charis.Poag at amd.com>; Cheung, Donald <donald.cheung at amd.com>; Khatir, Sepehr <sepehr.khatir at amd.com>; Oliveira, Daniel <Daniel.Oliveira at amd.com>
Subject: [PATCH v2 1/2] drm/amd/pm: Add gpu_metrics_v1_7

Add new gpu_metrics_v1_7 to acquire xgmi link status, application counter and max vram bandwidth

v2: Use gpu_metrics_v1_7 for SMU_v_13_0_6 (Lijo)

Signed-off-by: Asad Kamal <asad.kamal at amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar at amd.com>
---
 .../gpu/drm/amd/include/kgd_pp_interface.h    | 110 ++++++++++++++++++
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c  |   8 +-
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c        |   3 +
 3 files changed, 117 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index ee8170cda1d7..a95935cc3d76 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -364,6 +364,17 @@ struct amdgpu_xcp_metrics {
        u64 gfx_busy_acc[MAX_XCC];
 };

+struct amdgpu_xcp_metrics_v1_1 {
+       /* Utilization Instantaneous (%) */
+       u32 gfx_busy_inst[MAX_XCC];
+       u16 jpeg_busy[NUM_JPEG_ENG];
+       u16 vcn_busy[NUM_VCN];
+       /* Utilization Accumulated (%) */
+       u64 gfx_busy_acc[MAX_XCC];
+       /* Total App Clock Counter Accumulated */
+       u64 gfx_below_host_limit_acc[MAX_XCC];
+};
[kevin]:

It is better to change the type to 'uint64/32/16_t' (stdint.h) to indicate that it is a uapi interface.

With fixed,

Reviewed-by: Yang Wang <kevinyang.wang at amd.com>

Best Regards,
Kevin
+
 struct amd_pm_funcs {
 /* export for dpm on ci and si */
        int (*pre_set_power_state)(void *handle); @@ -979,6 +990,105 @@ struct gpu_metrics_v1_6 {
        uint32_t                        pcie_lc_perf_other_end_recovery;
 };

+struct gpu_metrics_v1_7 {
+       struct metrics_table_header     common_header;
+
+       /* Temperature (Celsius) */
+       uint16_t                        temperature_hotspot;
+       uint16_t                        temperature_mem;
+       uint16_t                        temperature_vrsoc;
+
+       /* Power (Watts) */
+       uint16_t                        curr_socket_power;
+
+       /* Utilization (%) */
+       uint16_t                        average_gfx_activity;
+       uint16_t                        average_umc_activity; // memory controller
+
+       /* VRAM max bandwidthi (in GB/sec) at max memory clock */
+       uint64_t                        mem_max_bandwidth;
+
+       /* Energy (15.259uJ (2^-16) units) */
+       uint64_t                        energy_accumulator;
+
+       /* Driver attached timestamp (in ns) */
+       uint64_t                        system_clock_counter;
+
+       /* Accumulation cycle counter */
+       uint32_t                        accumulation_counter;
+
+       /* Accumulated throttler residencies */
+       uint32_t                        prochot_residency_acc;
+       uint32_t                        ppt_residency_acc;
+       uint32_t                        socket_thm_residency_acc;
+       uint32_t                        vr_thm_residency_acc;
+       uint32_t                        hbm_thm_residency_acc;
+
+       /* Clock Lock Status. Each bit corresponds to clock instance */
+       uint32_t                        gfxclk_lock_status;
+
+       /* Link width (number of lanes) and speed (in 0.1 GT/s) */
+       uint16_t                        pcie_link_width;
+       uint16_t                        pcie_link_speed;
+
+       /* XGMI bus width and bitrate (in Gbps) */
+       uint16_t                        xgmi_link_width;
+       uint16_t                        xgmi_link_speed;
+
+       /* Utilization Accumulated (%) */
+       uint32_t                        gfx_activity_acc;
+       uint32_t                        mem_activity_acc;
+
+       /*PCIE accumulated bandwidth (GB/sec) */
+       uint64_t                        pcie_bandwidth_acc;
+
+       /*PCIE instantaneous bandwidth (GB/sec) */
+       uint64_t                        pcie_bandwidth_inst;
+
+       /* PCIE L0 to recovery state transition accumulated count */
+       uint64_t                        pcie_l0_to_recov_count_acc;
+
+       /* PCIE replay accumulated count */
+       uint64_t                        pcie_replay_count_acc;
+
+       /* PCIE replay rollover accumulated count */
+       uint64_t                        pcie_replay_rover_count_acc;
+
+       /* PCIE NAK sent  accumulated count */
+       uint32_t                        pcie_nak_sent_count_acc;
+
+       /* PCIE NAK received accumulated count */
+       uint32_t                        pcie_nak_rcvd_count_acc;
+
+       /* XGMI accumulated data transfer size(KiloBytes) */
+       uint64_t                        xgmi_read_data_acc[NUM_XGMI_LINKS];
+       uint64_t                        xgmi_write_data_acc[NUM_XGMI_LINKS];
+
+       /* XGMI link status(active/inactive) */
+       uint16_t                        xgmi_link_status[NUM_XGMI_LINKS];
+
+       uint16_t                        padding;
+
+       /* PMFW attached timestamp (10ns resolution) */
+       uint64_t                        firmware_timestamp;
+
+       /* Current clocks (Mhz) */
+       uint16_t                        current_gfxclk[MAX_GFX_CLKS];
+       uint16_t                        current_socclk[MAX_CLKS];
+       uint16_t                        current_vclk0[MAX_CLKS];
+       uint16_t                        current_dclk0[MAX_CLKS];
+       uint16_t                        current_uclk;
+
+       /* Number of current partition */
+       uint16_t                        num_partition;
+
+       /* XCP metrics stats */
+       struct amdgpu_xcp_metrics_v1_1  xcp_stats[NUM_XCP];
+
+       /* PCIE other end recovery counter */
+       uint32_t                        pcie_lc_perf_other_end_recovery;
+};
+
 /*
  * gpu_metrics_v2_0 is not recommended as it's not naturally aligned.
  * Use gpu_metrics_v2_1 or later instead.
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
index fa30a9e1f27a..11ecaa62f419 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
@@ -370,7 +370,7 @@ static int smu_v13_0_6_tables_init(struct smu_context *smu)
                return -ENOMEM;
        smu_table->metrics_time = 0;

-       smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v1_6);
+       smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v1_7);
        smu_table->gpu_metrics_table =
                kzalloc(smu_table->gpu_metrics_table_size, GFP_KERNEL);
        if (!smu_table->gpu_metrics_table) {
@@ -2321,8 +2321,8 @@ static ssize_t smu_v13_0_6_get_gpu_metrics(struct smu_context *smu, void **table  {
        bool per_inst, smu_13_0_6_per_inst, smu_13_0_14_per_inst, apu_per_inst;
        struct smu_table_context *smu_table = &smu->smu_table;
-       struct gpu_metrics_v1_6 *gpu_metrics =
-               (struct gpu_metrics_v1_6 *)smu_table->gpu_metrics_table;
+       struct gpu_metrics_v1_7 *gpu_metrics =
+               (struct gpu_metrics_v1_7 *)smu_table->gpu_metrics_table;
        bool flag = smu_v13_0_6_is_unified_metrics(smu);
        int ret = 0, xcc_id, inst, i, j, k, idx;
        struct amdgpu_device *adev = smu->adev; @@ -2341,7 +2341,7 @@ static ssize_t smu_v13_0_6_get_gpu_metrics(struct smu_context *smu, void **table

        metrics_a = (MetricsTableA_t *)metrics_x;

-       smu_cmn_init_soft_gpu_metrics(gpu_metrics, 1, 6);
+       smu_cmn_init_soft_gpu_metrics(gpu_metrics, 1, 7);

        gpu_metrics->temperature_hotspot =
                SMUQ10_ROUND(GET_METRIC_FIELD(MaxSocketTemperature, flag)); diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
index fd2aa949538e..a9e69d321f8c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
@@ -1081,6 +1081,9 @@ void smu_cmn_init_soft_gpu_metrics(void *table, uint8_t frev, uint8_t crev)
        case METRICS_VERSION(1, 6):
                structure_size = sizeof(struct gpu_metrics_v1_6);
                break;
+       case METRICS_VERSION(1, 7):
+               structure_size = sizeof(struct gpu_metrics_v1_7);
+               break;
        case METRICS_VERSION(2, 0):
                structure_size = sizeof(struct gpu_metrics_v2_0);
                break;
--
2.46.0



More information about the amd-gfx mailing list