public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, tj@kernel.org,
	sargun@sargun.me
Subject: Re: [PATCH v2] sched/fair: Fix insertion in rq->leaf_cfs_rq_list
Date: Wed, 30 Jan 2019 14:04:10 +0100	[thread overview]
Message-ID: <20190130130410.GG2278@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <1548825767-10799-1-git-send-email-vincent.guittot@linaro.org>

On Wed, Jan 30, 2019 at 06:22:47AM +0100, Vincent Guittot wrote:

> The algorithm used to order cfs_rq in rq->leaf_cfs_rq_list assumes that
> it will walk down to root the 1st time a cfs_rq is used and we will finish
> to add either a cfs_rq without parent or a cfs_rq with a parent that is
> already on the list. But this is not always true in presence of throttling.
> Because a cfs_rq can be throttled even if it has never been used but other CPUs
> of the cgroup have already used all the bandwdith, we are not sure to go down to
> the root and add all cfs_rq in the list.
> 
> Ensure that all cfs_rq will be added in the list even if they are throttled.

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index e2ff4b6..826fbe5 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -352,6 +352,20 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
>  	}
>  }
>  
> +static inline void list_add_branch_cfs_rq(struct sched_entity *se, struct rq *rq)
> +{
> +	struct cfs_rq *cfs_rq;
> +
> +	for_each_sched_entity(se) {
> +		cfs_rq = cfs_rq_of(se);
> +		list_add_leaf_cfs_rq(cfs_rq);
> +
> +		/* If parent is already in the list, we can stop */
> +		if (rq->tmp_alone_branch == &rq->leaf_cfs_rq_list)
> +			break;
> +	}
> +}
> +
>  /* Iterate through all leaf cfs_rq's on a runqueue: */
>  #define for_each_leaf_cfs_rq(rq, cfs_rq) \
>  	list_for_each_entry_rcu(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list)

> @@ -5179,6 +5197,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>  
>  	}
>  
> +	/* Ensure that all cfs_rq have been added to the list */
> +	list_add_branch_cfs_rq(se, rq);
> +
>  	hrtick_update(rq);
>  }

So I don't much like this; at all. But maybe I misunderstand, this is
somewhat tricky stuff and I've not looked at it in a while.

So per normal we do:

	enqueue_task_fair()
	  for_each_sched_entity() {
	    if (se->on_rq)
	      break;
	    enqueue_entity()
	      list_add_leaf_cfs_rq();
	  }

This ensures that all parents are already enqueued, right? because this
is what enqueues those parents.

And in this case you add an unconditional second
for_each_sched_entity(); even though it is completely redundant, afaict.


The problem seems to stem from the whole throttled crud; which (also)
breaks the above enqueue loop on throttle state, and there the parent can
go missing.

So why doesn't this live in unthrottle_cfs_rq() ?


  reply	other threads:[~2019-01-30 13:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 17:18 [PATCH] sched/fair: Fix insertion in rq->leaf_cfs_rq_list Vincent Guittot
2019-01-30  5:22 ` [PATCH v2] " Vincent Guittot
2019-01-30 13:04   ` Peter Zijlstra [this message]
2019-01-30 13:06     ` Peter Zijlstra
2019-01-30 13:27       ` Peter Zijlstra
2019-01-30 13:29         ` Vincent Guittot
2019-01-30 13:40           ` Peter Zijlstra
2019-01-30 15:48             ` Vincent Guittot
2019-01-30 16:58               ` Peter Zijlstra
2019-01-30 14:01   ` Peter Zijlstra
2019-01-30 14:01     ` Peter Zijlstra
2019-01-30 14:27       ` Vincent Guittot
2019-01-30 17:40         ` Vincent Guittot
2019-01-30 14:30     ` Vincent Guittot
2019-02-04  9:03   ` [tip:sched/core] " tip-bot for Vincent Guittot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130130410.GG2278@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sargun@sargun.me \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox