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 8 messages Jun 11

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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.

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: add DCLK metric handler via VCLK fall-through 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  | 79 +++++++++++++++++--
 2 files changed, 77 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/4 drm/amd/pm: smu_v14_0_0: add DCLK metric handler via VCLK fall-through

Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency. DCLK and VCLK have separate DPM clock tables but SmuMetrics_t has no DclkFrequency field, so report VclkFrequency for both.

---
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +6 -3
index 2fe006de927a..eeb508336349 100644
@@ -281,10 +281,13 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
 		*value = metrics->SocclkFrequency;
 		break;
 	case METRICS_AVERAGE_VCLK:
-		*value = metrics->VclkFrequency;
-		break;
 	case METRICS_AVERAGE_DCLK:
-		*value = 0;
+		/*
+		 * DCLK and VCLK have separate DPM clock tables but
+		 * SmuMetrics_t has no DclkFrequency field; report
+		 * VclkFrequency for both.
+		 */
+		*value = metrics->VclkFrequency;
 		break;
 	case METRICS_AVERAGE_UCLK:
 		*value = metrics->MemclkFrequency;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v3 1/4] drm/amd/pm: smu_v14_0_0: add DCLK metric handler via VCLK fall-through

Quoted 4 lines · Priya Hosur

Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency. DCLK and VCLK have separate DPM clock tables but SmuMetrics_t has no DclkFrequency field, so report VclkFrequency for both.

Just to confirm - if you are seeing different DPM tables for DCLK/VCLK, this shouldn't be done. If they simply follow the DPM levels, then you could match the level for VCLK and report the frequency at the same level for DCLK. Otherwise, ask for a proper update from FW team.

Thanks,
Lijo

Quoted 27 lines
---
  drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +6 -3
index 2fe006de927a..eeb508336349 100644
@@ -281,10 +281,13 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
  		*value = metrics->SocclkFrequency;
  		break;
  	case METRICS_AVERAGE_VCLK:
-		*value = metrics->VclkFrequency;
-		break;
  	case METRICS_AVERAGE_DCLK:
-		*value = 0;
+		/*
+		 * DCLK and VCLK have separate DPM clock tables but
+		 * SmuMetrics_t has no DclkFrequency field; report
+		 * VclkFrequency for both.
+		 */
+		*value = metrics->VclkFrequency;
  		break;
  	case METRICS_AVERAGE_UCLK:
  		*value = metrics->MemclkFrequency;
#3 lore raw

Re: [PATCH v3 1/4] drm/amd/pm: smu_v14_0_0: add DCLK metric handler via VCLK fall-through

In reply to Priya Hosur

Hi Lijo,

Thanks for the suggestion. I confirmed that the DPM tables are indeed different on this hardware (GC 11.5.1, SMU 14.0.1):

pp_dpm_vclk: 800, 1472, 1605, 1766, 1962, 2208, 2523, 2944 MHz
pp_dpm_dclk: 800, 981, 1104, 1177, 1358, 1472, 1766, 2208 MHz

The original code was returning 0 for METRICS_AVERAGE_DCLK, so the fall-through to VclkFrequency was an improvement but not fully correct given the different DPM tables.

Since VcnClkLevelsEnabled applies to both VCLK and DCLK with the same level count, I'll update patch 1 to match VclkFrequency to its DPM level index and then report the DCLK frequency at that same level for METRICS_AVERAGE_DCLK.

Will also check with the FW team about adding a DclkFrequency field to SmuMetrics_t.

Will send v4 with the fix.

Regards,
Priya

#4 lore raw

PATCH v3 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 v3 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 eeb508336349..4469048d966e 100644
@@ -686,6 +686,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;
 	}
@@ -730,6 +735,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;
 	}
@@ -1093,6 +1103,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;
 	}
@@ -1122,6 +1135,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;
 	}
@@ -1188,6 +1204,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 v3 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 4469048d966e..1c11e74072d3 100644
@@ -1194,14 +1194,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;
+				}
+
+				diff = abs((int)cur_value - (int)value);
+				if (diff < closest_diff) {
+					closest_diff = diff;
+					closest_idx = i;
+				} else if (diff > closest_diff) {
+					break;
+				}
+			}
 
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value,
-					      cur_value == value ? "*" : "");
+			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
Reviewed-by on v3 4/4
#7 lore raw

Re: [PATCH v3 4/4] drm/amd/pm: smu_v14_0_0: add closest-match fallback for DPM level marking

Quoted 13 lines · 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.

Quoted 4 lines

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

Thanks,
Lijo

Quoted 62 lines
---
  .../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 4469048d966e..1c11e74072d3 100644
@@ -1194,14 +1194,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;
+				}
+
+				diff = abs((int)cur_value - (int)value);
+				if (diff < closest_diff) {
+					closest_diff = diff;
+					closest_idx = i;
+				} else if (diff > closest_diff) {
+					break;
+				}
+			}
 
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value,
-					      cur_value == value ? "*" : "");
+			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: