[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0iM1GZppArfDQ5T7oNC8i7nr4OatYvdA80vDZwgms8VQA@mail.gmail.com>
Date: Mon, 25 Aug 2025 16:51:37 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Yaxiong Tian <tianyaxiong@...inos.cn>
Cc: rafael@...nel.org, daniel.lezcano@...aro.org, lenb@...nel.org,
robert.moore@...el.com, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
acpica-devel@...ts.linux.dev, Shaobo Huang <huangshaobo2075@...tium.com.cn>,
Yinfeng Wang <wangyinfeng@...tium.com.cn>, Xu Wang <wangxu@...tium.com.cn>
Subject: Re: [PATCH v2 1/2] cpuidle: Add interface to get cpuidle_driver by
CPU ID
On Thu, Aug 14, 2025 at 9:32 AM Yaxiong Tian <tianyaxiong@...inos.cn> wrote:
>
> Some drivers need to obtain the cpuidle_driver via CPU ID before the
> cpuidle_device is registered. Therefore, this interface is added.
>
> Tested-by: Shaobo Huang <huangshaobo2075@...tium.com.cn>
> Signed-off-by: Yaxiong Tian <tianyaxiong@...inos.cn>
> Signed-off-by: Shaobo Huang <huangshaobo2075@...tium.com.cn>
> Signed-off-by: Yinfeng Wang <wangyinfeng@...tium.com.cn>
> Signed-off-by: Xu Wang<wangxu@...tium.com.cn>
> ---
> drivers/cpuidle/driver.c | 16 ++++++++++++++++
> include/linux/cpuidle.h | 4 ++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> index 9bbfa594c442..8647f8165863 100644
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -353,6 +353,22 @@ struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
> }
> EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
>
> +/**
> + * cpuidle_get_cpu_driver_by_cpu - return the driver registered for a CPU.
> + * @cpu_num: a valid cpu num
> + *
> + * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered
> + * for the CPU associated with @cpu.
> + */
> +struct cpuidle_driver *cpuidle_get_cpu_driver_by_cpu(int cpu_num)
> +{
> + if (cpu_num < 0 || cpu_num >= nr_cpu_ids)
> + return NULL;
What about changing the __cpuidle_get_cpu_driver() parameter type to
unsigned int and also passing unsigned int to this function? The
first check above can go away then.
> +
> + return __cpuidle_get_cpu_driver(cpu_num);
> +}
> +EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver_by_cpu);
> +
> /**
> * cpuidle_driver_state_disabled - Disable or enable an idle state
> * @drv: cpuidle driver owning the state
> diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
> index a9ee4fe55dcf..aebbaae6a501 100644
> --- a/include/linux/cpuidle.h
> +++ b/include/linux/cpuidle.h
> @@ -200,6 +200,7 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);
> extern int cpuidle_play_dead(void);
>
> extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
> +extern struct cpuidle_driver *cpuidle_get_cpu_driver_by_cpu(int cpu_num);
> static inline struct cpuidle_device *cpuidle_get_device(void)
> {return __this_cpu_read(cpuidle_devices); }
> #else
> @@ -240,6 +241,9 @@ static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
> static inline int cpuidle_play_dead(void) {return -ENODEV; }
> static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
> struct cpuidle_device *dev) {return NULL; }
> +
> +static inline struct cpuidle_driver *cpuidle_get_cpu_driver_by_cpu(
> + int cpu_num) {return NULL; };
> static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
> #endif
>
> --
> 2.25.1
>
Powered by blists - more mailing lists