Skip to contentSkip to conversation

irq_work, Use llist in irq_work

PATCH In review Huang Ying 5 participants 23 messages Sep 8, 2011 – Sep 13, 2011

Subsystems (4)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

cover irq_work, Use llist in irq_work

Changes:

v2:

- Return whether list is empty before adding in llist_add and use that in __irq_work_queue

[PATCH -mm -v2 1/5] llist, Make all llist functions inline
[PATCH -mm -v2 2/5] llist, Define macro to check NMI safe cmpxchg [PATCH -mm -v2 3/5] llist, Move cpu_relax after cmpxchg
[PATCH -mm -v2 4/5] llist, Return whether list is empty before adding in llist_add [PATCH -mm -v2 5/5] irq_work, Use llist in irq_work

author
#1 lore raw

PATCH 1/5 llist, Make all llist functions inline

Because llist may be used in performance critical code path, make all llist functions inline to avoid function calling overhead.

---
 drivers/acpi/apei/Kconfig |    1 
 include/linux/llist.h     |  122 +++++++++++++++++++++++++++++++++++++++++--
 lib/Kconfig               |    3 -
 lib/Makefile              |    2 
 lib/llist.c               |  129 ----------------------------------------------
 5 files changed, 116 insertions(+), 141 deletions(-)
 delete mode 100644 lib/llist.c
drivers/acpi/apei/Kconfig +0 -1
@@ -14,7 +14,6 @@ config ACPI_APEI_GHES
 	depends on ACPI_APEI && X86
 	select ACPI_HED
 	select IRQ_WORK
-	select LLIST
 	select GENERIC_ALLOCATOR
 	help
 	  Generic Hardware Error Source provides a way to report
include/linux/llist.h +116 -6

138 lines not on this page · raw message

lib/Kconfig +0 -3
@@ -276,7 +276,4 @@ config CORDIC
 	  so its calculations are in fixed point. Modules can select this
 	  when they require this function. Module will be called cordic.
 
-config LLIST
-	bool
-
 endmenu
lib/Makefile +0 -2
@@ -116,8 +116,6 @@ obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o
 
 obj-$(CONFIG_CORDIC) += cordic.o
 
-obj-$(CONFIG_LLIST) += llist.o
-
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/llist.c deleted +0 -129

129 lines not on this page · raw message

author
#2 lore raw

PATCH 2/5 llist, Define macro to check NMI safe cmpxchg

In reply to Huang Ying

To make code cleaner and reduce code duplication. Thanks Peter Zijlstra for reminding.

