public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: David Laight <david.laight.linux@gmail.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Thomas Renninger <trenn@suse.de>, Borislav Petkov <bp@suse.de>,
	Jacob Shin <jacob.shin@amd.com>,
	stable@vger.kernel.org,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: amd_freq_sensitivity: Fix sensitivity clamping in amd_powersave_bias_target
Date: Fri, 19 Dec 2025 16:55:02 +0100	[thread overview]
Message-ID: <3F396FA4-8DB6-451E-BF58-02646808FC3B@linux.dev> (raw)
In-Reply-To: <20251202190904.27c9bc06@pumpkin>

On 2. Dec 2025, at 20:09, David Laight wrote:
> On Tue,  2 Dec 2025 13:44:28 +0100
> Thorsten Blum <thorsten.blum@linux.dev> wrote:
> 
>> The local variable 'sensitivity' was never clamped to 0 or
>> POWERSAVE_BIAS_MAX because the return value of clamp() was not used. Fix
>> this by assigning the clamped value back to 'sensitivity'.
> 
> This actually makes no difference
> (assuming od_tuners->powersave_bias <= POWERSAVE_BIAS_MAX).
> The only use of 'sensitivity' is the test at the end of the diff.
> 
> So I think you could just delete the line.

The local variable 'sensitivity' is an 'int', while '->powersave_bias'
is an 'unsigned int'. If 'sensitivity' were ever negative, it would be
converted to an 'unsigned int', producing an incorrect result. That's
probably what the clamping was meant to prevent.

However, calculating 'sensitivity' can be simplified from:

	sensitivity = POWERSAVE_BIAS_MAX -
		(POWERSAVE_BIAS_MAX * (d_reference - d_actual) / d_reference);

to:

	sensitivity = POWERSAVE_BIAS_MAX * d_actual / d_reference;

which makes it clearer that, in practice, 'sensitivity' is never
negative. How about simplifying the formula as above, changing
'sensitivity' to 'unsigned int', and removing the clamping?

Thanks,
Thorsten


  reply	other threads:[~2025-12-19 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 12:44 [PATCH] cpufreq: amd_freq_sensitivity: Fix sensitivity clamping in amd_powersave_bias_target Thorsten Blum
2025-12-02 19:09 ` David Laight
2025-12-19 15:55   ` Thorsten Blum [this message]
2025-12-23 13:23     ` Thorsten Blum

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=3F396FA4-8DB6-451E-BF58-02646808FC3B@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=bp@suse.de \
    --cc=david.laight.linux@gmail.com \
    --cc=jacob.shin@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=trenn@suse.de \
    --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