Skip to contentSkip to conversation

locking/pvqspinlock: Wait early if vCPU is preempted

PATCH New Pan Xinhui 2 participants 2 messages Jan 10, 2017 – Jan 12, 2017 Locking primitives

lore
Share & tools
lore

Pan Xinhui

author
#0 lore raw

PATCH v2 1/1 locking/pvqspinlock: Wait early if vCPU is preempted

If prev node is not in runnig state or its vCPU is preempted, we can give up our vCPU slices ASAP in pv_wait_node. After commit d9345c65eb79 ("sched/core: Introduce the vcpu_is_preempted(cpu) interface") kernel has knowledge of one vCPU is running or not.

---
v2:
rewrite the commit message as Ingo pointed out the mistake.

---
 kernel/locking/qspinlock_paravirt.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/locking/qspinlock_paravirt.h +2 -1
index e3b5520..48648dc 100644
@@ -263,7 +263,8 @@ pv_wait_early(struct pv_node *prev, int loop)
 	if ((loop & PV_PREV_CHECK_MASK) != 0)
 		return false;
 
-	return READ_ONCE(prev->state) != vcpu_running;
+	return READ_ONCE(prev->state) != vcpu_running ||
+				vcpu_is_preempted(prev->cpu);
 }
 
 /*
Signature · 1 line
2.4.11
#1 lore raw

[tip:locking/core] locking/pvqspinlock: Don't wait if vCPU is preempted

locking/pvqspinlock: Don't wait if vCPU is preempted
Commit-ID:  75437bb304b20a2b350b9a8e9f9238d5e24e12ba
Gitweb:     http://git.kernel.org/tip/75437bb304b20a2b350b9a8e9f9238d5e24e12ba
Author:     Pan Xinhui <[email protected]>
AuthorDate: Tue, 10 Jan 2017 02:56:46 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 12 Jan 2017 09:35:57 +0100

locking/pvqspinlock: Don't wait if vCPU is preempted

If prev node is not in running state or its vCPU is preempted, we can give up our vCPU slices in pv_wait_node() ASAP.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Fixed typos in the changelog, removed ugly linebreak from the code. ]
---
 kernel/locking/qspinlock_paravirt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/qspinlock_paravirt.h +1 -1
index e3b5520..e6b2f7a 100644
@@ -263,7 +263,7 @@ pv_wait_early(struct pv_node *prev, int loop)
 	if ((loop & PV_PREV_CHECK_MASK) != 0)
 		return false;
 
-	return READ_ONCE(prev->state) != vcpu_running;
+	return READ_ONCE(prev->state) != vcpu_running || vcpu_is_preempted(prev->cpu);
 }
 
 /*