sched/fair: fix returning possible non-optimal candidate

Message ID 20230621071605.3853119-1-linmiaohe@huawei.com
State New
Headers
Series sched/fair: fix returning possible non-optimal candidate |

Commit Message

Miaohe Lin June 21, 2023, 7:16 a.m. UTC
  In best_fits < 0 case, best_thermal_cap > prev_thermal_cap is checked to
determine whether best_energy_cpu should be returned. But prev_fits can
be > 0 in this case and it should be preferred.

Fixes: e5ed0550c04c ("sched/fair: unlink misfit task from cpu overutilized")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Vincent Guittot June 21, 2023, 8:30 a.m. UTC | #1
On Wed, 21 Jun 2023 at 09:16, Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> In best_fits < 0 case, best_thermal_cap > prev_thermal_cap is checked to
> determine whether best_energy_cpu should be returned. But prev_fits can
> be > 0 in this case and it should be preferred.

IIRC, (best_thermal_cap > prev_thermal_cap) makes the condition
(prev_fits < 0) useless

Do you have a use case where
(best_fits < 0)
&& (prev_fits > 0)
&& (best_thermal_cap > prev_thermal_cap)
?

>
> Fixes: e5ed0550c04c ("sched/fair: unlink misfit task from cpu overutilized")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  kernel/sched/fair.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 28ff831ee847..a4e300fc44be 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7684,7 +7684,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
>
>         if ((best_fits > prev_fits) ||
>             ((best_fits > 0) && (best_delta < prev_delta)) ||
> -           ((best_fits < 0) && (best_thermal_cap > prev_thermal_cap)))
> +           ((best_fits < 0) && (prev_fits < 0) && (best_thermal_cap > prev_thermal_cap)))
>                 target = best_energy_cpu;
>
>         return target;
> --
> 2.27.0
>
  

Patch

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 28ff831ee847..a4e300fc44be 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7684,7 +7684,7 @@  static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
 
 	if ((best_fits > prev_fits) ||
 	    ((best_fits > 0) && (best_delta < prev_delta)) ||
-	    ((best_fits < 0) && (best_thermal_cap > prev_thermal_cap)))
+	    ((best_fits < 0) && (prev_fits < 0) && (best_thermal_cap > prev_thermal_cap)))
 		target = best_energy_cpu;
 
 	return target;