Skip to contentSkip to conversation

drm/amd/pm: fix pp_dpm_* clock reporting on SMU v14.0.0/v14.0.1 APUs

PATCH Superseded Priya Hosur 2 participants 7 messages Jun 12

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover drm/amd/pm: fix pp_dpm_* clock reporting on SMU v14.0.0/v14.0.1 APUs

Fix several pp_dpm_* sysfs entries on SMU v14.0.0 and v14.0.1 APUs (e.g. Radeon 8060S / GC 11.5.x) that either report incorrect values or never show the active-level "*" marker.

v4:
- Patch 1: instead of falling through to VclkFrequency for DCLK, match VclkFrequency to its DPM level index and report the DCLK frequency at the same level, since DCLK and VCLK have different DPM frequency tables (Lijo)
- Patch 4: added Reviewed-by from Lijo

v3:
- Patch 1: expanded inline comment to note that DCLK and VCLK have separate DPM tables even though SmuMetrics_t only has VclkFrequency (Lijo)
- Patch 4: dropped redundant exact_match bool; always use closest_idx to mark the active level (Lijo)

v2:
- Patch 1: dropped VCLK1/DCLK1 metric handlers (UINT_MAX -> N/A is correct; VCN1 only present on v14.0.1) (Lijo, Mario)
- Patch 4: break on exact match; early exit when DPM table is sorted and diff starts increasing (Lijo)

Priya Hosur (4):
drm/amd/pm: smu_v14_0_0: fix DCLK metric reporting via VCLK level
index
drm/amd/pm: add IP_VERSION(11,5,1) to vclk/dclk DPM sysfs whitelists drm/amd/pm: smu_v14_0_0: add SMU_DCEFCLK support in DPM frequency
queries
drm/amd/pm: smu_v14_0_0: add closest-match fallback for DPM level
marking

 drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  8 +-
 .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 97 ++++++++++++++++++-
 2 files changed, 98 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/4 drm/amd/pm: smu_v14_0_0: fix DCLK metric reporting via VCLK level index

SmuMetrics_t has no DclkFrequency field but DCLK and VCLK have separate DPM clock tables with different frequencies at each level.

For METRICS_AVERAGE_DCLK, find the DPM level whose VCLK frequency matches the reported VclkFrequency and return the DCLK frequency at that same level index, since both clocks share the same level count (VcnClkLevelsEnabled / Vcn0ClkLevelsEnabled).

The original code returned 0 for METRICS_AVERAGE_DCLK, which broke the active-level marker in pp_dpm_dclk entirely.

---
 .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +27 -0
index 2fe006de927a..c4c45c8dff69 100644
@@ -284,7 +284,34 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
 		*value = metrics->VclkFrequency;
 		break;
 	case METRICS_AVERAGE_DCLK:
+		/*
+		 * SmuMetrics_t has no DclkFrequency field.  DCLK and VCLK
+		 * share the same DPM level count, so find the DPM level
+		 * whose VCLK matches the reported VclkFrequency and return
+		 * the DCLK frequency at that level.
+		 */
 		*value = 0;
+		if (amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 1)) {
+			DpmClocks_t_v14_0_1 *clk_table = smu->smu_table.clocks_table;
+			uint8_t i, levels = clk_table->Vcn0ClkLevelsEnabled;
+
+			for (i = 0; i < levels; i++) {
+				if (clk_table->VClocks0[i] == metrics->VclkFrequency) {
+					*value = clk_table->DClocks0[i];
+					break;
+				}
+			}
+		} else {
+			DpmClocks_t *clk_table = smu->smu_table.clocks_table;
+			uint8_t i, levels = clk_table->VcnClkLevelsEnabled;
+
+			for (i = 0; i < levels; i++) {
+				if (clk_table->VClocks[i] == metrics->VclkFrequency) {
+					*value = clk_table->DClocks[i];
+					break;
+				}
+			}
+		}
 		break;
 	case METRICS_AVERAGE_UCLK:
 		*value = metrics->MemclkFrequency;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v4 1/4] drm/amd/pm: smu_v14_0_0: fix DCLK metric reporting via VCLK level index

Quoted 31 lines · Priya Hosur

SmuMetrics_t has no DclkFrequency field but DCLK and VCLK have separate DPM clock tables with different frequencies at each level.

For METRICS_AVERAGE_DCLK, find the DPM level whose VCLK frequency matches the reported VclkFrequency and return the DCLK frequency at that same level index, since both clocks share the same level count (VcnClkLevelsEnabled / Vcn0ClkLevelsEnabled).

The original code returned 0 for METRICS_AVERAGE_DCLK, which broke the active-level marker in pp_dpm_dclk entirely.

