All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lazar, Lijo" <lijo.lazar@amd.com>
To: Priya Hosur <Priya.Hosur@amd.com>,
	amd-gfx@lists.freedesktop.org, Alexander.Deucher@amd.com,
	Christian.Koenig@amd.com, Mario.Limonciello@amd.com,
	Kenneth.Feng@amd.com
Cc: Pratik.Vishwakarma@amd.com, Veerabadhran.Gopalakrishnan@amd.com
Subject: Re: [PATCH v2 4/4] drm/amd/pm: smu_v14_0_0: add closest-match fallback for DPM level marking
Date: Thu, 11 Jun 2026 09:47:16 +0530	[thread overview]
Message-ID: <6c63f0ef-7cc5-41cb-8b5a-e4fcb21684b7@amd.com> (raw)
In-Reply-To: <20260610182333.3922-5-Priya.Hosur@amd.com>



On 10-Jun-26 11:53 PM, Priya Hosur wrote:
> 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.
> 
> Signed-off-by: Priya Hosur <Priya.Hosur@amd.com>
> ---
>   .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 53 ++++++++++++++++---
>   1 file changed, 46 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
> index 1be8d1a8da19..c01c71acbe3f 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
> @@ -1190,14 +1190,53 @@ 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;
> +			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) {
> +					closest_idx = i;
> +					exact_match = true;
> +					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;
> +
> +				if (exact_match)

exact_match is redundant now. It only needs closest_idx check.

Thanks,
Lijo

> +					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:


      reply	other threads:[~2026-06-11  4:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 18:23 [PATCH v2 0/4] drm/amd/pm: smu_v14_0_0: fix pp_dpm_* clock reporting on SMU v14.0.0/v14.0.1 APUs Priya Hosur
2026-06-10 18:23 ` [PATCH v2 1/4] drm/amd/pm: smu_v14_0_0: add DCLK metric handler via VCLK fall-through Priya Hosur
2026-06-11  4:11   ` Lazar, Lijo
2026-06-10 18:23 ` [PATCH v2 2/4] drm/amd/pm: add IP_VERSION(11, 5, 1) to vclk/dclk DPM sysfs whitelists Priya Hosur
2026-06-10 18:23 ` [PATCH v2 3/4] drm/amd/pm: smu_v14_0_0: add SMU_DCEFCLK support in DPM frequency queries Priya Hosur
2026-06-10 18:23 ` [PATCH v2 4/4] drm/amd/pm: smu_v14_0_0: add closest-match fallback for DPM level marking Priya Hosur
2026-06-11  4:17   ` Lazar, Lijo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c63f0ef-7cc5-41cb-8b5a-e4fcb21684b7@amd.com \
    --to=lijo.lazar@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Kenneth.Feng@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Pratik.Vishwakarma@amd.com \
    --cc=Priya.Hosur@amd.com \
    --cc=Veerabadhran.Gopalakrishnan@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.