From: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, boqun.feng@gmail.com,
Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
Subject: [PATCH 2/2] locking/osq: Drop the overload of osq_lock()
Date: Sun, 26 Jun 2016 06:41:55 -0400 [thread overview]
Message-ID: <1466937715-6683-3-git-send-email-xinhui.pan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1466937715-6683-1-git-send-email-xinhui.pan@linux.vnet.ibm.com>
An over-committed guest with more vCPUs than pCPUs has a heavy overload
in osq_lock().
This is because vCPU A hold the osq lock and yield out, vCPU B wait
per_cpu node->locked to be set. IOW, vCPU B wait vCPU A to run and
unlock the osq lock.
So lets also use neet_yield_to() to detect if we need stop the spinning
Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
---
kernel/locking/osq_lock.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index 05a3785..4287603 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -21,6 +21,11 @@ static inline int encode_cpu(int cpu_nr)
return cpu_nr + 1;
}
+static inline int node_cpu(struct optimistic_spin_node *node)
+{
+ return node->cpu - 1;
+}
+
static inline struct optimistic_spin_node *decode_cpu(int encoded_cpu_val)
{
int cpu_nr = encoded_cpu_val - 1;
@@ -84,9 +89,10 @@ osq_wait_next(struct optimistic_spin_queue *lock,
bool osq_lock(struct optimistic_spin_queue *lock)
{
struct optimistic_spin_node *node = this_cpu_ptr(&osq_node);
- struct optimistic_spin_node *prev, *next;
+ struct optimistic_spin_node *prev, *next, *prev_old;
int curr = encode_cpu(smp_processor_id());
int old;
+ unsigned int yield_count;
node->locked = 0;
node->next = NULL;
@@ -114,14 +120,20 @@ bool osq_lock(struct optimistic_spin_queue *lock)
* guaranteed their existence -- this allows us to apply
* cmpxchg in an attempt to undo our queueing.
*/
-
+ prev_old = prev;
+ yield_count = vcpu_get_yield_count(node_cpu(prev));
while (!READ_ONCE(node->locked)) {
/*
* If we need to reschedule bail... so we can block.
*/
- if (need_resched())
+ if (need_resched() ||
+ need_yield_to(node_cpu(prev), yield_count))
goto unqueue;
+ prev = READ_ONCE(node->prev);
+ if (prev != prev_old)
+ yield_count = vcpu_get_yield_count(node_cpu(prev));
+
cpu_relax_lowlatency();
}
return true;
--
2.4.11
next prev parent reply other threads:[~2016-06-26 6:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-26 10:41 [PATCH 0/2] implement vcpu preempted check Pan Xinhui
2016-06-26 10:41 ` [PATCH 1/2] kernel/sched: introduce vcpu preempted interface Pan Xinhui
2016-06-27 8:42 ` Peter Zijlstra
2016-06-27 9:42 ` xinhui
2016-06-26 10:41 ` Pan Xinhui [this message]
2016-06-26 7:12 ` [PATCH 2/2] locking/osq: Drop the overload of osq_lock() panxinhui
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=1466937715-6683-3-git-send-email-xinhui.pan@linux.vnet.ibm.com \
--to=xinhui.pan@linux.vnet.ibm.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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
all inboxes | Powered by JetHome®