Skip to contentSkip to conversation

Lock-less list

PATCH In review Huang Ying 11 participants 25 messages Jan 17, 2011 – Jan 21, 2011

Subsystems (11)
Networking x86 PowerPC Library code +7 more subsystems
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

cover Lock-less list

v10:

- Rebased on latest Linus' tree.
- Revise ARCH_HAVE_NMI_SAFE_CMPXCHG definition for SPARC32 per arch maintainer's comments.

v9:

- Split out lock-less allocator, will repost allocator with its user in another patchset.
- Use lock-less list in irq_work and replace net/rds/xlist.h

v8:

- Rebased on mmotm 2010-12-02

v7:

- Revise ARCH_HAVE_NMI_SAFE_CMPXCHG definition for some architectures according to architecture maitainers' comments.
- Remove spin_trylock_irqsave based fallback for lockless memory allocator, because it does not work for !CONFIG_SMP and is not likely to be used.
- Make lockless memory allocator and list does not depend on ARCH_HAVE_NMI_SAFE_CMPXCHG. Instead, require the user to depend on it when needed. And BUG_ON(in_nmi()) is added in necessary place to prevent silent race.

v6:

- Revise ARCH_HAVE_NMI_SAFE_CMPXCHG definition for some architectures according to architecture maitainers' comments.

v5:

- Add ARCH_HAVE_NMI_SAFE_CMPXCHG
- Add spin_trylock_irqsave based fallback in lockless memory allocator if ARCH_HAVE_NMI_SAFE_CMPXCHG=n
- Make lockless list depends on ARCH_HAVE_NMI_SAFE_CMPXCHG

v4:

- Split from APEI patchset
- Update patch description and comments according to ML comments

v3:

- Rework lockless memory allocator and list according to ML comments

[PATCH -v10 1/4] Add Kconfig option ARCH_HAVE_NMI_SAFE_CMPXCHG [PATCH -v10 2/4] lib, Add lock-less NULL terminated single list [PATCH -v10 3/4] irq_work, Use llist in irq_work
[PATCH -v10 4/4] net, rds, Replace xlist in net/rds/xlist.h with llist

author
#1 lore raw

PATCH 1/4 Add Kconfig option ARCH_HAVE_NMI_SAFE_CMPXCHG

cmpxchg() is widely used by lockless code, including NMI-safe lockless code. But on some architectures, the cmpxchg() implementation is not NMI-safe, on these architectures the lockless code may need to a spin_trylock_irqsave() based implementation.

This patch adds a Kconfig option: ARCH_HAVE_NMI_SAFE_CMPXCHG, so that NMI-safe lockless code can depend on it or provide different implementation according to it.

On many architectures, cmpxchg is only NMI-safe for several specific operand sizes. So, ARCH_HAVE_NMI_SAFE_CMPXCHG define in this patch only guarantees cmpxchg is NMI-safe for sizeof(unsigned long).

CC Richard Henderson <[email protected]>
CC Russell King <[email protected]>
CC Mikael Starvik <[email protected]>
CC David Howells <[email protected]>
CC Yoshinori Sato <[email protected]>
CC Tony Luck <[email protected]>
CC Hirokazu Takata <[email protected]>
CC Geert Uytterhoeven <[email protected]>
CC Michal Simek <[email protected]>
CC Ralf Baechle <[email protected]>
CC Kyle McMartin <[email protected]>
CC Martin Schwidefsky <[email protected]>
CC Chen Liqin <[email protected]>
CC "David S. Miller" <[email protected]>
CC Ingo Molnar <[email protected]>
CC Chris Zankel <[email protected]>
---
 arch/Kconfig         |    3 +++
 arch/alpha/Kconfig   |    1 +
 arch/avr32/Kconfig   |    1 +
 arch/frv/Kconfig     |    1 +
 arch/ia64/Kconfig    |    1 +
 arch/m68k/Kconfig    |    1 +
 arch/parisc/Kconfig  |    1 +
 arch/powerpc/Kconfig |    1 +
 arch/s390/Kconfig    |    1 +
 arch/sh/Kconfig      |    1 +
 arch/sparc/Kconfig   |    1 +
 arch/tile/Kconfig    |    1 +
 arch/x86/Kconfig     |    1 +
 13 files changed, 15 insertions(+)
arch/Kconfig +3 -0
@@ -178,4 +178,7 @@ config HAVE_ARCH_JUMP_LABEL
 config HAVE_ARCH_MUTEX_CPU_RELAX
 	bool
 
+config ARCH_HAVE_NMI_SAFE_CMPXCHG
+	bool
+
 source "kernel/gcov/Kconfig"
arch/alpha/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ALPHA
 	select HAVE_SYSCALL_WRAPPERS
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select HAVE_DMA_ATTRS
 	help
 	  The Alpha is a 64-bit general-purpose processor designed and
arch/avr32/Kconfig +1 -0
@@ -6,6 +6,7 @@ config AVR32
 	select HAVE_CLK
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
 	  designed for cost-sensitive embedded applications, with particular
arch/frv/Kconfig +1 -0
@@ -5,6 +5,7 @@ config FRV
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 
 config ZONE_DMA
 	bool
arch/ia64/Kconfig +1 -0
@@ -22,6 +22,7 @@ config IA64
 	select HAVE_KVM
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_DMA_API_DEBUG
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/m68k/Kconfig +1 -0
@@ -4,6 +4,7 @@ config M68K
 	select HAVE_AOUT
 	select HAVE_IDE
 	select GENERIC_ATOMIC64
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS
 
 config MMU
 	bool
arch/parisc/Kconfig +1 -0
@@ -11,6 +11,7 @@ config PARISC
 	select BUG
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_ATOMIC64 if !64BIT
 	select GENERIC_HARDIRQS_NO__DO_IRQ
 	help
