All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: zuoqian <zuoqian113@gmail.com>,
	Ionela Voinescu <ionela.voinescu@arm.com>,
	rafael@kernel.org, Sudeep Holla <sudeep.holla@arm.com>,
	viresh.kumar@linaro.org, cristian.marussi@arm.com,
	arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: scpi: compare against frequency instead of rate
Date: Thu, 23 Jan 2025 12:16:50 +0000	[thread overview]
Message-ID: <Z5IzMhTOhtujyH0n@bogus> (raw)
In-Reply-To: <ad11dfc1-5e88-4421-b427-3955d4220133@stanley.mountain>

(for some reason I don't have the original email)

On Thu, Jan 23, 2025 at 02:12:14PM +0300, Dan Carpenter wrote:
> On Thu, Jan 23, 2025 at 07:53:20AM +0000, zuoqian wrote:
> > The CPU rate from clk_get_rate() may not be divisible by 1000
> > (e.g., 133333333). But the rate calculated from frequency is always
> > divisible by 1000 (e.g., 133333000).
> > Comparing the rate causes a warning during CPU scaling:
> > "cpufreq: __target_index: Failed to change cpu frequency: -5".
> > When we choose to compare frequency here, the issue does not occur.
> > 
> > Signed-off-by: zuoqian <zuoqian113@gmail.com>
> > ---
> >  drivers/cpufreq/scpi-cpufreq.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
> > index cd89c1b9832c..3bff4bb5ab4a 100644
> > --- a/drivers/cpufreq/scpi-cpufreq.c
> > +++ b/drivers/cpufreq/scpi-cpufreq.c
> > @@ -39,8 +39,9 @@ static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
> >  static int
> >  scpi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index)
> >  {
> > -	u64 rate = policy->freq_table[index].frequency * 1000;
> 
> policy->freq_table[index].frequency is a u32 so in this original
> calculation, even though "rate" is declared as a u64, it can't actually
> be more than UINT_MAX.
>

Agreed and understood.

> > +	unsigned long freq = policy->freq_table[index].frequency;
> >  	struct scpi_data *priv = policy->driver_data;
> > +	u64 rate = freq * 1000;
>
> So you've fixed this by casting policy->freq_table[index].frequency
> to unsigned long, which fixes the problem on 64bit systems but it still
> remains on 32bit systems.  It would be better to declare freq as a u64.
>

Just trying to understand if that matters. freq is in kHz as copied
from policy->freq_table[index].frequency and we compare it with
kHZ below as the obtained clock rate is divided by 1000. What am I
missing ? If it helps, it can be renamed as freq_in_khz and even keep
it as "unsigned int" as in struct cpufreq_frequency_table.

-- 
Regards,
Sudeep

  reply	other threads:[~2025-01-23 12:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-23  7:53 [PATCH] cpufreq: scpi: compare against frequency instead of rate zuoqian
2025-01-23 11:12 ` Dan Carpenter
2025-01-23 12:16   ` Sudeep Holla [this message]
2025-01-23 13:04     ` Dan Carpenter
2025-01-24  9:42       ` zuoqian
2025-01-24 10:51         ` Dan Carpenter
2025-01-25  8:49 ` [PATCH v2] cpufreq: scpi: compare kHz instead of Hz zuoqian
2025-01-25 13:04   ` Dan Carpenter
2025-02-03 10:51     ` Viresh Kumar
2025-03-06 11:01   ` Dan Carpenter

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=Z5IzMhTOhtujyH0n@bogus \
    --to=sudeep.holla@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=dan.carpenter@linaro.org \
    --cc=ionela.voinescu@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=zuoqian113@gmail.com \
    /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.