Cc Mathieu Desnoyers <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 include/linux/llist.h |   22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
include/linux/llist.h +10 -12
@@ -70,6 +70,12 @@ struct llist_node {
 #define LLIST_HEAD_INIT(name)	{ NULL }
 #define LLIST_HEAD(name)	struct llist_head name = LLIST_HEAD_INIT(name)
 
+#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
+#define CHECK_NMI_SAFE_CMPXCHG()
+#else
+#define CHECK_NMI_SAFE_CMPXCHG()	BUG_ON(in_nmi())
+#endif
+
 /**
  * init_llist_head - initialize lock-less list head
  * @head:	the head for your lock-less list
@@ -147,9 +153,7 @@ static inline void llist_add(struct llis
 {
 	struct llist_node *entry, *old_entry;
 
-#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
-	BUG_ON(in_nmi());
-#endif
+	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
 	do {
@@ -171,9 +175,7 @@ static inline void llist_add_batch(struc
 {
 	struct llist_node *entry, *old_entry;
 
-#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
-	BUG_ON(in_nmi());
-#endif
+	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
 	do {
@@ -201,9 +203,7 @@ static inline struct llist_node *llist_d
 {
 	struct llist_node *entry, *old_entry, *next;
 
-#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
-	BUG_ON(in_nmi());
-#endif
+	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
 	do {
@@ -227,9 +227,7 @@ static inline struct llist_node *llist_d
  */
 static inline struct llist_node *llist_del_all(struct llist_head *head)
 {
-#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
-	BUG_ON(in_nmi());
-#endif
+	CHECK_NMI_SAFE_CMPXCHG();
 
 	return xchg(&head->first, NULL);
 }
author
#3 lore raw

PATCH 3/5 llist, Move cpu_relax after cmpxchg

In reply to Huang Ying

If the first cmpxchg calling succeeds, it is not necessary to use cpu_relax before cmpxchg. So cpu_relax in a busy loop involving cmpxchg should go after cmpxchg instead of before that. This patch fixes this in llist.

---
 include/linux/llist.h |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
include/linux/llist.h +15 -6
@@ -156,11 +156,14 @@ static inline void llist_add(struct llis
 	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
-	do {
+	for (;;) {
 		old_entry = entry;
 		new->next = entry;
+		entry = cmpxchg(&head->first, old_entry, new);
+		if (entry == old_entry)
+			break;
 		cpu_relax();
-	} while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry);
+	}
 }
 
 /**
@@ -178,11 +181,14 @@ static inline void llist_add_batch(struc
 	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
-	do {
+	for (;;) {
 		old_entry = entry;
 		new_last->next = entry;
+		entry = cmpxchg(&head->first, old_entry, new_first);
+		if (entry == old_entry)
+			break;
 		cpu_relax();
-	} while ((entry = cmpxchg(&head->first, old_entry, new_first)) != old_entry);
+	}
 }
 
 /**
@@ -206,13 +212,16 @@ static inline struct llist_node *llist_d
 	CHECK_NMI_SAFE_CMPXCHG();
 
 	entry = head->first;
-	do {
+	for (;;) {
 		if (entry == NULL)
 			return NULL;
 		old_entry = entry;
 		next = entry->next;
+		entry = cmpxchg(&head->first, old_entry, next);
+		if (entry == old_entry)
+			break;
 		cpu_relax();
-	} while ((entry = cmpxchg(&head->first, old_entry, next)) != old_entry);
+	}
 
 	return entry;
 }
author
#4 lore raw

PATCH 4/5 llist, Return whether list is empty before adding in llist_add

In reply to Huang Ying

This is needed by irq_work. And because list_add_xxx functions are inline, this can be optimized out if not needed by callers.

Cc Mathieu Desnoyers <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 include/linux/llist.h |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
include/linux/llist.h +10 -2
@@ -148,8 +148,10 @@ static inline bool llist_empty(const str
  * llist_add - add a new entry
  * @new:	new entry to be added
  * @head:	the head for your lock-less list
+ *
+ * Return whether list is empty before adding.
  */
-static inline void llist_add(struct llist_node *new, struct llist_head *head)
+static inline bool llist_add(struct llist_node *new, struct llist_head *head)
 {
 	struct llist_node *entry, *old_entry;
 
@@ -164,6 +166,8 @@ static inline void llist_add(struct llis
 			break;
 		cpu_relax();
 	}
+
+	return old_entry == NULL;
 }
 
 /**
@@ -171,8 +175,10 @@ static inline void llist_add(struct llis
  * @new_first:	first entry in batch to be added
  * @new_last:	last entry in batch to be added
  * @head:	the head for your lock-less list
+ *
+ * Return whether list is empty before adding.
  */