arch/powerpc/Kconfig +1 -0
@@ -141,6 +141,7 @@ config PPC
 	select GENERIC_ATOMIC64 if PPC32
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_HW_BREAKPOINT if PERF_EVENTS && PPC_BOOK3S_64
 
arch/s390/Kconfig +1 -0
@@ -81,6 +81,7 @@ config S390
 	select INIT_ALL_POSSIBLE
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select HAVE_KERNEL_GZIP
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_LZMA
arch/sh/Kconfig +1 -0
@@ -11,6 +11,7 @@ config SUPERH
 	select HAVE_DMA_ATTRS
 	select HAVE_IRQ_WORK
 	select HAVE_PERF_EVENTS
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select PERF_USE_VMALLOC
 	select HAVE_KERNEL_GZIP
 	select HAVE_KERNEL_BZIP2
arch/sparc/Kconfig +1 -0
@@ -50,6 +50,7 @@ config SPARC64
 	select RTC_DRV_STARFIRE
 	select HAVE_PERF_EVENTS
 	select PERF_USE_VMALLOC
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 
 config ARCH_DEFCONFIG
 	string
arch/tile/Kconfig +1 -0
@@ -104,6 +104,7 @@ config TILE
 	select GENERIC_FIND_NEXT_BIT
 	select USE_GENERIC_SMP_HELPERS
 	select CC_OPTIMIZE_FOR_SIZE
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 
 # FIXME: investigate whether we need/want these options.
 #	select HAVE_IOREMAP_PROT
arch/x86/Kconfig +1 -0
@@ -23,6 +23,7 @@ config X86
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
 	select HAVE_IRQ_WORK
+	select ARCH_HAVE_NMI_SAFE_CMPXCHG if !M386
 	select HAVE_IOREMAP_PROT
 	select HAVE_KPROBES
 	select HAVE_MEMBLOCK
author
#2 lore raw

PATCH 2/4 lib, Add lock-less NULL terminated single list

In reply to Huang Ying

Cmpxchg is used to implement adding new entry to the list, deleting all entries from the list, deleting first entry of the list and some other operations.

Because this is a single list, so the tail can not be accessed in O(1).

If there are multiple producers and multiple consumers, llist_add can be used in producers and llist_del_all can be used in consumers. They can work simultaneously without lock. But llist_del_first can not be used here. Because llist_del_first depends on list->first->next does not changed if list->first is not changed during its operation, but llist_del_first, llist_add, llist_add sequence in another consumer may violate that.

If there are multiple producers and one consumer, llist_add can be used in producers and llist_del_all or llist_del_first can be used in the consumer.

The list entries deleted via llist_del_all can be traversed with traversing function such as llist_for_each etc. But the list entries can not be traversed safely before deleted from the list without proper synchronization with the list consumers.

The basic atomic operation of this list is cmpxchg on long. On architectures that don't have NMI-safe cmpxchg implementation, the list can NOT be used in NMI handler. So code uses the list in NMI handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.

---
 include/linux/llist.h |   99 +++++++++++++++++++++++++++++++++++++++++
 lib/Kconfig           |    3 +
 lib/Makefile          |    2 
 lib/llist.c           |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 223 insertions(+)
 create mode 100644 include/linux/llist.h
 create mode 100644 lib/llist.c
include/linux/llist.h new file +99 -0
@@ -0,0 +1,99 @@
+#ifndef LLIST_H
+#define LLIST_H
+/*
+ * Lock-less NULL terminated single linked list
+ *
+ * If there are multiple producers and multiple consumers, llist_add
+ * can be used in producers and llist_del_all can be used in
+ * consumers.  They can work simultaneously without lock.  But
+ * llist_del_first can not be used here.  Because llist_del_first
+ * depends on list->first->next does not changed if list->first is not
+ * changed during its operation, but llist_del_first, llist_add,
+ * llist_add sequence in another consumer may violate that.
+ *
+ * If there are multiple producers and one consumer, llist_add can be
+ * used in producers and llist_del_all or llist_del_first can be used
+ * in the consumer.
+ *
+ * The list entries deleted via llist_del_all can be traversed with
+ * traversing function such as llist_for_each etc.  But the list
+ * entries can not be traversed safely before deleted from the list
+ * without proper synchronization with the list consumers.
+ *
+ * The basic atomic operation of this list is cmpxchg on long.  On
+ * architectures that don't have NMI-safe cmpxchg implementation, the
+ * list can NOT be used in NMI handler.  So code uses the list in NMI
+ * handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.
+ */
+
+struct llist_head {
+	struct llist_node *first;
+};
+
+struct llist_node {
+	struct llist_node *next;
+};
+
+#define LLIST_HEAD_INIT(name)	{ NULL }
+#define LLIST_HEAD(name)	struct llist_head name = LLIST_HEAD_INIT(name)
+
+/**
+ * init_llist_head - initialize lock-less list head
+ * @head:	the head for your lock-less list
+ */
+static inline void init_llist_head(struct llist_head *list)
+{
+	list->first = NULL;
+}
+
+/**
+ * llist_entry - get the struct of this entry
+ * @ptr:	the &struct llist_node pointer.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the llist_node within the struct.
+ */
+#define llist_entry(ptr, type, member)		\
+	container_of(ptr, type, member)
+
+/**
+ * llist_for_each - iterate over some entries of a lock-less list
+ * @pos:	the &struct llist_node to use as a loop cursor
+ * @node:	the first entry of deleted list entries
+ *
+ * In general, some entries of the lock-less list can be traversed
+ * safely only after being deleted from list, so start with an entry
+ * instead of list head.
+ */
+#define llist_for_each(pos, node)			\
+	for (pos = (node); pos; pos = pos->next)
+
+/**
+ * llist_for_each_entry - iterate over some entries of lock-less list of given type
+ * @pos:	the type * to use as a loop cursor.
+ * @node:	the fist entry of deleted list entries.
+ * @member:	the name of the llist_node with the struct.
+ *
+ * In general, some entries of the lock-less list can be traversed
+ * safely only after being removed from list, so start with an entry
+ * instead of list head.
+ */
+#define llist_for_each_entry(pos, node, member)				\
+	for (pos = llist_entry((node), typeof(*pos), member);		\
+	     &pos->member != NULL;					\
+	     pos = llist_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * llist_empty - tests whether a lock-less list is empty
+ * @head:	the list to test
+ */
+static inline int llist_empty(const struct llist_head *head)
+{
+	return head->first == NULL;
+}
+
+void llist_add(struct llist_node *new, struct llist_head *head);
+void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
+		     struct llist_head *head);
+struct llist_node *llist_del_first(struct llist_head *head);
+struct llist_node *llist_del_all(struct llist_head *head);
+#endif /* LLIST_H */
lib/Kconfig +3 -0
@@ -219,4 +219,7 @@ config LRU_CACHE
 config AVERAGE
 	bool
 
