linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] cpuidle: not unset the driver if it already exist
@ 2019-10-23  1:57 Zhenzhong Duan
  2019-10-28 15:22 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Zhenzhong Duan @ 2019-10-23  1:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: rjw, daniel.lezcano, linux-pm, mtosatti, Zhenzhong Duan

__cpuidle_set_driver() check if there is an already exist driver and
unset it before return with -EBUSY. The next call will succeed as it's
just unset.

check if any of the CPUs in the mask have a driver different from drv
already and if so return -EBUSY before updating any cpuidle_drivers
per-CPU pointers.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
v2: update code logic per Rafael

 drivers/cpuidle/driver.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 80c1a83..acfce04 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -62,24 +62,23 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
  * __cpuidle_set_driver - set per CPU driver variables for the given driver.
  * @drv: a valid pointer to a struct cpuidle_driver
  *
- * For each CPU in the driver's cpumask, unset the registered driver per CPU
- * to @drv.
- *
- * Returns 0 on success, -EBUSY if the CPUs have driver(s) already.
+ * Returns 0 on success, -EBUSY if any CPU in the cpumask have a driver
+ * different from drv already.
  */
 static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
 {
 	int cpu;
 
 	for_each_cpu(cpu, drv->cpumask) {
+		struct cpuidle_driver *old_drv;
 
-		if (__cpuidle_get_cpu_driver(cpu)) {
-			__cpuidle_unset_driver(drv);
+		old_drv = __cpuidle_get_cpu_driver(cpu);
+		if (old_drv && old_drv != drv)
 			return -EBUSY;
-		}
+	}
 
+	for_each_cpu(cpu, drv->cpumask)
 		per_cpu(cpuidle_drivers, cpu) = drv;
-	}
 
 	return 0;
 }
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] cpuidle: not unset the driver if it already exist
  2019-10-23  1:57 [PATCH v2] cpuidle: not unset the driver if it already exist Zhenzhong Duan
@ 2019-10-28 15:22 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2019-10-28 15:22 UTC (permalink / raw)
  To: Zhenzhong Duan; +Cc: linux-kernel, daniel.lezcano, linux-pm, mtosatti

On Wednesday, October 23, 2019 3:57:14 AM CET Zhenzhong Duan wrote:
> __cpuidle_set_driver() check if there is an already exist driver and
> unset it before return with -EBUSY. The next call will succeed as it's
> just unset.
> 
> check if any of the CPUs in the mask have a driver different from drv
> already and if so return -EBUSY before updating any cpuidle_drivers
> per-CPU pointers.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> ---
> v2: update code logic per Rafael
> 
>  drivers/cpuidle/driver.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> index 80c1a83..acfce04 100644
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -62,24 +62,23 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
>   * __cpuidle_set_driver - set per CPU driver variables for the given driver.
>   * @drv: a valid pointer to a struct cpuidle_driver
>   *
> - * For each CPU in the driver's cpumask, unset the registered driver per CPU
> - * to @drv.
> - *
> - * Returns 0 on success, -EBUSY if the CPUs have driver(s) already.
> + * Returns 0 on success, -EBUSY if any CPU in the cpumask have a driver
> + * different from drv already.
>   */
>  static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
>  {
>  	int cpu;
>  
>  	for_each_cpu(cpu, drv->cpumask) {
> +		struct cpuidle_driver *old_drv;
>  
> -		if (__cpuidle_get_cpu_driver(cpu)) {
> -			__cpuidle_unset_driver(drv);
> +		old_drv = __cpuidle_get_cpu_driver(cpu);
> +		if (old_drv && old_drv != drv)
>  			return -EBUSY;
> -		}
> +	}
>  
> +	for_each_cpu(cpu, drv->cpumask)
>  		per_cpu(cpuidle_drivers, cpu) = drv;
> -	}
>  
>  	return 0;
>  }
> 

Applied as 5.5 material, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-28 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23  1:57 [PATCH v2] cpuidle: not unset the driver if it already exist Zhenzhong Duan
2019-10-28 15:22 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).