mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>, gautham.shenoy@amd.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Viresh Kumar <viresh.kumar@linaro.org>,
	rafael@kernel.org, perry.yuan@amd.com
Subject: Re: [PATCH] cpufreq/amd-pstate: Fix the clamping of perf values
Date: Mon, 24 Feb 2025 18:09:38 -0600	[thread overview]
Message-ID: <6feda9d4-aa51-4903-8d6e-9444ad423fd2@amd.com> (raw)
In-Reply-To: <20250222033221.554976-1-dhananjay.ugwekar@amd.com>

On 2/21/2025 21:32, Dhananjay Ugwekar wrote:
> The clamping in freq_to_perf() is broken right now, as we first typecast
> (read wraparound) the overflowing value into a u8 and then clamp it down.
> So, use a u32 to store the >255 value in certain edge cases and then clamp
> it down into a u8.
> 
> Also, use a "explicit typecast + clamp" instead of just a "clamp_t" as the
> latter typecasts first and then clamps between the limits, which defeats
> our purpose.
> 
> Fixes: 305621eb6a8b ("cpufreq/amd-pstate: Modularize perf<->freq conversion")
> Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>

Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>

I'll rebase my series on this for v5.

> ---
>   drivers/cpufreq/amd-pstate.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 9ab95ec1f828..4705a644db6d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -144,10 +144,10 @@ static struct quirk_entry quirk_amd_7k62 = {
>   
>   static inline u8 freq_to_perf(struct amd_cpudata *cpudata, unsigned int freq_val)
>   {
> -	u8 perf_val = DIV_ROUND_UP_ULL((u64)freq_val * cpudata->nominal_perf,
> +	u32 perf_val = DIV_ROUND_UP_ULL((u64)freq_val * cpudata->nominal_perf,
>   					cpudata->nominal_freq);
>   
> -	return clamp_t(u8, perf_val, cpudata->lowest_perf, cpudata->highest_perf);
> +	return (u8)clamp(perf_val, cpudata->lowest_perf, cpudata->highest_perf);
>   }
>   
>   static inline u32 perf_to_freq(struct amd_cpudata *cpudata, u8 perf_val)


      reply	other threads:[~2025-02-25  2:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-22  3:32 Dhananjay Ugwekar
2025-02-25  0:09 ` Mario Limonciello [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=6feda9d4-aa51-4903-8d6e-9444ad423fd2@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=dhananjay.ugwekar@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=perry.yuan@amd.com \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®