+config LLIST
+	bool
+
 endmenu
lib/Makefile +2 -0
@@ -110,6 +110,8 @@ obj-$(CONFIG_ATOMIC64_SELFTEST) += atomi
 
 obj-$(CONFIG_AVERAGE) += average.o
 
+obj-$(CONFIG_LLIST) += llist.o
+
 hostprogs-y	:= gen_crc32table
 clean-files	:= crc32table.h
 
lib/llist.c new file +119 -0

119 lines not on this page · raw message

author
#3 lore raw

PATCH 3/4 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 ++++---
 init/Kconfig             |    1 
 kernel/irq_work.c        |   92 ++++++++++++++++++-----------------------------
 3 files changed, 47 insertions(+), 61 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 */
init/Kconfig +1 -0
@@ -27,6 +27,7 @@ config HAVE_IRQ_WORK
 config IRQ_WORK
 	bool
 	depends on HAVE_IRQ_WORK
+	select LLIST
 
 menu "General setup"
 
kernel/irq_work.c +37 -55

170 lines not on this page · raw message

author
#4 lore raw

PATCH 4/4 net, rds, Replace xlist in net/rds/xlist.h with llist

In reply to Huang Ying

The functionality of xlist and llist is almost same. This patch replace xlist with llist to avoid code duplication.

Known issues: don't know how to test this, need special hardware?

---
 net/rds/Kconfig   |    1 
 net/rds/ib_rdma.c |  112 ++++++++++++++++++++++++------------------------------
 net/rds/xlist.h   |   80 --------------------------------------
 3 files changed, 52 insertions(+), 141 deletions(-)
 delete mode 100644 net/rds/xlist.h
net/rds/Kconfig +1 -0
@@ -9,6 +9,7 @@ config RDS
 
 config RDS_RDMA
 	tristate "RDS over Infiniband and iWARP"
+	select LLIST
 	depends on RDS && INFINIBAND && INFINIBAND_ADDR_TRANS
 	---help---
 	  Allow RDS to use Infiniband and iWARP as a transport.
net/rds/ib_rdma.c +51 -61

214 lines not on this page · raw message

net/rds/xlist.h deleted +0 -80

80 lines not on this page · raw message

maintainer
#5 lore raw
In reply to Huang Ying

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing. And that required an nmi-context memory allocator. And that required a "lockless" list implementation.

Yes?

If so, what happened to all of that? I assume that the facilities which this patch series adds will be used for "hardware error reporting"?

author
#6 lore raw
Quoted 7 lines · Andrew Morton

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing. And that required an nmi-context memory allocator. And that required a "lockless" list implementation.

Yes?

Yes. But the "lockless" list implementation is general, it can be used by other part of kernel too, such as irq_work and xlist in net/rds/xlist.h in the patchset.

Best Regards,
Huang Ying

maintainer
#7 lore raw
Quoted 7 lines · On Thu, 20 Jan 2011 08:45:58 +0800 Huang Ying <[email protected]> wrote:
Quoted 6 lines · Andrew Morton

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing. And that required an nmi-context memory allocator. And that required a "lockless" list implementation.

Quoted 5 lines
Quoted 1 line

Yes?

Yes. But the "lockless" list implementation is general, it can be used by other part of kernel too, such as irq_work and xlist in net/rds/xlist.h in the patchset.

Well. Lots of things are general but that doesn't mean we toss them into the kernel when we already have plenty of infrastructure to handle that sort of thing.

otoh, hoisting xlist.h out of net/rds and making it generally available is a good thing.

otooh, net/rds/ probably didn't need xlist at all and could have used existing general code.

So... I'd say that unless and until the NMI-context allocator is merged, the case for merging the lockless list code is a bit marginal? Or have you identified other code sites which could use llist and which would gain some benefit from migrating?

author
#8 lore raw
Quoted 20 lines · Andrew Morton
Quoted 7 lines · On Thu, 20 Jan 2011 08:45:58 +0800 Huang Ying <[email protected]> wrote:
Quoted 6 lines · Andrew Morton

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing. And that required an nmi-context memory allocator. And that required a "lockless" list implementation.

Quoted 5 lines
Quoted 1 line

Yes?

Yes. But the "lockless" list implementation is general, it can be used by other part of kernel too, such as irq_work and xlist in net/rds/xlist.h in the patchset.

