Re: [PATCH v3] sched/fair: Do not set skip buddy up the sched hierarchy

From: Vincent Guittot
Date: Thu Dec 26 2019 - 10:06:03 EST


On Thu, 19 Dec 2019 at 01:14, Josh Don <joshdon@xxxxxxxxxx> wrote:
>
> From: Venkatesh Pallipadi <venki@xxxxxxxxxx>
>
> Setting the skip buddy up the hierarchy effectively means that a thread
> calling yield will also end up skipping the other tasks in its hierarchy
> as well. However, a yielding thread shouldn't end up causing this
> behavior on behalf of its entire hierarchy.
>
> For typical uses of yield, setting the skip buddy up the hierarchy is
> counter-productive, as that results in CPU being yielded to a task in
> some other cgroup.
>
> So, limit the skip effect only to the task requesting it.
>
> Co-developed-by: Josh Don <joshdon@xxxxxxxxxx>
> Signed-off-by: Josh Don <joshdon@xxxxxxxxxx>

Reviewed-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>

> ---
> v2: Only clear skip buddy on the current cfs_rq
>
> v3: Modify comment describing the justification for this change.
>
> kernel/sched/fair.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 08a233e97a01..0056b57d52cb 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4051,13 +4051,10 @@ static void __clear_buddies_next(struct sched_entity *se)
>
> static void __clear_buddies_skip(struct sched_entity *se)
> {
> - for_each_sched_entity(se) {
> - struct cfs_rq *cfs_rq = cfs_rq_of(se);
> - if (cfs_rq->skip != se)
> - break;
> + struct cfs_rq *cfs_rq = cfs_rq_of(se);
>
> + if (cfs_rq->skip == se)
> cfs_rq->skip = NULL;
> - }
> }
>
> static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
> @@ -6552,8 +6549,12 @@ static void set_next_buddy(struct sched_entity *se)
>
> static void set_skip_buddy(struct sched_entity *se)
> {
> - for_each_sched_entity(se)
> - cfs_rq_of(se)->skip = se;
> + /*
> + * Only set the skip buddy for the task requesting it. Setting the skip
> + * buddy up the hierarchy would result in skipping all other tasks in
> + * the hierarchy as well.
> + */
> + cfs_rq_of(se)->skip = se;
> }
>
> /*
> --
> 2.24.1.735.g03f4e72817-goog
>