---
  .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 27 +++++++++++++++++++
  1 file changed, 27 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +6 -0
index 2fe006de927a..c4c45c8dff69 100644
@@ -284,7 +284,34 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
  		*value = metrics->VclkFrequency;
  		break;
  	case METRICS_AVERAGE_DCLK:
+		/*
+		 * SmuMetrics_t has no DclkFrequency field.  DCLK and VCLK
+		 * share the same DPM level count, so find the DPM level
+		 * whose VCLK matches the reported VclkFrequency and return
+		 * the DCLK frequency at that level.
+		 */
  		*value = 0;

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu, · line 303

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +10 -0
+		if (amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 1)) {
+			DpmClocks_t_v14_0_1 *clk_table = smu->smu_table.clocks_table;
+			uint8_t i, levels = clk_table->Vcn0ClkLevelsEnabled;
+
+			for (i = 0; i < levels; i++) {
+				if (clk_table->VClocks0[i] == metrics->VclkFrequency) {
+					*value = clk_table->DClocks0[i];
+					break;
+				}
+			}

I think it's better create a function - get_closest_level - as in patch 4 and use it at both places.

Thanks,
Lijo

Quoted 14 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +11 -0
+		} else {
+			DpmClocks_t *clk_table = smu->smu_table.clocks_table;
+			uint8_t i, levels = clk_table->VcnClkLevelsEnabled;
+
+			for (i = 0; i < levels; i++) {
+				if (clk_table->VClocks[i] == metrics->VclkFrequency) {
+					*value = clk_table->DClocks[i];
+					break;
+				}
+			}
+		}
  		break;
  	case METRICS_AVERAGE_UCLK:
  		*value = metrics->MemclkFrequency;
#3 lore raw

PATCH v4 2/4 drm/amd/pm: add IP_VERSION(11, 5, 1) to vclk/dclk DPM sysfs whitelists

In reply to Priya Hosur

Add IP_VERSION(11,5,1) to pp_dpm_vclk and pp_dpm_dclk visibility whitelists so these sysfs entries are exposed on Strix Halo (GC 11.5.1). Add IP_VERSION(11,5,1) to pp_dpm_vclk1 and pp_dpm_dclk1 whitelists with the existing num_vcn_inst >= 2 guard since Strix Halo has two VCN instances.

Without this, amd-smi reports N/A for VCLK0, VCLK1, DCLK0 and DCLK1 clocks.

---
 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -2
index dfebe67c164d..305852f5b153 100644
@@ -2027,6 +2027,7 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		      gc_ver == IP_VERSION(11, 0, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 4) ||
 		      gc_ver == IP_VERSION(11, 5, 0) ||
+		      gc_ver == IP_VERSION(11, 5, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 2) ||
 		      gc_ver == IP_VERSION(11, 0, 3) ||
 		      amdgpu_is_multi_aid(adev)))
@@ -2035,7 +2036,8 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		if (!((gc_ver == IP_VERSION(10, 3, 1) ||
 		       gc_ver == IP_VERSION(10, 3, 0) ||
 		       gc_ver == IP_VERSION(11, 0, 2) ||
-		       gc_ver == IP_VERSION(11, 0, 3)) && adev->vcn.num_vcn_inst >= 2))
+		       gc_ver == IP_VERSION(11, 0, 3) ||
+		       gc_ver == IP_VERSION(11, 5, 1)) && adev->vcn.num_vcn_inst >= 2))
 			*states = ATTR_STATE_UNSUPPORTED;
 	} else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
 		if (!(gc_ver == IP_VERSION(10, 3, 1) ||
@@ -2048,6 +2050,7 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		      gc_ver == IP_VERSION(11, 0, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 4) ||
 		      gc_ver == IP_VERSION(11, 5, 0) ||
+		      gc_ver == IP_VERSION(11, 5, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 2) ||
 		      gc_ver == IP_VERSION(11, 0, 3) ||
 		      amdgpu_is_multi_aid(adev)))
@@ -2056,7 +2059,8 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		if (!((gc_ver == IP_VERSION(10, 3, 1) ||
 		       gc_ver == IP_VERSION(10, 3, 0) ||
 		       gc_ver == IP_VERSION(11, 0, 2) ||
-		       gc_ver == IP_VERSION(11, 0, 3)) && adev->vcn.num_vcn_inst >= 2))
+		       gc_ver == IP_VERSION(11, 0, 3) ||
+		       gc_ver == IP_VERSION(11, 5, 1)) && adev->vcn.num_vcn_inst >= 2))
 			*states = ATTR_STATE_UNSUPPORTED;
 	} else if (DEVICE_ATTR_IS(pp_dpm_pcie)) {
 		if (amdgpu_is_multi_aid(adev))
Signature · 1 line
2.43.0
#4 lore raw

PATCH v4 2/4 drm/amd/pm: add IP_VERSION(11, 5, 1) to vclk/dclk DPM sysfs whitelists

In reply to Priya Hosur

Add IP_VERSION(11,5,1) to pp_dpm_vclk and pp_dpm_dclk visibility whitelists so these sysfs entries are exposed on Strix Halo (GC 11.5.1). Add IP_VERSION(11,5,1) to pp_dpm_vclk1 and pp_dpm_dclk1 whitelists with the existing num_vcn_inst >= 2 guard since Strix Halo has two VCN instances.

Without this, amd-smi reports N/A for VCLK0, VCLK1, DCLK0 and DCLK1 clocks.

---
 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -2
index dfebe67c164d..305852f5b153 100644
@@ -2027,6 +2027,7 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		      gc_ver == IP_VERSION(11, 0, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 4) ||
 		      gc_ver == IP_VERSION(11, 5, 0) ||
+		      gc_ver == IP_VERSION(11, 5, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 2) ||
 		      gc_ver == IP_VERSION(11, 0, 3) ||
 		      amdgpu_is_multi_aid(adev)))
@@ -2035,7 +2036,8 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		if (!((gc_ver == IP_VERSION(10, 3, 1) ||
 		       gc_ver == IP_VERSION(10, 3, 0) ||
 		       gc_ver == IP_VERSION(11, 0, 2) ||
-		       gc_ver == IP_VERSION(11, 0, 3)) && adev->vcn.num_vcn_inst >= 2))
+		       gc_ver == IP_VERSION(11, 0, 3) ||
+		       gc_ver == IP_VERSION(11, 5, 1)) && adev->vcn.num_vcn_inst >= 2))
 			*states = ATTR_STATE_UNSUPPORTED;
 	} else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
 		if (!(gc_ver == IP_VERSION(10, 3, 1) ||
@@ -2048,6 +2050,7 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		      gc_ver == IP_VERSION(11, 0, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 4) ||
 		      gc_ver == IP_VERSION(11, 5, 0) ||
+		      gc_ver == IP_VERSION(11, 5, 1) ||
 		      gc_ver == IP_VERSION(11, 0, 2) ||
 		      gc_ver == IP_VERSION(11, 0, 3) ||
 		      amdgpu_is_multi_aid(adev)))