Well. Lots of things are general but that doesn't mean we toss them into the kernel when we already have plenty of infrastructure to handle that sort of thing.

Quoted 7 lines

otoh, hoisting xlist.h out of net/rds and making it generally available is a good thing.

otooh, net/rds/ probably didn't need xlist at all and could have used existing general code.

From commit description of xlist, it seems that xlist is created for

some performance issue.

commit 6fa70da6081bbcf948801fd5ee0be4d222298a43

Author: Chris Mason <[email protected]>
Date:   Fri Jun 11 11:17:59 2010 -0700

rds: recycle FMRs through lockless lists

FRM allocation and recycling is performance critical and fairly lock intensive. The current code has a per connection lock that all processes bang on and it becomes a major bottleneck on large systems.

This changes things to use a number of cmpxchg based lists instead, allowing us to go through the whole FMR lifecycle without locking inside RDS.

[snip]

So general list may be not good for them.

Quoted 2 lines

So... I'd say that unless and until the NMI-context allocator is merged, the case for merging the lockless list code is a bit marginal?

In fact, lockless allocator is not really depends on llist, it just depends on the ARCH_HAVE_NMI_SAFE_CMPXCHG patch in the patchset.

Quoted 2 lines

Or have you identified other code sites which could use llist and which would gain some benefit from migrating?

The llist will be used by APEI (ACPI Platform Error Interface, that is, an ACPI-based "hardware error reporting" thing). It may be used by other hardware error reporting mechanisms too, which involves NMI or NMI-like notification method.

Best Regards,
Huang Ying

#9 lore raw
In reply to Andrew Morton
Quoted 23 lines · Andrew Morton
Quoted 7 lines · On Thu, 20 Jan 2011 08:45:58 +0800 Huang Ying <[email protected]> wrote:
Quoted 6 lines · Andrew Morton

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing. And that required an nmi-context memory allocator. And that required a "lockless" list implementation.

Quoted 5 lines
Quoted 1 line

Yes?

Yes. But the "lockless" list implementation is general, it can be used by other part of kernel too, such as irq_work and xlist in net/rds/xlist.h in the patchset.

Well. Lots of things are general but that doesn't mean we toss them into the kernel when we already have plenty of infrastructure to handle that sort of thing.

otoh, hoisting xlist.h out of net/rds and making it generally available is a good thing.

Quoted 7 lines

otooh, net/rds/ probably didn't need xlist at all and could have used existing general code.

So... I'd say that unless and until the NMI-context allocator is merged, the case for merging the lockless list code is a bit marginal? Or have you identified other code sites which could use llist and which would gain some benefit from migrating?

In fact, I have a patch ready and waiting to revert the whole irq_work stuff, that too seems to be a superfluous generalization.

#10 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 26 lines · Andrew Morton
Quoted 7 lines · On Thu, 20 Jan 2011 08:45:58 +0800 Huang Ying <[email protected]> wrote:
Quoted 6 lines · Andrew Morton

I'm trying to remember why we're talking about this.

You had an ACPI-based "hardware error reporting" thing.  And that required an nmi-context memory allocator.  And that required a "lockless" list implementation.

Quoted 5 lines
Quoted 1 line

Yes?

Yes.  But the "lockless" list implementation is general, it can be used by other part of kernel too,  such as irq_work and xlist in net/rds/xlist.h in the patchset.

Well.  Lots of things are general but that doesn't mean we toss them into the kernel when we already have plenty of infrastructure to handle that sort of thing.

otoh, hoisting xlist.h out of net/rds and making it generally available is a good thing.

otooh, net/rds/ probably didn't need xlist at all and could have used existing general code.

Quoted 7 lines
Quoted 4 lines

So...  I'd say that unless and until the NMI-context allocator is merged, the case for merging the lockless list code is a bit marginal? Or have you identified other code sites which could use llist and which would gain some benefit from migrating?

In fact, I have a patch ready and waiting to revert the whole irq_work stuff, that too seems to be a superfluous generalization.

What do you plan to replace irq_work? I plan to use it in APEI NMI handler and MCE handler.

Best Regards,
Huang Ying

#11 lore raw
Quoted 6 lines · huang ying
Quoted 3 lines

In fact, I have a patch ready and waiting to revert the whole irq_work stuff, that too seems to be a superfluous generalization.

What do you plan to replace irq_work? I plan to use it in APEI NMI handler and MCE handler.

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

As it stands now you're simply submitting infrastructure without any users, and we all know the RAS thing isn't settled, so those users might never come..

#12 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · huang ying
Quoted 3 lines

In fact, I have a patch ready and waiting to revert the whole irq_work stuff, that too seems to be a superfluous generalization.

Quoted 7 lines
Quoted 2 lines

What do you plan to replace irq_work?  I plan to use it in APEI NMI handler and MCE handler.

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure. As far as I know, Linus and Andrew suggest to use printk for hardware error reporting. And now, I just try to write APEI driver and reporting hardware error with printk. Is it acceptable? Do you have some other idea about hardware error reporting?

Quoted 3 lines

As it stands now you're simply submitting infrastructure without any users, and we all know the RAS thing isn't settled, so those users might never come..

As for llist, I just want to send some code that is useful for not only RAS users. If it has not any user except APEI driver, I will move it into APEI driver code.

Best Regards,
Huang Ying

#13 lore raw
Quoted 9 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure. As far as I know, Linus and Andrew suggest to use printk for hardware error reporting. And now, I just try to write APEI driver and reporting hardware error with printk. Is it acceptable? Do you have some other idea about hardware error reporting?

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

It's somewhat annoying that you simply ignore repeated feedback and feign ignorance. Reminds me of someone :-)

Ingo

#14 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

