Skip to contentSkip to conversation

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

PATCH Superseded Priya Hosur 3 participants 11 messages Jun 10

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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

This series fixes multiple pp_dpm_* sysfs clocks reporting N/A or missing the * current-level marker on SMU v14.0.0/v14.0.1 APUs (GC 11.5.1).

Background
----------
On GC 11.5.1 APUs, amd-smi reports N/A for VCLK, DCLK, VCLK1, DCLK1 and DCEFCLK clocks. Additionally, MCLK and FCLK show DPM levels but lack the
* marker indicating the current level.

The N/A clocks are caused by missing IP_VERSION(11,5,1) entries in the sysfs visibility whitelists and absent metric handlers. The missing * marker is caused by the SMU reporting time-filtered average frequencies that do not match any DPM level exactly.

Fix
---
1. Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency (SmuMetrics_t has no DclkFrequency field; DCLK tracks VCLK on VCN). Add VCLK1/DCLK1 metric handlers returning 0.

2. Add IP_VERSION(11,5,1) to pp_dpm_vclk, pp_dpm_dclk, pp_dpm_vclk1 and pp_dpm_dclk1 whitelists. The target APU has two VCN instances.

3. Add SMU_DCEFCLK to get_dpm_freq_by_index and get_dpm_level_count using DcfClocks[]/NumDcfClkLevelsEnabled. Add DCEFCLK case in emit_clk_levels.

4. Add closest-match fallback in emit_clk_levels: first pass tries exact match; if no match (averaged frequency), mark the DPM level with the smallest absolute frequency difference. Reverse DPM index for SMU_MCLK since MemPstateTable stores levels high-to-low.

Validation
----------
Tested on GC 11.5.1, SMU 14.0.1 APU. All pp_dpm_* clocks now report correct DPM levels with * markers via both sysfs and amd-smi.

Priya Hosur (4):
drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers 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  | 76 +++++++++++++++++--
 2 files changed, 76 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/4 drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers

Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency, since SmuMetrics_t has no DclkFrequency field and DCLK tracks VCLK on VCN. Add VCLK1/DCLK1 metric handlers returning 0 as the struct has no fields for these, avoiding UINT_MAX default that causes N/A in amd-smi.

---
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +5 -1
index 2fe006de927a..c977681d8946 100644
@@ -281,9 +281,13 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
 		*value = metrics->SocclkFrequency;
 		break;
 	case METRICS_AVERAGE_VCLK:
+	case METRICS_AVERAGE_DCLK:
+		/* No DclkFrequency in SmuMetrics_t; DCLK tracks VCLK on VCN */
 		*value = metrics->VclkFrequency;
 		break;
-	case METRICS_AVERAGE_DCLK:
+	case METRICS_AVERAGE_VCLK1:
+	case METRICS_AVERAGE_DCLK1:
+		/* No Vclk1/Dclk1 in v14.0.0 SmuMetrics_t; avoid UINT_MAX default */
 		*value = 0;
 		break;
 	case METRICS_AVERAGE_UCLK:
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/4] drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers

Quoted 17 lines · Priya Hosur

Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency, since SmuMetrics_t has no DclkFrequency field and DCLK tracks VCLK on VCN. Add VCLK1/DCLK1 metric handlers returning 0 as the struct has no fields for these, avoiding UINT_MAX default that causes N/A in amd-smi.

---
  drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +0 -0
index 2fe006de927a..c977681d8946 100644
@@ -281,9 +281,13 @@ static int smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
  		*value = metrics->SocclkFrequency;

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 290

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +5 -1
  		break;
  	case METRICS_AVERAGE_VCLK:
+	case METRICS_AVERAGE_DCLK:
+		/* No DclkFrequency in SmuMetrics_t; DCLK tracks VCLK on VCN */
  		*value = metrics->VclkFrequency;
  		break;
-	case METRICS_AVERAGE_DCLK:
+	case METRICS_AVERAGE_VCLK1:
+	case METRICS_AVERAGE_DCLK1:
+		/* No Vclk1/Dclk1 in v14.0.0 SmuMetrics_t; avoid UINT_MAX default */

These are clocks for the second VCN instance. If adding them to FW metrics is not an option, then reporting the value as UINT_MAX is better as that indicates N/A (not applicable/available).

Thanks,
Lijo> *value = 0;

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +0 -0
  		break;
  	case METRICS_AVERAGE_UCLK:
#3 lore raw

Re: [PATCH 1/4] drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers

Quoted 26 lines · Lijo
Quoted 23 lines · Priya Hosur

Merge METRICS_AVERAGE_VCLK and METRICS_AVERAGE_DCLK into a single fall-through case mapping both to VclkFrequency, since SmuMetrics_t has no DclkFrequency field and DCLK tracks VCLK on VCN. Add VCLK1/DCLK1 metric handlers returning 0 as the struct has no fields for these, avoiding UINT_MAX default that causes N/A in amd-smi.

---
  drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +0 -0
