]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/amdgpu: add the sensor value of VCN activity
authorXiaojian Du <Xiaojian.Du@amd.com>
Fri, 8 Mar 2024 07:48:48 +0000 (15:48 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 20 Mar 2024 17:37:37 +0000 (13:37 -0400)
This will add the sensor value of VCN activity for some ASICs.

Signed-off-by: Xiaojian Du <Xiaojian.Du@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/amdgpu_pm.c

index 32054ecf0b87e342453485d86d0329565cddb4c5..afb930b706154ab2fc7e1f3e9414107817f0fa6d 100644 (file)
@@ -150,6 +150,7 @@ enum amd_pp_sensors {
        AMDGPU_PP_SENSOR_VCN_POWER_STATE,
        AMDGPU_PP_SENSOR_PEAK_PSTATE_SCLK,
        AMDGPU_PP_SENSOR_PEAK_PSTATE_MCLK,
+       AMDGPU_PP_SENSOR_VCN_LOAD,
 };
 
 enum amd_pp_task {
index f09b9d49297e815f469cc54be1c1130711576a12..efc631bddf4a1750153c89786111dee2be44305c 100644 (file)
@@ -1581,6 +1581,30 @@ static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
        return sysfs_emit(buf, "%d\n", value);
 }
 
+/**
+ * DOC: vcn_busy_percent
+ *
+ * The amdgpu driver provides a sysfs API for reading how busy the VCN
+ * is as a percentage.  The file vcn_busy_percent is used for this.
+ * The SMU firmware computes a percentage of load based on the
+ * aggregate activity level in the IP cores.
+ */
+static ssize_t amdgpu_get_vcn_busy_percent(struct device *dev,
+                                                 struct device_attribute *attr,
+                                                 char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       unsigned int value;
+       int r;
+
+       r = amdgpu_hwmon_get_sensor_generic(adev, AMDGPU_PP_SENSOR_VCN_LOAD, &value);
+       if (r)
+               return r;
+
+       return sysfs_emit(buf, "%d\n", value);
+}
+
 /**
  * DOC: pcie_bw
  *
@@ -2180,6 +2204,7 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
                              .attr_update = pp_od_clk_voltage_attr_update),
        AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent,                         ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
        AMDGPU_DEVICE_ATTR_RO(mem_busy_percent,                         ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
+       AMDGPU_DEVICE_ATTR_RO(vcn_busy_percent,         ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
        AMDGPU_DEVICE_ATTR_RO(pcie_bw,                                  ATTR_FLAG_BASIC),
        AMDGPU_DEVICE_ATTR_RW(pp_features,                              ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
        AMDGPU_DEVICE_ATTR_RO(unique_id,                                ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
@@ -2223,6 +2248,15 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
                     gc_ver != IP_VERSION(9, 4, 3)) ||
                    gc_ver == IP_VERSION(9, 0, 1))
                        *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(vcn_busy_percent)) {
+               if (!(gc_ver == IP_VERSION(10, 3, 1) ||
+                         gc_ver == IP_VERSION(10, 3, 3) ||
+                         gc_ver == IP_VERSION(10, 3, 6) ||
+                         gc_ver == IP_VERSION(10, 3, 7) ||
+                         gc_ver == IP_VERSION(11, 0, 1) ||
+                         gc_ver == IP_VERSION(11, 0, 4) ||
+                         gc_ver == IP_VERSION(11, 5, 0)))
+                       *states = ATTR_STATE_UNSUPPORTED;
        } else if (DEVICE_ATTR_IS(pcie_bw)) {
                /* PCIe Perf counters won't work on APU nodes */
                if (adev->flags & AMD_IS_APU ||
@@ -4429,6 +4463,9 @@ static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *a
        /* MEM Load */
        if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
                seq_printf(m, "MEM Load: %u %%\n", value);
+       /* VCN Load */
+       if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_LOAD, (void *)&value, &size))
+               seq_printf(m, "VCN Load: %u %%\n", value);
 
        seq_printf(m, "\n");