linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/fair: add !se->on_rq check before dequeue entity
@ 2020-02-20  7:29 qiwuchen55
  2020-02-20  9:38 ` Vincent Guittot
  0 siblings, 1 reply; 6+ messages in thread
From: qiwuchen55 @ 2020-02-20  7:29 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman
  Cc: linux-kernel, chenqiwu

From: chenqiwu <chenqiwu@xiaomi.com>

We igonre checking for !se->on_rq condition before dequeue one
entity from cfs rq. It must be required in case the entity has
been dequeued.

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
 kernel/sched/fair.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 3c8a379..945dcaf 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5341,6 +5341,8 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	bool was_sched_idle = sched_idle_rq(rq);
 
 	for_each_sched_entity(se) {
+		if (!se->on_rq)
+			break;
 		cfs_rq = cfs_rq_of(se);
 		dequeue_entity(cfs_rq, se, flags);
 
-- 
1.9.1


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

* Re: [PATCH] sched/fair: add !se->on_rq check before dequeue entity
  2020-02-20  7:29 [PATCH] sched/fair: add !se->on_rq check before dequeue entity qiwuchen55
@ 2020-02-20  9:38 ` Vincent Guittot
  2020-02-20 10:09   ` chenqiwu
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Guittot @ 2020-02-20  9:38 UTC (permalink / raw)
  To: qiwuchen55
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, linux-kernel, chenqiwu

On Thu, 20 Feb 2020 at 08:29, <qiwuchen55@gmail.com> wrote:
>
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> We igonre checking for !se->on_rq condition before dequeue one
> entity from cfs rq. It must be required in case the entity has
> been dequeued.

Do you have a use case that triggers this situation ?

This is the only way to reach this situation seems to be dequeuing a
task on a throttled cfs_rq

>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
>  kernel/sched/fair.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 3c8a379..945dcaf 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5341,6 +5341,8 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>         bool was_sched_idle = sched_idle_rq(rq);
>
>         for_each_sched_entity(se) {
> +               if (!se->on_rq)
> +                       break;
>                 cfs_rq = cfs_rq_of(se);
>                 dequeue_entity(cfs_rq, se, flags);
>
> --
> 1.9.1
>

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

* Re: [PATCH] sched/fair: add !se->on_rq check before dequeue entity
  2020-02-20  9:38 ` Vincent Guittot
@ 2020-02-20 10:09   ` chenqiwu
  2020-02-20 10:31     ` Vincent Guittot
  0 siblings, 1 reply; 6+ messages in thread
From: chenqiwu @ 2020-02-20 10:09 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, linux-kernel, chenqiwu

On Thu, Feb 20, 2020 at 10:38:02AM +0100, Vincent Guittot wrote:
> On Thu, 20 Feb 2020 at 08:29, <qiwuchen55@gmail.com> wrote:
> >
> > From: chenqiwu <chenqiwu@xiaomi.com>
> >
> > We igonre checking for !se->on_rq condition before dequeue one
> > entity from cfs rq. It must be required in case the entity has
> > been dequeued.
> 
> Do you have a use case that triggers this situation ?
> 
> This is the only way to reach this situation seems to be dequeuing a
> task on a throttled cfs_rq
>
Sorry, I have no use case triggers this situation. It's just found by
reading code.
I agree the situation you mentioned above may have a racy with
dequeue_task_fair() in the following code path:
__schedule
	pick_next_task_fair
		put_prev_entity
			check_cfs_rq_runtime
				throttle_cfs_rq
					dequeue_entity

So this check is worth to be added for dequeue_task_fair().

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

