Skip to content

Commit

Permalink
sched: Limit the scope of clear_buddies
Browse files Browse the repository at this point in the history
The clear_buddies function does not seem to play well with the concept
of hierarchical runqueues.  In the following tree, task groups are
represented by 'G', tasks by 'T', next by 'n' and last by 'l'.

     (nl)
    /    \
   G(nl)  G
   / \     \
 T(l) T(n)  T

This situation can arise when a task is woken up T(n), and the previously
running task T(l) is marked last.

When clear_buddies is called from either T(l) or T(n), the next and last
buddies of the group G(nl) will be cleared.  This is not the desired
result, since we would like to be able to find the other type of buddy
in many cases.

This especially a worry when implementing yield_task_fair through the
buddy system.

The fix is simple: only clear the buddy type that the task itself
is indicated to be.  As an added bonus, we stop walking up the tree
when the buddy has already been cleared or pointed elsewhere.

Signed-off-by: Rik van Riel <riel@redhat.coM>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20110201094837.6b0962a9@annuminas.surriel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Rik van Riel authored and Ingo Molnar committed Feb 3, 2011
1 parent 725e758 commit 2c13c91
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions kernel/sched_fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,19 +995,35 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
list_add_leaf_cfs_rq(cfs_rq);
}

static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
static void __clear_buddies_last(struct sched_entity *se)
{
if (!se || cfs_rq->last == se)
cfs_rq->last = NULL;
for_each_sched_entity(se) {
struct cfs_rq *cfs_rq = cfs_rq_of(se);
if (cfs_rq->last == se)
cfs_rq->last = NULL;
else
break;
}
}

if (!se || cfs_rq->next == se)
cfs_rq->next = NULL;
static void __clear_buddies_next(struct sched_entity *se)
{
for_each_sched_entity(se) {
struct cfs_rq *cfs_rq = cfs_rq_of(se);
if (cfs_rq->next == se)
cfs_rq->next = NULL;
else
break;
}
}

static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
for_each_sched_entity(se)
__clear_buddies(cfs_rq_of(se), se);
if (cfs_rq->last == se)
__clear_buddies_last(se);

if (cfs_rq->next == se)
__clear_buddies_next(se);
}

static void
Expand Down

0 comments on commit 2c13c91

Please sign in to comment.