mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
To: Xuewen Yan <xuewen.yan@unisoc.com>
Cc: rui.zhang@intel.com, rafael@kernel.org, linux-pm@vger.kernel.org,
	viresh.kumar@linaro.org, amit.kachhap@gmail.com,
	daniel.lezcano@kernel.org, linux-kernel@vger.kernel.org,
	ke.wang@unisoc.com, di.shen@unisoc.com, jeson.gao@unisoc.com,
	xuewen.yan94@gmail.com
Subject: Re: [RFC PATCH 1/2] thermal/cpufreq_cooling: remove unused cpu_idx in get_load()
Date: Fri, 20 Mar 2026 12:32:23 +0000	[thread overview]
Message-ID: <031562ee-b88f-49b9-8b1e-dbbbe1a508c6@arm.com> (raw)
In-Reply-To: <20260320113148.7308-1-xuewen.yan@unisoc.com>

Hi Xuewen,

On 3/20/26 11:31, Xuewen Yan wrote:
> From: Di Shen <di.shen@unisoc.com>
> 
> The cpu_idx variable in the get_load function is now
> unused and can be safely removed.
> 
> No code logic is affected.
> 
> Signed-off-by: Di Shen <di.shen@unisoc.com>
> ---
>   drivers/thermal/cpufreq_cooling.c | 13 +++++--------
>   1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c
> index 32bf5ab44f4a..d030dbeb2973 100644
> --- a/drivers/thermal/cpufreq_cooling.c
> +++ b/drivers/thermal/cpufreq_cooling.c
> @@ -151,26 +151,23 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev,
>    * get_load() - get load for a cpu
>    * @cpufreq_cdev: struct cpufreq_cooling_device for the cpu
>    * @cpu: cpu number
> - * @cpu_idx: index of the cpu in time_in_idle array
>    *
>    * Return: The average load of cpu @cpu in percentage since this
>    * function was last called.
>    */
>   #ifdef CONFIG_SMP
> -static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
> -		    int cpu_idx)
> +static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu)
>   {
>   	unsigned long util = sched_cpu_util(cpu);
>   
>   	return (util * 100) / arch_scale_cpu_capacity(cpu);
>   }
>   #else /* !CONFIG_SMP */
> -static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
> -		    int cpu_idx)
> +static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu)
>   {
>   	u32 load;
>   	u64 now, now_idle, delta_time, delta_idle;
> -	struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx];
> +	struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu];

This is a bug. We allocate 'num_cpus' size of array based on
number of CPU in the cpumask for a given cpufreq policy.
If there are 4 cpus in the CPU cluster but CPUs have ids:
CPU4-7 then accessing it with this change would explode.

Please re-design this patch set slightly and I will have a look
on the 2nd version (and particularly the part in current patch 2/2).

Regards,
Lukasz

  parent reply	other threads:[~2026-03-20 12:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 11:31 Xuewen Yan
2026-03-20 11:31 ` [RFC PATCH 2/2] thermal/cpufreq_cooling: Use idle_time to get cpu_load when scx_enabled Xuewen Yan
2026-03-24  1:41   ` Qais Yousef
2026-03-20 12:32 ` Lukasz Luba [this message]
2026-03-21  8:48   ` [RFC PATCH 1/2] thermal/cpufreq_cooling: remove unused cpu_idx in get_load() Xuewen Yan
2026-03-23  5:34   ` Viresh Kumar
2026-03-23  9:20     ` Lukasz Luba
2026-03-23 10:41       ` Viresh Kumar
2026-03-23 10:52         ` Lukasz Luba
2026-03-23 11:06           ` Viresh Kumar
2026-03-23 13:25             ` Lukasz Luba
2026-03-24  2:20               ` Xuewen Yan
2026-03-24 10:46                 ` Lukasz Luba
2026-03-24 12:03                   ` Xuewen Yan
2026-03-25  8:31                     ` Lukasz Luba
2026-03-26  9:05                   ` Qais Yousef
2026-03-26  9:21                     ` Lukasz Luba
2026-03-28  8:09                       ` Qais Yousef
2026-03-30  8:56                         ` Lukasz Luba

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=031562ee-b88f-49b9-8b1e-dbbbe1a508c6@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=amit.kachhap@gmail.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=di.shen@unisoc.com \
    --cc=jeson.gao@unisoc.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=viresh.kumar@linaro.org \
    --cc=xuewen.yan94@gmail.com \
    --cc=xuewen.yan@unisoc.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 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®