-static inline void llist_add_batch(struct llist_node *new_first,
+static inline bool llist_add_batch(struct llist_node *new_first,
 				   struct llist_node *new_last,
 				   struct llist_head *head)
 {
@@ -189,6 +195,8 @@ static inline void llist_add_batch(struc
 			break;
 		cpu_relax();
 	}
+
+	return old_entry == NULL;
 }
 
 /**
author
#5 lore raw

PATCH 5/5 irq_work, Use llist in irq_work

In reply to Huang Ying

Use llist in irq_work instead of the lock-less linked list implementation in irq_work to avoid the code duplication.

Cc Peter Zijlstra <[email protected]>
---
 include/linux/irq_work.h |   15 ++++---
 kernel/irq_work.c        |   92 ++++++++++++++++-------------------------------
 2 files changed, 42 insertions(+), 65 deletions(-)
include/linux/irq_work.h +9 -6
@@ -1,20 +1,23 @@
 #ifndef _LINUX_IRQ_WORK_H
 #define _LINUX_IRQ_WORK_H
 
+#include <linux/llist.h>
+
 struct irq_work {
-	struct irq_work *next;
+	unsigned long flags;
+	struct llist_node llnode;
 	void (*func)(struct irq_work *);
 };
 
 static inline
-void init_irq_work(struct irq_work *entry, void (*func)(struct irq_work *))
+void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
 {
-	entry->next = NULL;
-	entry->func = func;
+	work->flags = 0;
+	work->func = func;
 }
 
-bool irq_work_queue(struct irq_work *entry);
+bool irq_work_queue(struct irq_work *work);
 void irq_work_run(void);
-void irq_work_sync(struct irq_work *entry);
+void irq_work_sync(struct irq_work *work);
 
 #endif /* _LINUX_IRQ_WORK_H */
kernel/irq_work.c +33 -59

175 lines not on this page · raw message

maintainer
#6 lore raw

[PATCH 6/5] llist: Add llist_next()

In reply to Huang Ying

Subject: llist: Add llist_next()
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 13:12:28 CEST 2011

So we don't have to expose the struct list_node members

---
 include/linux/llist.h |    5 +++++
 kernel/irq_work.c     |    2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/linux/llist.h +5 -0
Index: linux-2.6/include/linux/llist.h
===================================================================
@@ -144,6 +144,11 @@ static inline bool llist_empty(const str
 	return ACCESS_ONCE(head->first) == NULL;
 }
 
+static inline struct llist_node *llist_next(struct llist_node *node)
+{
+	return node->next;
+}
+
 /**
  * llist_add - add a new entry
  * @new:	new entry to be added
kernel/irq_work.c +1 -1
Index: linux-2.6/kernel/irq_work.c
===================================================================
@@ -110,7 +110,7 @@ void irq_work_run(void)
 	while (llnode != NULL) {
 		work = llist_entry(llnode, struct irq_work, llnode);
 
-		llnode = llnode->next;
+		llnode = llist_next(llnode);
 
 		/*
 		 * Clear the PENDING bit, after this point the @work
maintainer
#7 lore raw

[PATCH 7/5] sched: Convert to use llist

In reply to Huang Ying

Subject: sched: Convert to use llist
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 13:06:17 CEST 2011

Use the generic llist primitives..

---
 include/linux/sched.h |    3 ++-
 kernel/sched.c        |   48 ++++++++++--------------------------------------
 2 files changed, 12 insertions(+), 39 deletions(-)
include/linux/sched.h +2 -1
Index: linux-2.6/include/linux/sched.h
===================================================================
@@ -90,6 +90,7 @@ struct sched_param {
 #include <linux/task_io_accounting.h>
 #include <linux/latencytop.h>
 #include <linux/cred.h>
+#include <linux/llist.h>
 
 #include <asm/processor.h>
 
@@ -1225,7 +1226,7 @@ struct task_struct {
 	unsigned int ptrace;
 
 #ifdef CONFIG_SMP
-	struct task_struct *wake_entry;
+	struct llist_node wake_entry;
 	int on_cpu;
 #endif
 	int on_rq;
kernel/sched.c +10 -38

84 lines not on this page · raw message

maintainer
#8 lore raw

[PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

In reply to Huang Ying

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

 $ for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance > $i; done
 $ echo 4096 32000 64 128 > /proc/sys/kernel/sem
 $ ./sembench -t 2048 -w 1900 -o 0

Pre:

run time 30 seconds 778936 worker burns per second run time 30 seconds 912190 worker burns per second run time 30 seconds 817506 worker burns per second run time 30 seconds 830870 worker burns per second run time 30 seconds 845056 worker burns per second

Post:

run time 30 seconds 905920 worker burns per second run time 30 seconds 849046 worker burns per second run time 30 seconds 886286 worker burns per second run time 30 seconds 822320 worker burns per second run time 30 seconds 900283 worker burns per second

---
 include/linux/llist.h |    3 ---
 1 file changed, 3 deletions(-)
include/linux/llist.h +0 -3
Index: linux-2.6/include/linux/llist.h
===================================================================
@@ -169,7 +169,6 @@ static inline bool llist_add(struct llis
 		entry = cmpxchg(&head->first, old_entry, new);
 		if (entry == old_entry)
 			break;
-		cpu_relax();
 	}
 
 	return old_entry == NULL;
@@ -198,7 +197,6 @@ static inline bool llist_add_batch(struc
 		entry = cmpxchg(&head->first, old_entry, new_first);
 		if (entry == old_entry)
 			break;
-		cpu_relax();
 	}
 
 	return old_entry == NULL;
@@ -233,7 +231,6 @@ static inline struct llist_node *llist_d
 		entry = cmpxchg(&head->first, old_entry, next);
 		if (entry == old_entry)
 			break;
-		cpu_relax();
 	}
 
 	return entry;
#9 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 6 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

May still save power. however:

include/linux/llist.h static inline bool llist_add(struct llis · line 172

Quoted 4 lines
include/linux/llist.h +0 -1
 		entry = cmpxchg(&head->first, old_entry, new);
 		if (entry == old_entry)
 			break;
-		cpu_relax();

You need at least a barrier() then, otherwise the compiler could change the memory order in the loop.

-Andi

maintainer
#10 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 10 lines · Andi Kleen
Quoted 6 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

May still save power. however:

Quoted 7 lines

include/linux/llist.h static inline bool llist_add(struct llis · line 172

Quoted 4 lines
include/linux/llist.h +0 -1
 		entry = cmpxchg(&head->first, old_entry, new);
 		if (entry == old_entry)
 			break;
-		cpu_relax();

You need at least a barrier() then, otherwise the compiler could change the memory order in the loop.

the cmpxchg is a full memory barrier and compiler barrier.

#11 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

In reply to Andi Kleen
Quoted 9 lines · * Andi Kleen ([email protected]) wrote:
Quoted 6 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

May still save power.

Looking at kernel/spinlock.c:

void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
{
[...]

                while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
                        arch_##op##_relax(&lock->raw_lock); \

so basically, in typical locking primitives (spinlock), it looks like lower power consumption is preferred over getting the raw maximal performance in fully contented scenarios.

So what is the rationale for making those lock-less lists retry scheme different from spinlocks here ?

Thanks,

Mathieu

Signature · 4 lines
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
maintainer
#12 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 16 lines · Mathieu Desnoyers
Quoted 9 lines · * Andi Kleen ([email protected]) wrote:
Quoted 6 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra <[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

May still save power.

Looking at kernel/spinlock.c:

void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
{
[...]

Quoted 6 lines
                while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\
                        arch_##op##_relax(&lock->raw_lock); \

so basically, in typical locking primitives (spinlock), it looks like lower power consumption is preferred over getting the raw maximal performance in fully contented scenarios.

Who says its about power consumption? That was a baseless claim made by Andi which you propagate as a truth. Typically PAUSE is too short to really save any power and the only gain of having it in loops is to provide a window where another core on the cache domain can have a go.

If power consumption would be the prime concern Intel should fix their damn mwait implementation so we can use that for locks. Local spinners + mwait would give a very power efficient 'spin'-lock.

Quoted 2 lines

So what is the rationale for making those lock-less lists retry scheme different from spinlocks here ?

PAUSE should help on the medium contended case (it would be pointless on heavy contention), but hurt the lightly contended case. We have all kinds of contention spinlocks in the kernel, but we don't as of yet have very contended llist users in the kernel.

Furthermore, I would argue we should avoid growing them, significantly contended atomic ops are bad, use a different scheme.

maintainer
#13 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

In reply to Mathieu Desnoyers
Quoted 2 lines · Peter Zijlstra

Furthermore, I would argue we should avoid growing them, significantly contended atomic ops are bad, use a different scheme.

To clarify, plain cmpxchg loops are unfair and unbounded in completion time, and we should therefore avoid any sort of medium/high contention. If you get into that situation you're doing it wrong.

#14 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

In reply to Mathieu Desnoyers
Quoted 2 lines

so basically, in typical locking primitives (spinlock), it looks like lower power consumption is preferred over getting the raw maximal

It's not only power, its:
- Allow the other siblings make more progress on SMT
- Do some backoff to stress the interconnect less (this is important on >2S):
A tight loop which constantly writes is a extremly stressfull pattern.
- Save some power by allowing the CPU to do more clock gating

-Andi

maintainer
#15 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 8 lines · Andi Kleen
Quoted 2 lines

so basically, in typical locking primitives (spinlock), it looks like lower power consumption is preferred over getting the raw maximal

It's not only power, its:
- Allow the other siblings make more progress on SMT
- Do some backoff to stress the interconnect less (this is important on >2S):
A tight loop which constantly writes is a extremly stressfull pattern.
- Save some power by allowing the CPU to do more clock gating

If you're hitting a cmpxchg hard enough for any of those to make a difference you're doing it wrong.

#16 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

In reply to Peter Zijlstra
Quoted 10 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra<[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

  $ for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance>  $i; done
  $ echo 4096 32000 64 128>  /proc/sys/kernel/sem
  $ ./sembench -t 2048 -w 1900 -o 0

We hyperthreading enabled, and were all threads loaded? cpu_relax allows the other thread to make more progress while the spinner relaxes.

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#17 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 7 lines · Avi Kivity
Quoted 6 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra<[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

Quoted 7 lines
Quoted 4 lines
  $ for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance>  $i; done
  $ echo 4096 32000 64 128>  /proc/sys/kernel/sem
  $ ./sembench -t 2048 -w 1900 -o 0

We hyperthreading enabled, and were all threads loaded? cpu_relax allows the other thread to make more progress while the spinner relaxes.

Yeah, with HT enabled, the benchmark runs 2048 tasks and does 1900 task bulk wakeups or so. Forgot the details, but it basically stresses the sleep+wakeup paths like nobodies business.

#18 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Peter Zijlstra

Subject: llist: Remove cpu_relax() usage in cmpxchg loops
From: Peter Zijlstra<[email protected]>
Date: Mon Sep 12 15:50:49 CEST 2011

Initial benchmarks show they're a net loss (2 socket wsm):

   $ for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance>   $i; done
   $ echo 4096 32000 64 128>   /proc/sys/kernel/sem
   $ ./sembench -t 2048 -w 1900 -o 0
Quoted 6 lines
Quoted 2 lines

We hyperthreading enabled, and were all threads loaded? cpu_relax allows the other thread to make more progress while the spinner relaxes.

Yeah, with HT enabled, the benchmark runs 2048 tasks and does 1900 task bulk wakeups or so. Forgot the details, but it basically stresses the sleep+wakeup paths like nobodies business.

Ok.

Another issue is that hypervisors use PAUSE to detect a spinning guest and issue a directed yield to another vcpu. But for cmpxchg loops, the "spinner" would just commit on the next loop, no? So I think there's no objection from that front.

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#19 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 4 lines · Avi Kivity

Another issue is that hypervisors use PAUSE to detect a spinning guest and issue a directed yield to another vcpu. But for cmpxchg loops, the "spinner" would just commit on the next loop, no? So I think there's no objection from that front.

Right, we shouldn't ever spend a significant amount spinning on a cmpxchg. If we do we need to fix that instead.

#20 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Avi Kivity

Another issue is that hypervisors use PAUSE to detect a spinning guest and issue a directed yield to another vcpu. But for cmpxchg loops, the "spinner" would just commit on the next loop, no? So I think there's no objection from that front.

Right, we shouldn't ever spend a significant amount spinning on a cmpxchg. If we do we need to fix that instead.

I hate arguing while agreeing, but the issue isn't that we don't spend a significant time spinning, but that there is no owner. Should the other cpu go away, we just pick up a new copy of oldval and complete the transaction.

With spinlocks, even if you hold it for just a single guest cycle, the situation is different. If the vcpu that holds the spinlock is preempted, the spinner is forced to spin until the owner is rescheduled.

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#21 lore raw

Re: [PATCH 8/5] llist: Remove cpu_relax() usage in cmpxchg loops

Quoted 5 lines · Avi Kivity

I hate arguing while agreeing, but the issue isn't that we don't spend a significant time spinning, but that there is no owner. Should the other cpu go away, we just pick up a new copy of oldval and complete the transaction.

Ah, ok. Yes that too ;-)