index 2fe006de927a..c977681d8946 100644
@@ -281,9 +281,13 @@ static int 
 smu_v14_0_0_get_smu_metrics_data(struct smu_context *smu,
           *value = metrics->SocclkFrequency;
           break;

      case METRICS_AVERAGE_VCLK:
+    case METRICS_AVERAGE_DCLK:
+        /* No DclkFrequency in SmuMetrics_t; DCLK tracks VCLK on VCN */ *value = metrics->VclkFrequency;

Quoted 9 lines
Quoted 6 lines

          break;
-    case METRICS_AVERAGE_DCLK:
+    case METRICS_AVERAGE_VCLK1:
+    case METRICS_AVERAGE_DCLK1:
+        /* No Vclk1/Dclk1 in v14.0.0 SmuMetrics_t; avoid UINT_MAX default */

These are clocks for the second VCN instance. If adding them to FW metrics is not an option, then reporting the value as UINT_MAX is better as that indicates N/A (not applicable/available).

Do the two instances share a common clock?

Quoted 5 lines

Thanks,
Lijo>           *value = 0;

Quoted 2 lines

          break;
      case METRICS_AVERAGE_UCLK:

#4 lore raw

Re: [PATCH 1/4] drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers

In reply to Priya Hosur
Quoted 3 lines · Lijo

These are clocks for the second VCN instance. If adding them to FW metrics is not an option, then reporting the value as UINT_MAX is better as that indicates N/A (not applicable/available).

Agreed, I'll drop the VCLK1/DCLK1 handlers and let them fall through to the default (UINT_MAX / N/A) in v2.

Quoted 1 line

Do the two instances share a common clock?

On v14.0.0, there is a single VCN instance where VCLK and DCLK share the same clock domain -- the DPM table comment in smu14_driver_if says "Applies to both Vclk and Dclk". So mapping METRICS_AVERAGE_DCLK to VclkFrequency is correct here.

On v14.0.1, there are two VCN instances (Vcn0/Vcn1) with separate clock domains, but SmuMetrics_t only exposes VclkFrequency for instance 0. There are no fields for DCLK, VCLK1, or DCLK1 in the firmware metrics struct.

Thanks,
Priya Hosur

#5 lore raw

Re: [PATCH 1/4] drm/amd/pm: smu_v14_0_0: add DCLK and VCLK1/DCLK1 metric handlers

Quoted 15 lines · Priya Hosur
Quoted 3 lines · Lijo

These are clocks for the second VCN instance. If adding them to FW metrics is not an option, then reporting the value as UINT_MAX is better as that indicates N/A (not applicable/available).

Agreed, I'll drop the VCLK1/DCLK1 handlers and let them fall through to the default (UINT_MAX / N/A) in v2.

Quoted 1 line

Do the two instances share a common clock?

On v14.0.0, there is a single VCN instance where VCLK and DCLK share the same clock domain -- the DPM table comment in smu14_driver_if says "Applies to both Vclk and Dclk". So mapping METRICS_AVERAGE_DCLK to VclkFrequency is correct here.

Quoted 5 lines

On v14.0.1, there are two VCN instances (Vcn0/Vcn1) with separate clock domains, but SmuMetrics_t only exposes VclkFrequency for instance 0. There are no fields for DCLK, VCLK1, or DCLK1 in the firmware metrics struct.

Then I agree with Lijo's suggestion that it should continue to be N/A for second instance.

#6 lore raw

PATCH 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
#7 lore raw

PATCH 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 c977681d8946..c203e828cce4 100644
@@ -687,6 +687,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;
 	}
@@ -731,6 +736,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;
 	}
@@ -1094,6 +1104,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;
 	}
@@ -1123,6 +1136,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;
 	}
@@ -1189,6 +1205,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
#8 lore raw

PATCH 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 c203e828cce4..b113cf2b26fa 100644
@@ -1195,14 +1195,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;
+			bool exact_match = false;
+
+			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)
+					exact_match = true;
+
+				if (abs((int)cur_value - (int)value) < closest_diff) {
+					closest_diff = abs((int)cur_value - (int)value);
+					closest_idx = i;
+				}
+			}
 
-			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;
+
+				if (exact_match)
+					size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+							      i, value,
+							      cur_value == value ? "*" : "");
+				else
+					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
#9 lore raw

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

Quoted 42 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.

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 +8 -5
index c203e828cce4..b113cf2b26fa 100644
@@ -1195,14 +1195,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;

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +10 -0
+			bool exact_match = false;
+
+			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)
+					exact_match = true;

What about closest_idx = i; and break here? You may also break the loop if new_diff > closest_diff

Thanks,
Lijo

Quoted 27 lines
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c +21 -2
+
+				if (abs((int)cur_value - (int)value) < closest_diff) {
+					closest_diff = abs((int)cur_value - (int)value);
+					closest_idx = i;
+				}
+			}
 
-			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;
+
+				if (exact_match)
+					size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+							      i, value,
+							      cur_value == value ? "*" : "");
+				else
+					size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+							      i, value,
+							      i == closest_idx ? "*" : "");
+			}
  		}
  		break;
  	case SMU_DCEFCLK:
#10 lore raw

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

In reply to Priya Hosur
Quoted 2 lines · Lijo

What about closest_idx = i; and break here? You may also break the loop if new_diff > closest_diff

On exact match I'll set closest_idx = i, break, and skip the fallback path entirely. For the closest-match search, I'll add an early exit when the diff starts increasing (since DPM levels are monotonically ordered). Will address in v2.

Thanks,
Priya hosur