@@ -2056,7 +2059,8 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
 		if (!((gc_ver == IP_VERSION(10, 3, 1) ||
 		       gc_ver == IP_VERSION(10, 3, 0) ||
 		       gc_ver == IP_VERSION(11, 0, 2) ||
-		       gc_ver == IP_VERSION(11, 0, 3)) && adev->vcn.num_vcn_inst >= 2))
+		       gc_ver == IP_VERSION(11, 0, 3) ||
+		       gc_ver == IP_VERSION(11, 5, 1)) && adev->vcn.num_vcn_inst >= 2))
 			*states = ATTR_STATE_UNSUPPORTED;
 	} else if (DEVICE_ATTR_IS(pp_dpm_pcie)) {
 		if (amdgpu_is_multi_aid(adev))
Signature · 1 line
2.43.0
#5 lore raw

PATCH v4 3/4 drm/amd/pm: smu_v14_0_0: add SMU_DCEFCLK support in DPM frequency queries

In reply to Priya Hosur

Add SMU_DCEFCLK case to smu_v14_0_1_get_dpm_freq_by_index and smu_v14_0_0_get_dpm_freq_by_index using DcfClocks[] with NumDcfClkLevelsEnabled bounds check. Add matching case in both get_dpm_level_count functions.

Add SMU_DCEFCLK case in emit_clk_levels to list DCEF DPM levels. No * marker is emitted since SmuMetrics_t has no DcfclkFrequency field (same firmware limitation as Phoenix).

Without this, pp_dpm_dcefclk reports N/A on Strix Halo.

---
 .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +28 -0
index c4c45c8dff69..206bfa906ad6 100644
@@ -710,6 +710,11 @@ static int smu_v14_0_1_get_dpm_freq_by_index(struct smu_context *smu,
 			return -EINVAL;
 		*freq = clk_table->FclkClocks_Freq[dpm_level];
 		break;
+	case SMU_DCEFCLK:
+		if (dpm_level >= clk_table->NumDcfClkLevelsEnabled)
+			return -EINVAL;
+		*freq = clk_table->DcfClocks[dpm_level];
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -754,6 +759,11 @@ static int smu_v14_0_0_get_dpm_freq_by_index(struct smu_context *smu,
 			return -EINVAL;
 		*freq = clk_table->FclkClocks_Freq[dpm_level];
 		break;
+	case SMU_DCEFCLK:
+		if (dpm_level >= clk_table->NumDcfClkLevelsEnabled)
+			return -EINVAL;
+		*freq = clk_table->DcfClocks[dpm_level];
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -1117,6 +1127,9 @@ static int smu_v14_0_1_get_dpm_level_count(struct smu_context *smu,
 	case SMU_FCLK:
 		*count = clk_table->NumFclkLevelsEnabled;
 		break;
+	case SMU_DCEFCLK:
+		*count = clk_table->NumDcfClkLevelsEnabled;
+		break;
 	default:
 		break;
 	}
@@ -1146,6 +1159,9 @@ static int smu_v14_0_0_get_dpm_level_count(struct smu_context *smu,
 	case SMU_FCLK:
 		*count = clk_table->NumFclkLevelsEnabled;
 		break;
+	case SMU_DCEFCLK:
+		*count = clk_table->NumDcfClkLevelsEnabled;
+		break;
 	default:
 		break;
 	}
@@ -1212,6 +1228,18 @@ static int smu_v14_0_0_emit_clk_levels(struct smu_context *smu,
 					      cur_value == value ? "*" : "");
 		}
 		break;
+	case SMU_DCEFCLK:
+		ret = smu_v14_0_common_get_dpm_level_count(smu, clk_type, &count);
+		if (ret)
+			return ret;
+
+		for (i = 0; i < count; i++) {
+			ret = smu_v14_0_common_get_dpm_freq_by_index(smu, clk_type, i, &value);
+			if (ret)
+				return ret;
+			size += sysfs_emit_at(buf, size, "%d: %uMhz\n", i, value);
+		}
+		break;
 	case SMU_GFXCLK:
 	case SMU_SCLK:
 		ret = smu_v14_0_0_get_current_clk_freq(smu, clk_type, &cur_value);
Signature · 1 line
2.43.0
#6 lore raw

PATCH v4 4/4 drm/amd/pm: smu_v14_0_0: add closest-match fallback for DPM level marking

In reply to Priya Hosur

Replace the simple exact-match loop in emit_clk_levels with a two-pass approach: the first pass checks whether the current frequency matches any DPM level exactly and also tracks the closest level by absolute frequency difference. The second pass emits the levels, marking the exact match if found, otherwise the closest level.

The SMU reports time-filtered average frequencies that often do not match any DPM table entry exactly. Without this fallback, MCLK, FCLK and other clocks show DPM levels but never display the * marker, breaking userspace tools that rely on it to identify the active frequency.

Also uses reverse DPM index for SMU_MCLK since MemPstateTable stores levels high-to-low.

---
 .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 46 ++++++++++++++++---
 1 file changed, 39 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +39 -7
index 206bfa906ad6..45b0baeb194c 100644
@@ -1218,14 +1218,46 @@ static int smu_v14_0_0_emit_clk_levels(struct smu_context *smu,
 		if (ret)
 			return ret;
 
-		for (i = 0; i < count; i++) {
-			idx = (clk_type == SMU_MCLK) ? (count - i - 1) : i;
-			ret = smu_v14_0_common_get_dpm_freq_by_index(smu, clk_type, idx, &value);
-			if (ret)
-				return ret;
+		/*
+		 * Try exact match first. If the SMU reports a time-averaged
+		 * frequency that doesn't match any DPM level exactly, fall
+		 * back to marking the closest DPM level.
+		 */
+		{
+			int closest_idx = 0;
+			uint32_t closest_diff = U32_MAX;
+			uint32_t diff;
+
+			for (i = 0; i < count; i++) {
+				idx = (clk_type == SMU_MCLK) ? (count - i - 1) : i;
+				ret = smu_v14_0_common_get_dpm_freq_by_index(smu, clk_type, idx, &value);
+				if (ret)
+					return ret;
+
+				if (cur_value == value) {
+					closest_idx = i;
+					break;
+				}
 
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value,
-					      cur_value == value ? "*" : "");
+				diff = abs((int)cur_value - (int)value);
+				if (diff < closest_diff) {
+					closest_diff = diff;
+					closest_idx = i;
+				} else if (diff > closest_diff) {
+					break;
+				}
+			}
+
+			for (i = 0; i < count; i++) {
+				idx = (clk_type == SMU_MCLK) ? (count - i - 1) : i;
+				ret = smu_v14_0_common_get_dpm_freq_by_index(smu, clk_type, idx, &value);
+				if (ret)
+					return ret;
+
+				size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+						      i, value,
+						      i == closest_idx ? "*" : "");
+			}
 		}
 		break;
 	case SMU_DCEFCLK:
Signature · 1 line
2.43.0