2019-12-19 00:15:32

by Josh Don

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

From: Venkatesh Pallipadi <[email protected]>

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 <[email protected]>
Signed-off-by: Josh Don <[email protected]>
---
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


2019-12-26 15:06:58

by Vincent Guittot

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

On Thu, 19 Dec 2019 at 01:14, Josh Don <[email protected]> wrote:
>
> From: Venkatesh Pallipadi <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Josh Don <[email protected]>

Reviewed-by: Vincent Guittot <[email protected]>

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

2020-02-25 01:50:48

by Josh Don

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

Bumping in case this fell through the cracks of the patch queue

On Thu, Dec 26, 2019 at 7:05 AM Vincent Guittot
<[email protected]> wrote:
>
> On Thu, 19 Dec 2019 at 01:14, Josh Don <[email protected]> wrote:
> >
> > From: Venkatesh Pallipadi <[email protected]>
> >
> > 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 <[email protected]>
> > Signed-off-by: Josh Don <[email protected]>
>
> Reviewed-by: Vincent Guittot <[email protected]>
>
> > ---
> > 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
> >