Quoted 7 lines
Quoted 4 lines

I am not sending hardware error reporting infrastructure.  As far as I know, Linus and Andrew suggest to use printk for hardware error reporting.  And now, I just try to write APEI driver and reporting hardware error with printk.  Is it acceptable?  Do you have some other idea about hardware error reporting?

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Best Regards,
Huang Ying

#15 lore raw
Quoted 14 lines · huang ying
Quoted 13 lines · Ingo Molnar
Quoted 9 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure.  As far as I know, Linus and Andrew suggest to use printk for hardware error reporting.  And now, I just try to write APEI driver and reporting hardware error with printk.  Is it acceptable?  Do you have some other idea about hardware error reporting?

Quoted 7 lines
Quoted 2 lines

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Of course, that's why the upstream EDAC code uses printk too. In fact it does all sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog method of pushing all decoding to user-space is fundamentally flawed.

So yes, printk is the primary output channel and having a readable printk output pretty much overrides any other concern.

But that is not what you are doing. I get the impression that you are using printk as an _excuse_ to not have to work with the RAS people and run some parallel framework so that you do not have to work with them or listen to them. It is rather counter-productive. Working together is useful.

Thanks,

Ingo

#16 lore raw
Quoted 29 lines · Ingo Molnar
Quoted 14 lines · huang ying
Quoted 13 lines · Ingo Molnar
Quoted 9 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure.  As far as I know, Linus and Andrew suggest to use printk for hardware error reporting.  And now, I just try to write APEI driver and reporting hardware error with printk.  Is it acceptable?  Do you have some other idea about hardware error reporting?

Quoted 7 lines
Quoted 2 lines

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Of course, that's why the upstream EDAC code uses printk too. In fact it does all sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog method of pushing all decoding to user-space is fundamentally flawed.

Quoted 7 lines

So yes, printk is the primary output channel and having a readable printk output pretty much overrides any other concern.

But that is not what you are doing. I get the impression that you are using printk as an _excuse_ to not have to work with the RAS people and run some parallel framework so that you do not have to work with them or listen to them. It is rather counter-productive. Working together is useful.

No. I am not working on some other hardware error reporting framework now. I just want to make printk works better for hardware error reporting. For example, printk is not NMI-safe yet, so I need lockless list and memory allocator to record the information in NMI handler and printk them later. And maybe in the future, we can make printk NMI safe with similar method. I think there is no contradiction between my work and other RAS people's work.

Best Regards,
Huang Ying

maintainer
#17 lore raw
In reply to Ingo Molnar

+ Tony.

Quoted 20 lines · Ingo Molnar
Quoted 17 lines · huang ying
Quoted 15 lines · Ingo Molnar
Quoted 9 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure.  As far as I know, Linus and Andrew suggest to use printk for hardware error reporting.  And now, I just try to write APEI driver and reporting hardware error with printk.  Is it acceptable?  Do you have some other idea about hardware error reporting?

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Quoted 8 lines
Quoted 4 lines

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Of course, that's why the upstream EDAC code uses printk too. In fact it does all sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog method of pushing all decoding to user-space is fundamentally flawed.

True story. And yet google folk still do that, unfortunately:
https://lkml.org/lkml/2011/1/10/419

I think printk should be used in the most cases, where the home user runs Linux on his machine and it freezes and when he tries to catch the MCA info, he simply collects serial console or with a persistent storage device in place, he reboots and then reads out the exact decoded error.

In the big data center, printk might not be that useful anymore and we might want to have structured log error data - still decoded, mind you, and properly formatted but sent to userspace over perf and then over the network or collected by a userspace daemon doing policy decisions and error trends evaluation. This is, I think, much saner approach than collecting hardware info from every machine and then using it to decode the errors. We still need a bunch of work in that direction though.

Quoted 7 lines

So yes, printk is the primary output channel and having a readable printk output pretty much overrides any other concern.

But that is not what you are doing. I get the impression that you are using printk as an _excuse_ to not have to work with the RAS people and run some parallel framework so that you do not have to work with them or listen to them. It is rather counter-productive. Working together is useful.

So yeah, let me reiterate what Andrew and Ingo said: I don't want to discuss the merits of all those cool lockless software thingies that could replace this and that and would be cool if someone used them. I'm only interested if they can help in a real-world use case - otherwise it's just a programming exercise.

Yeah, this all IMHO, of course :).

Signature · 2 lines
Regards/Gruss,
Boris.
#18 lore raw
Quoted 28 lines · Borislav Petkov

+ Tony.

Quoted 25 lines · Ingo Molnar
Quoted 21 lines · huang ying
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

Quoted 7 lines
Quoted 4 lines

I am not sending hardware error reporting infrastructure.  As far as I know, Linus and Andrew suggest to use printk for hardware error reporting.  And now, I just try to write APEI driver and reporting hardware error with printk.  Is it acceptable?  Do you have some other idea about hardware error reporting?

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Quoted 6 lines
Quoted 3 lines

Of course, that's why the upstream EDAC code uses printk too. In fact it does all sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog method of pushing all decoding to user-space is fundamentally flawed.

True story. And yet google folk still do that, unfortunately:
https://lkml.org/lkml/2011/1/10/419

I wouldnt worry about that too much - such uses are extremely isolated.

If we give RAS functionality that gives the limited capabilities of /dev/mcelog and much more then the migration path is clear towards the superior solution.

Thanks,

Ingo

#19 lore raw
Quoted 4 lines
Quoted 2 lines

True story. And yet google folk still do that, unfortunately:
https://lkml.org/lkml/2011/1/10/419

I wouldn't worry about that too much - such uses are extremely isolated.

Google is just one user - but they have (so I hear) a large number of machines.

