mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption
@ 2025-02-27  8:58 Abel Wu
  2025-02-27  8:58 ` [PATCH v2 1/2] sched/fair: Do not let idle entities preempt others Abel Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Abel Wu @ 2025-02-27  8:58 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, Phil Auld, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, Josh Don,
	Tianchen Ding
  Cc: Abel Wu, open list:SCHEDULER

The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
defines the behavior of SCHED_IDLE as following:

 - no SCHED_IDLE buddies
 - never let SCHED_IDLE preempt on wakeup
 - always preempt SCHED_IDLE on wakeup
 - limit SLEEPER fairness for SCHED_IDLE

and the middle two of them are broken now.

v2:
 - Collect Reviewed-by tags from Vincent, Josh and Madadi, thanks!
 - Rebased to up-to-date tip. (Madadi)
 - Folded some discussion with Vincent into commit log.

Abel Wu (2):
  sched/fair: Do not let idle entities preempt others
  sched/fair: Fix premature check of WAKEUP_PREEMPTION

 kernel/sched/fair.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

-- 
2.37.3


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

* [PATCH v2 1/2] sched/fair: Do not let idle entities preempt others
  2025-02-27  8:58 [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption Abel Wu
@ 2025-02-27  8:58 ` Abel Wu
  2025-02-27  8:58 ` [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION Abel Wu
  2025-02-28  8:05 ` [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption K Prateek Nayak
  2 siblings, 0 replies; 7+ messages in thread
From: Abel Wu @ 2025-02-27  8:58 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, Phil Auld, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, Josh Don,
	Tianchen Ding
  Cc: Abel Wu, open list:SCHEDULER

A task with SCHED_IDLE policy doesn't preempt others by definition, and
the semantics are intended to be preserved when extending to cgroups
introduced in commit 304000390f88 ("sched: Cgroup SCHED_IDLE support").

But current implementation allows idle entities to preempt each other
on wakeup, which seems not behave as expected especially after
commit faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
so fix this by explicitly skip wakeup preemption for idle entities.

Fixes: 304000390f88 ("sched: Cgroup SCHED_IDLE support")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Josh Don <joshdon@google.com>
Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
---
 kernel/sched/fair.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d042e94a79c3..aaa9822e9562 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8795,8 +8795,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	pse_is_idle = se_is_idle(pse);
 
 	/*
-	 * Preempt an idle entity in favor of a non-idle entity (and don't preempt
-	 * in the inverse case).
+	 * Preempt an idle entity in favor of a non-idle entity.
 	 */
 	if (cse_is_idle && !pse_is_idle) {
 		/*
@@ -8807,7 +8806,10 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 		goto preempt;
 	}
 
-	if (cse_is_idle != pse_is_idle)
+	/*
+	 * IDLE entities do not preempt others.
+	 */
+	if (unlikely(pse_is_idle))
 		return;
 
 	/*
-- 
2.37.3


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

* [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION
  2025-02-27  8:58 [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption Abel Wu
  2025-02-27  8:58 ` [PATCH v2 1/2] sched/fair: Do not let idle entities preempt others Abel Wu
@ 2025-02-27  8:58 ` Abel Wu
  2025-02-28 14:26   ` Vincent Guittot
  2025-02-28  8:05 ` [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption K Prateek Nayak
  2 siblings, 1 reply; 7+ messages in thread
From: Abel Wu @ 2025-02-27  8:58 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, Phil Auld, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, Josh Don,
	Tianchen Ding
  Cc: Abel Wu, open list:SCHEDULER

The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
defines the behavior of SCHED_IDLE as following:

 - no SCHED_IDLE buddies
 - never let SCHED_IDLE preempt on wakeup
 - always preempt SCHED_IDLE on wakeup
 - limit SLEEPER fairness for SCHED_IDLE

and the 3rd rule is broken if !WAKEUP_PREEMPTION due to recently merged
commit faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")

Although WAKEUP_PREEMPTION is mainly there for debug purpose to provide
a way to check whether a performance degrade of certain workload is due
to overscheduling or not, it is still kind of weird that we treat sched-
idle cpus as idle but don't let the non-idle tasks preempt the sched-idle
cpus in debug mode (!WAKEUP_PREEMPTION).

Fix it by strictly following the aforementioned rules.

Fixes: faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
---
 kernel/sched/fair.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index aaa9822e9562..a7eeb72d57aa 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8785,9 +8785,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	if (test_tsk_need_resched(rq->curr))
 		return;
 
-	if (!sched_feat(WAKEUP_PREEMPTION))
-		return;
-
 	find_matching_se(&se, &pse);
 	WARN_ON_ONCE(!pse);
 
@@ -8806,6 +8803,9 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 		goto preempt;
 	}
 
+	if (!sched_feat(WAKEUP_PREEMPTION))
+		return;
+
 	/*
 	 * IDLE entities do not preempt others.
 	 */
-- 
2.37.3


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

* Re: [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption
  2025-02-27  8:58 [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption Abel Wu
  2025-02-27  8:58 ` [PATCH v2 1/2] sched/fair: Do not let idle entities preempt others Abel Wu
  2025-02-27  8:58 ` [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION Abel Wu
@ 2025-02-28  8:05 ` K Prateek Nayak
  2025-03-03  3:30   ` Abel Wu
  2 siblings, 1 reply; 7+ messages in thread
From: K Prateek Nayak @ 2025-02-28  8:05 UTC (permalink / raw)
  To: Abel Wu, Madadi Vineeth Reddy, Phil Auld, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	Josh Don, Tianchen Ding
  Cc: open list:SCHEDULER

Hello Abel,

On 2/27/2025 2:28 PM, Abel Wu wrote:
> The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
> defines the behavior of SCHED_IDLE as following:
> 
>   - no SCHED_IDLE buddies
>   - never let SCHED_IDLE preempt on wakeup
>   - always preempt SCHED_IDLE on wakeup
>   - limit SLEEPER fairness for SCHED_IDLE
> 
> and the middle two of them are broken now.

Feel free to include:

Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
-- 
Thanks and Regards,
Prateek

> 
> v2:
>   - Collect Reviewed-by tags from Vincent, Josh and Madadi, thanks!
>   - Rebased to up-to-date tip. (Madadi)
>   - Folded some discussion with Vincent into commit log.
> 
> Abel Wu (2):
>    sched/fair: Do not let idle entities preempt others
>    sched/fair: Fix premature check of WAKEUP_PREEMPTION
> 
>   kernel/sched/fair.c | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
> 



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

* Re: [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION
  2025-02-27  8:58 ` [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION Abel Wu
@ 2025-02-28 14:26   ` Vincent Guittot
  2025-03-03  3:32     ` Abel Wu
  0 siblings, 1 reply; 7+ messages in thread
From: Vincent Guittot @ 2025-02-28 14:26 UTC (permalink / raw)
  To: Abel Wu
  Cc: Madadi Vineeth Reddy, Phil Auld, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, Josh Don, Tianchen Ding,
	open list:SCHEDULER

On Thu, 27 Feb 2025 at 09:58, Abel Wu <wuyun.abel@bytedance.com> wrote:
>
> The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
> defines the behavior of SCHED_IDLE as following:
>
>  - no SCHED_IDLE buddies
>  - never let SCHED_IDLE preempt on wakeup
>  - always preempt SCHED_IDLE on wakeup
>  - limit SLEEPER fairness for SCHED_IDLE
>
> and the 3rd rule is broken if !WAKEUP_PREEMPTION due to recently merged
> commit faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
>
> Although WAKEUP_PREEMPTION is mainly there for debug purpose to provide
> a way to check whether a performance degrade of certain workload is due
> to overscheduling or not, it is still kind of weird that we treat sched-
> idle cpus as idle but don't let the non-idle tasks preempt the sched-idle
> cpus in debug mode (!WAKEUP_PREEMPTION).
>
> Fix it by strictly following the aforementioned rules.
>
> Fixes: faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
> Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>

WAKEUP_PREEMPTION seems to be still used so

Acked-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---
>  kernel/sched/fair.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index aaa9822e9562..a7eeb72d57aa 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8785,9 +8785,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
>         if (test_tsk_need_resched(rq->curr))
>                 return;
>
> -       if (!sched_feat(WAKEUP_PREEMPTION))
> -               return;
> -
>         find_matching_se(&se, &pse);
>         WARN_ON_ONCE(!pse);
>
> @@ -8806,6 +8803,9 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
>                 goto preempt;
>         }
>
> +       if (!sched_feat(WAKEUP_PREEMPTION))
> +               return;
> +
>         /*
>          * IDLE entities do not preempt others.
>          */
> --
> 2.37.3
>

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

* Re: Re: [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption
  2025-02-28  8:05 ` [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption K Prateek Nayak
@ 2025-03-03  3:30   ` Abel Wu
  0 siblings, 0 replies; 7+ messages in thread
From: Abel Wu @ 2025-03-03  3:30 UTC (permalink / raw)
  To: K Prateek Nayak, Madadi Vineeth Reddy, Phil Auld, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	Josh Don, Tianchen Ding
  Cc: open list:SCHEDULER

On 2/28/25 4:05 PM, K Prateek Nayak wrote:
> Hello Abel,
> 
> On 2/27/2025 2:28 PM, Abel Wu wrote:
>> The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
>> defines the behavior of SCHED_IDLE as following:
>>
>>   - no SCHED_IDLE buddies
>>   - never let SCHED_IDLE preempt on wakeup
>>   - always preempt SCHED_IDLE on wakeup
>>   - limit SLEEPER fairness for SCHED_IDLE
>>
>> and the middle two of them are broken now.
> 
> Feel free to include:
> 
> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>

Thanks!


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

* Re: Re: [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION
  2025-02-28 14:26   ` Vincent Guittot
@ 2025-03-03  3:32     ` Abel Wu
  0 siblings, 0 replies; 7+ messages in thread
From: Abel Wu @ 2025-03-03  3:32 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Madadi Vineeth Reddy, Phil Auld, Ingo Molnar, Peter Zijlstra,
	Juri Lelli, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, Josh Don, Tianchen Ding,
	open list:SCHEDULER

On 2/28/25 10:26 PM, Vincent Guittot wrote:
> On Thu, 27 Feb 2025 at 09:58, Abel Wu <wuyun.abel@bytedance.com> wrote:
>>
>> The commit 6bc912b71b6f ("sched: SCHED_OTHER vs SCHED_IDLE isolation")
>> defines the behavior of SCHED_IDLE as following:
>>
>>   - no SCHED_IDLE buddies
>>   - never let SCHED_IDLE preempt on wakeup
>>   - always preempt SCHED_IDLE on wakeup
>>   - limit SLEEPER fairness for SCHED_IDLE
>>
>> and the 3rd rule is broken if !WAKEUP_PREEMPTION due to recently merged
>> commit faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
>>
>> Although WAKEUP_PREEMPTION is mainly there for debug purpose to provide
>> a way to check whether a performance degrade of certain workload is due
>> to overscheduling or not, it is still kind of weird that we treat sched-
>> idle cpus as idle but don't let the non-idle tasks preempt the sched-idle
>> cpus in debug mode (!WAKEUP_PREEMPTION).
>>
>> Fix it by strictly following the aforementioned rules.
>>
>> Fixes: faa42d29419d ("sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy")
>> Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
> 
> WAKEUP_PREEMPTION seems to be still used so
> 
> Acked-by: Vincent Guittot <vincent.guittot@linaro.org>

Thanks!


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

end of thread, other threads:[~2025-03-03  3:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27  8:58 [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption Abel Wu
2025-02-27  8:58 ` [PATCH v2 1/2] sched/fair: Do not let idle entities preempt others Abel Wu
2025-02-27  8:58 ` [PATCH v2 2/2] sched/fair: Fix premature check of WAKEUP_PREEMPTION Abel Wu
2025-02-28 14:26   ` Vincent Guittot
2025-03-03  3:32     ` Abel Wu
2025-02-28  8:05 ` [PATCH v2 0/2] Fix SCHED_IDLE behavior on wakeup preemption K Prateek Nayak
2025-03-03  3:30   ` Abel Wu

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®