* Re: [PATCH] sched/fair: add !se->on_rq check before dequeue entity
  2020-02-20 10:09   ` chenqiwu
@ 2020-02-20 10:31     ` Vincent Guittot
  2020-02-20 12:15       ` Vincent Guittot
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Guittot @ 2020-02-20 10:31 UTC (permalink / raw)
  To: chenqiwu
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, linux-kernel, chenqiwu

On Thu, 20 Feb 2020 at 11:09, chenqiwu <qiwuchen55@gmail.com> wrote:
>
> On Thu, Feb 20, 2020 at 10:38:02AM +0100, Vincent Guittot wrote:
> > On Thu, 20 Feb 2020 at 08:29, <qiwuchen55@gmail.com> wrote:
> > >
> > > From: chenqiwu <chenqiwu@xiaomi.com>
> > >
> > > We igonre checking for !se->on_rq condition before dequeue one
> > > entity from cfs rq. It must be required in case the entity has
> > > been dequeued.
> >
> > Do you have a use case that triggers this situation ?
> >
> > This is the only way to reach this situation seems to be dequeuing a
> > task on a throttled cfs_rq
> >
> Sorry, I have no use case triggers this situation. It's just found by
> reading code.
> I agree the situation you mentioned above may have a racy with
> dequeue_task_fair() in the following code path:
> __schedule
>         pick_next_task_fair
>                 put_prev_entity
>                         check_cfs_rq_runtime
>                                 throttle_cfs_rq
>                                         dequeue_entity
>
> So this check is worth to be added for dequeue_task_fair().

In fact the check is already done thanks to the: if (cfs_rq_throttled(cfs_rq))
AFAICT, there is no other way to enqueue a task on a cfs_rq for which
the group entity is not enqueued

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

* Re: [PATCH] sched/fair: add !se->on_rq check before dequeue entity
  2020-02-20 10:31     ` Vincent Guittot
@ 2020-02-20 12:15       ` Vincent Guittot
  2020-02-20 14:42         ` chenqiwu
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Guittot @ 2020-02-20 12:15 UTC (permalink / raw)
  To: chenqiwu
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, linux-kernel, chenqiwu

On Thu, 20 Feb 2020 at 11:31, Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> On Thu, 20 Feb 2020 at 11:09, chenqiwu <qiwuchen55@gmail.com> wrote:
> >
> > On Thu, Feb 20, 2020 at 10:38:02AM +0100, Vincent Guittot wrote:
> > > On Thu, 20 Feb 2020 at 08:29, <qiwuchen55@gmail.com> wrote:
> > > >
> > > > From: chenqiwu <chenqiwu@xiaomi.com>
> > > >
> > > > We igonre checking for !se->on_rq condition before dequeue one
> > > > entity from cfs rq. It must be required in case the entity has
> > > > been dequeued.
> > >
> > > Do you have a use case that triggers this situation ?
> > >
> > > This is the only way to reach this situation seems to be dequeuing a
> > > task on a throttled cfs_rq
> > >
> > Sorry, I have no use case triggers this situation. It's just found by
> > reading code.
> > I agree the situation you mentioned above may have a racy with
> > dequeue_task_fair() in the following code path:
> > __schedule
> >         pick_next_task_fair
> >                 put_prev_entity
> >                         check_cfs_rq_runtime
> >                                 throttle_cfs_rq
> >                                         dequeue_entity
> >
> > So this check is worth to be added for dequeue_task_fair().
>
> In fact the check is already done thanks to the: if (cfs_rq_throttled(cfs_rq))
> AFAICT, there is no other way to enqueue a task on a cfs_rq for which
> the group entity is not enqueued

Hmm i have been too quick in my reply. I wanted to say:
AFAICT, there is no other way to dequeue a task from a cfs_rq for
which the group entity is not enqueued

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

* Re: [PATCH] sched/fair: add !se->on_rq check before dequeue entity
  2020-02-20 12:15       ` Vincent Guittot
@ 2020-02-20 14:42         ` chenqiwu
  0 siblings, 0 replies; 6+ messages in thread
From: chenqiwu @ 2020-02-20 14:42 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, linux-kernel, chenqiwu

> 
> Hmm i have been too quick in my reply. I wanted to say:
> AFAICT, there is no other way to dequeue a task from a cfs_rq for
> which the group entity is not enqueued

But we should notice the potential racy pathes called by deactivate_task().
For example:
One path is dequeue a task from its cfs_rq called by schedule():
__schedule
	deactivate_task
		dequeue_task
			dequeue_task_fair

Another path is trying to migrate the same task to a CPU on the preferred node:
numa_migrate_preferred
	task_numa_migrate	
		migrate_swap
			stop_two_cpus
				migrate_swap_stop
					__migrate_swap_task
						deactivate_task
							dequeue_task_fair

There could be a racy if the task is dequeued form its cfs_rq in parallel.

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

end of thread, other threads:[~2020-02-20 14:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20  7:29 [PATCH] sched/fair: add !se->on_rq check before dequeue entity qiwuchen55
2020-02-20  9:38 ` Vincent Guittot
2020-02-20 10:09   ` chenqiwu
2020-02-20 10:31     ` Vincent Guittot
2020-02-20 12:15       ` Vincent Guittot
2020-02-20 14:42         ` chenqiwu

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).