I would hazard a guess that there are other users that feel the same way - i.e. users with a large number of machines that move onto new kernel versions from time to time.

These users want a stable kernel->user ABI - and Google has stated quite clearly that "printk" doesn't meet their need. I think that they would be happy with some other stable solution than mcelog, but we might as well ask for their input before imposing something on them.

Mike: would you like to join the conversation on how to report errors - or nominate someone else to represent the Google point of view?

-Tony

#20 lore raw
In reply to Ingo Molnar
Quoted 20 lines · Ingo Molnar
Quoted 17 lines · huang ying
Quoted 15 lines · Ingo Molnar
Quoted 9 lines · huang ying
Quoted 4 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and focus on your larger RAS picture, once you have consensus on that from all parties involved, then, and only then, does it make sense to submit everything, including infrastructure.

I am not sending hardware error reporting infrastructure. As far as I know, Linus and Andrew suggest to use printk for hardware error reporting. And now, I just try to write APEI driver and reporting hardware error with printk. Is it acceptable? Do you have some other idea about hardware error reporting?

Erm, how could you possible have missed the perf based RAS daemon work of Boris, which we've pointed out about half a dozen times already?

Quoted 8 lines
Quoted 4 lines

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Of course, that's why the upstream EDAC code uses printk too. In fact it does all sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog method of pushing all decoding to user-space is fundamentally flawed.

Geez, I don't know how to approach this preposition in a concise way :(
Processing machine checks in-kernel is just as flawed as relying on
/dev/mcelog alone IMO. I agree with you that relying on /dev/mcelog to get all of our error data out is flawed, but so is relying on an in-kernel "abstraction" of the data exposed from the hardware.

There are many different ways a system can fail such that an MCE isn't received and processed by the kernel. Sometimes the error is just too fatal to do anything useful. Errors like a NB buffer CRC error, a bus syncflood, or a cache hierarchy ECC error that was incorrectly propagated up through to the L1 (which may only have parity checking) can cause the kernel to fall over as the CPU is either cut off from the rest of the world or too confused to get anything right.

