LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Rik van Riel <riel@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Avi Kiviti <avi@redhat.com>,
Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mike Galbraith <efault@gmx.de>,
Chris Wright <chrisw@sous-sol.org>,
ttracy@redhat.com, "Nakajima, Jun" <jun.nakajima@intel.com>
Subject: [RFC -v7 PATCH 2/7] sched: limit the scope of clear_buddies
Date: Wed, 26 Jan 2011 17:19:46 -0500 [thread overview]
Message-ID: <20110126171946.674c4a60@annuminas.surriel.com> (raw)
In-Reply-To: <20110126165657.2ddd2ac9@annuminas.surriel.com>
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>
---
kernel/sched_fair.c | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index f4ee445..0321473 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -784,19 +784,35 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
__enqueue_entity(cfs_rq, se);
}
-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
next prev parent reply other threads:[~2011-01-26 22:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-26 21:56 [RFC -v7 PATCH 0/7] directed yield for Pause Loop Exiting Rik van Riel
2011-01-26 22:19 ` Rik van Riel [this message]
2011-01-26 22:19 ` [RFC -v7 PATCH 1/7] sched: check the right ->nr_running in yield_task_fair Rik van Riel
2011-01-26 22:21 ` [RFC -v7 PATCH 3/7] sched: use a buddy to implement yield_task_fair Rik van Riel
2011-01-31 11:47 ` Peter Zijlstra
2011-01-31 15:02 ` Rik van Riel
2011-01-26 22:21 ` [RFC -v7 PATCH 4/7] Add yield_to(task, preempt) functionality Rik van Riel
2011-01-31 11:49 ` Peter Zijlstra
2011-01-31 18:11 ` Rik van Riel
2011-01-26 22:23 ` [RFC -v7 PATCH 5/7] export pid symbols needed for kvm_vcpu_on_spin Rik van Riel
2011-01-31 11:51 ` Peter Zijlstra
2011-01-31 13:26 ` Avi Kivity
2011-01-31 13:43 ` Peter Zijlstra
2011-01-31 13:45 ` Avi Kivity
2011-01-26 22:24 ` [RFC -v7 PATCH 6/7] kvm: keep track of which task is running a KVM vcpu Rik van Riel
2011-01-26 22:25 ` [RFC -v7 PATCH 7/7] kvm: use yield_to instead of sleep in kvm_vcpu_on_spin Rik van Riel
2011-01-27 13:20 ` [RFC -v7 PATCH 0/7] directed yield for Pause Loop Exiting Avi Kivity
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=20110126171946.674c4a60@annuminas.surriel.com \
--to=riel@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=avi@redhat.com \
--cc=chrisw@sous-sol.org \
--cc=efault@gmx.de \
--cc=jun.nakajima@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ttracy@redhat.com \
--cc=vatsa@linux.vnet.ibm.com \
--subject='Re: [RFC -v7 PATCH 2/7] sched: limit the scope of clear_buddies' \
/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
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).