Getting at this information is still very worthwhile however, and I'm guessing that this is what the APEI bits are meant to be doing. You'll be seeing patches for Google firmware drivers that provide functionality along the same vein in the coming days (I'm still busy whitewashing and documenting them).

It's also very ignorant to assume that the kernel knows everything about the system and is capable of decoding errors to the satisfaction of userland. As Duncan Laurie pointed out (https://lkml.org/lkml/2011/1/11/390) we care about not only the physical address, but which stick and which dimm *chip* on the stick is having problems. In-kernel abstractions break down due to the following:

* The kernel couldn't possible know how my i2c busses are setup and
the SPD EEPROMs are related to the physical memory abstraction that the bios sets up for me. I don't know of any standard way to have the BIOS expose this sort of information to the operating system. This sort of layout changes between motherboard spins quite frequently as well, so good luck mapping it yourself in any generic way.

* The kernel couldn't know how to map SPD JEDEC Manufacturer ID,
Model part number and revision to anything useful about the chips themselves.

* The kernel also couldn't know how to communicate with the AMBs in
a meaningful way (if present).

At the end of the day, The only things I really care about are:

* I don't care if the kernel pre-processes the data it gets from the
hardware when there is an error. For most users, burping something out to the logs in decoded form is generally useful. It isn't for us.
* Don't ever put the kernel in a position where it will spam the
logs and wedge the system -- even if the hardware is wonky.
* Don't dummy the data such that I can't do the same calculations
with better visibility from userland.
* Don't ever enforce a reactive policy that can't be changed from
userland.
* I don't care whether the data comes from netlink, /dev/mcelog,
whiz-bang-sysfs uevent, or thingamaboo perfevents doohickie: as long as I get events that are both atomic+consistent and the ABI is maintained.

I've CCed Robert who owns our userland bits as he may have something to add.

That said, I'd love to have generic NMI-safe data-passing for improved debugability, regardless of this conflated bickering about RAS infrastructure :)

#21 lore raw

OOh ohh, can I jump in? As another of "those Google guys" who has been dealing with Linux's lack of solutions here for years....

Quoted 34 lines · Mike Waychison
Quoted 33 lines · Ingo Molnar
Quoted 29 lines · huang ying
Quoted 20 lines · Ingo Molnar
Quoted 8 lines · huang ying
Quoted 7 lines

But will all that stuff be accepted? Please stop sending infrastructure bits and
focus on your larger RAS picture, once you have consensus on that from all
parties involved, then, and only then, does it make sense to submit everything,
including infrastructure.

Quoted 8 lines

I am not sending hardware error reporting infrastructure.  As far as I know, Linus
and Andrew suggest to use printk for hardware error reporting.  And now, I just
try to write APEI driver and reporting hardware error with printk.  Is it
acceptable?  Do you have some other idea about hardware error reporting?

Quoted 3 lines

Erm, how could you possible have missed the perf based RAS daemon work of Boris,
which we've pointed out about half a dozen times already?

Even if there is some other hardware error reporting infrastructure such as perf based, I think we still need printk too. After all, as Linus pointed out, printk is the most popular error reporting mechanism so far. Do you think so?

Quoted 5 lines
Quoted 5 lines

Of course, that's why the upstream EDAC code uses printk too. In fact it does all
sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog
method of pushing all decoding to user-space is fundamentally flawed.

EDAC is fundamentally flawed and we don't use it any more. It strips off so much information that we can't actually figure out what happened to the level we want. We do it in userspace now.

Quoted 21 lines

Geez, I don't know how to approach this preposition in a concise way :( Processing machine checks in-kernel is just as flawed as relying on /dev/mcelog alone IMO.  I agree with you that relying on /dev/mcelog to get all of our error data out is flawed, but so is relying on an in-kernel "abstraction" of the data exposed from the hardware.

There are many different ways a system can fail such that an MCE isn't received and processed by the kernel.  Sometimes the error is just too fatal to do anything useful.  Errors like a NB buffer CRC error, a bus syncflood, or a cache hierarchy ECC error that was incorrectly propagated up through to the L1 (which may only have parity checking) can cause the kernel to fall over as the CPU is either cut off from the rest of the world or too confused to get anything right.

Getting at this information is still very worthwhile however, and I'm guessing that this is what the APEI bits are meant to be doing.  You'll be seeing patches for Google firmware drivers that provide functionality along the same vein in the coming days (I'm still busy whitewashing and documenting them).

Quoted 6 lines

It's also very ignorant to assume that the kernel knows everything about the system and is capable of decoding errors to the satisfaction of userland. As Duncan Laurie pointed out (https://lkml.org/lkml/2011/1/11/390) we care about not only the physical address, but which stick and which dimm *chip* on the stick is having problems.  In-kernel abstractions  break down due to the following:

This. Andi was trying to use DMI tables to decode physical address to DIMMs, but I'll tell you this: I have yet to see a platform that has THAT MUCH information in the DMI tables and have it be *correct*.

Quoted 15 lines

  * The kernel couldn't possible know how my i2c busses are setup and the SPD EEPROMs are related to the physical memory abstraction that the bios sets up for me.  I don't know of any standard way to have the BIOS expose this sort of information to the operating system.  This sort of layout changes between motherboard spins quite frequently as well, so good luck mapping it yourself in any generic way.

  * The kernel couldn't know how to map SPD JEDEC Manufacturer ID, Model part number and revision to anything useful about the chips themselves.

  * The kernel also couldn't know how to communicate with the AMBs in a meaningful way (if present).

Quoted 7 lines

At the end of the day,   The only things I really care about are:

  * I don't care if the kernel pre-processes the data it gets from the hardware when there is an error.  For most users, burping something out to the logs in decoded form is generally useful.  It isn't for us.
  * Don't ever put the kernel in a position where it will spam the logs and wedge the system -- even if the hardware is wonky.

I'll add to this - sometimes 100 MCEs/second is acceptable. The Kernel needs to not flake out under that.

Quoted 2 lines

  * Don't dummy the data such that I can't do the same calculations with better visibility from userland.

This. We do extensive analysis of data in userland.

Quoted 5 lines

  * Don't ever enforce a reactive policy that can't be changed from userland.
  * I don't care whether the data comes from netlink, /dev/mcelog, whiz-bang-sysfs uevent, or thingamaboo perfevents doohickie: as long as I get events that are both atomic+consistent and the ABI is maintained.

I've been asking for hardware events for ever. I seem to recall a proposal from IBM at OLS 2002 or 2003 where this was discussed. I wanted it then, and I still want it. But I don't just want MCEs. Why can I not use the same channel to get PCI errors or SATA errors or EDAC (non-MCE) errors.

I don't care what the channel is, so long as I can rate-limit (/dev/mcelog is pretty good at that) events and the events I read contain full details about what happened.

Quoted 11 lines

I've CCed Robert who owns our userland bits as he may have something to add.

That said, I'd love to have generic NMI-safe data-passing for improved debugability, regardless of this conflated bickering about RAS infrastructure :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

#22 lore raw
Quoted 9 lines · Tim Hockin
Quoted 5 lines
Quoted 5 lines

Of course, that's why the upstream EDAC code uses printk too. In fact it does all
sorts of in-kernel decoding to make the printk output more useful - the /dev/mcelog
method of pushing all decoding to user-space is fundamentally flawed.

EDAC is fundamentally flawed and we don't use it any more. It strips off so much information that we can't actually figure out what happened to the level we want. We do it in userspace now.

Well, you better make sure to tell me what information you need reported and I'll try to get it fixed :) Currently, we can decode all MCEs in the kernel and when the MCE is reporting a DRAM ECC error we can get you the chip select it resulted from with EDAC.

We can also get you the bank, row and column from which the error originates (could be added easily to amd64_edac.c).

[..]

Quoted 10 lines
Quoted 6 lines

It's also very ignorant to assume that the kernel knows everything about the system and is capable of decoding errors to the satisfaction of userland. As Duncan Laurie pointed out (https://lkml.org/lkml/2011/1/11/390) we care about not only the physical address, but which stick and which dimm *chip* on the stick is having problems.  In-kernel abstractions  break down due to the following:

This. Andi was trying to use DMI tables to decode physical address to DIMMs, but I'll tell you this: I have yet to see a platform that has THAT MUCH information in the DMI tables and have it be *correct*.

and yes, there's not a fool-proof and generic way to tell which chip select on the system points at which DIMM. And excuse me, but I really really think that reading i2c devices and decyphering SPD ROM info from them is still not the optimal solution - it should be easier and more transparent than that. But guess what, this might change...

Quoted 16 lines
Quoted 16 lines

  * The kernel couldn't possible know how my i2c busses are setup and the SPD EEPROMs are related to the physical memory abstraction that the bios sets up for me.  I don't know of any standard way to have the BIOS expose this sort of information to the operating system.  This sort of layout changes between motherboard spins quite frequently as well, so good luck mapping it yourself in any generic way.

  * The kernel couldn't know how to map SPD JEDEC Manufacturer ID, Model part number and revision to anything useful about the chips themselves.

  * The kernel also couldn't know how to communicate with the AMBs in a meaningful way (if present).

At the end of the day,   The only things I really care about are:

Quoted 8 lines
Quoted 5 lines

  * I don't care if the kernel pre-processes the data it gets from the hardware when there is an error.  For most users, burping something out to the logs in decoded form is generally useful.  It isn't for us.
  * Don't ever put the kernel in a position where it will spam the logs and wedge the system -- even if the hardware is wonky.

I'll add to this - sometimes 100 MCEs/second is acceptable. The Kernel needs to not flake out under that.

Yeah, we got that, you want error reporting to be configurable and not only over printk - we'll fix it.

Quoted 4 lines
Quoted 2 lines

  * Don't dummy the data such that I can't do the same calculations with better visibility from userland.

This. We do extensive analysis of data in userland.

Yeah, we want to put the MCE register info along with the decoded info. We don't want to dummy up the data - we want to make it more useful.

Quoted 12 lines
Quoted 5 lines

  * Don't ever enforce a reactive policy that can't be changed from userland.
  * I don't care whether the data comes from netlink, /dev/mcelog, whiz-bang-sysfs uevent, or thingamaboo perfevents doohickie: as long as I get events that are both atomic+consistent and the ABI is maintained.

I've been asking for hardware events for ever. I seem to recall a proposal from IBM at OLS 2002 or 2003 where this was discussed. I wanted it then, and I still want it. But I don't just want MCEs. Why can I not use the same channel to get PCI errors or SATA errors or EDAC (non-MCE) errors.

Quoted 3 lines

I don't care what the channel is, so long as I can rate-limit (/dev/mcelog is pretty good at that) events and the events I read contain full details about what happened.

Ok, makes sense.

Quoted 5 lines
Quoted 5 lines

I've CCed Robert who owns our userland bits as he may have something to add.

That said, I'd love to have generic NMI-safe data-passing for improved debugability, regardless of this conflated bickering about RAS infrastructure :)

Thanks for the suggestions, much appreciated.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#23 lore raw
In reply to Huang Ying

Hi Huang,

I just found out about your lockless linked-list implementation, it looks interesting. Paul McKenney and myself have created a similar implementation for userspace within the Userspace RCU project, you might want to have a look (it's LGPLv2.1).

One point about semantic: a singly-linked list for which you can either delete the first element or all the elements should probably be called a stack ? I'm therefore going to refer to "push/pop" in this email rather than "add/delete".

We've got two linked-list stack implementations in the userspace RCU tree:

One has wait-free push, and blocking pop. Useful if you can afford to block when you pop from the list. There is no restriction on the number of concurrent push/pop to/from the list. The code is at:

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/wfstack-static.h

The other has lock-free push and pop, no restriction on the number of concurrent push/pop, but uses a clever trick that ensures that the cmpxchg loop will never see a re-used pointer by using a RCU read-side to protect from memory reclaim. It therefore requires that the memory used for the list must only be freed after a RCU grace period. The code is at:

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/rculfstack-static.h

We could probably extend this to allow popping all stack entries in one go, but I haven't given it much thought.

We also have queue implementations (enqueue at head, dequeue at tail). The first has wait-free enqueue/blocking dequeue and the second has lock-free enqueue/dequeue. We use the wait-free enqueue/blocking dequeue queue to push RCU callbacks when call_rcu() is executed from real-time threads, and we then dequeue the callbacks to execute with a blocking thread. The lock-free enqueue/dequeue queue also needs a reference count on the "dummy" node it keeps in addition to use RCU to delay memory reclamation (see comments in the code).

wait-free enqueue/blocking dequeue:

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/wfqueue-static.h

lock-free enqueue/dequeue (beware, the refcounting makes the API less elegant than the other implementations):

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/rculfqueue-static.h

Hoping this might be helpful to you,

Mathieu

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

Hi, Mathieu,

Quoted 40 lines · Mathieu Desnoyers

Hi Huang,

I just found out about your lockless linked-list implementation, it looks interesting. Paul McKenney and myself have created a similar implementation for userspace within the Userspace RCU project, you might want to have a look (it's LGPLv2.1).

One point about semantic: a singly-linked list for which you can either delete the first element or all the elements should probably be called a stack ? I'm therefore going to refer to "push/pop" in this email rather than "add/delete".

We've got two linked-list stack implementations in the userspace RCU tree:

One has wait-free push, and blocking pop. Useful if you can afford to block when you pop from the list. There is no restriction on the number of concurrent push/pop to/from the list. The code is at:

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/wfstack-static.h

The other has lock-free push and pop, no restriction on the number of concurrent push/pop, but uses a clever trick that ensures that the cmpxchg loop will never see a re-used pointer by using a RCU read-side to protect from memory reclaim. It therefore requires that the memory used for the list must only be freed after a RCU grace period. The code is at:

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/rculfstack-static.h

We could probably extend this to allow popping all stack entries in one go, but I haven't given it much thought.

We also have queue implementations (enqueue at head, dequeue at tail). The first has wait-free enqueue/blocking dequeue and the second has lock-free enqueue/dequeue. We use the wait-free enqueue/blocking dequeue queue to push RCU callbacks when call_rcu() is executed from real-time threads, and we then dequeue the callbacks to execute with a blocking thread. The lock-free enqueue/dequeue queue also needs a reference count on the "dummy" node it keeps in addition to use RCU to delay memory reclamation (see comments in the code).

wait-free enqueue/blocking dequeue:

Quoted 8 lines

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/wfqueue-static.h

lock-free enqueue/dequeue (beware, the refcounting makes the API less elegant than the other implementations):

http://git.lttng.org/?p=userspace-rcu.git;a=blob;f=urcu/rculfqueue-static.h

Hoping this might be helpful to you,

Thanks! I will investigate your code!

Best Regards,
Huang Ying