llist, Make all llist functions inline
Subsystems (3)
PATCH 1/4 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
PATCH 2/4 llist, Define macro to check NMI safe cmpxchg
To make code cleaner and reduce code duplication. Thanks Peter Zijlstra for reminding.
--- 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 ); }
Re: [PATCH -mm 2/4] llist, Define macro to check NMI safe cmpxchg
Quoted 13 lines · * Huang Ying ([email protected]) wrote:
To make code cleaner and reduce code duplication. Thanks Peter Zijlstra for reminding.
Signed-off-by Huang Ying <[email protected]>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 struct llist_node { · line 74
Quoted 5 lines
include/linux/llist.h +2
-0@@ -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 ()
Does it have to be in caps ? And can it be turned into a static inline function ? I'm thinking about something close to might_sleep().
Thanks,
Mathieu
Quoted 51 lines
include/linux/llist.h +8
-12+#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 ); }
Signature · 4 lines
Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com
PATCH 3/4 llist, Move cpu_relax after cmpxchg
In reply to Huang YingIf 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 llisCHECK_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(strucCHECK_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_dCHECK_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; }
Re: [PATCH -mm 3/4] llist, Move cpu_relax after cmpxchg
Quoted 5 lines · * Huang Ying ([email protected]) wrote:
If the first cmpxchg calling succeeds, it is not necessary to use
cpu_relaxbefore cmpxchg. Socpu_relaxin a busy loop involving cmpxchg should go after cmpxchg instead of before that. This patch fixes this in llist.
Thanks!
MAthieu
Quoted 62 lines
Signed-off-by Huang Ying <[email protected]>Cc Mathieu Desnoyers <[email protected]>Cc Peter Zijlstra <[email protected]>--- 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 llisCHECK_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(strucCHECK_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_dCHECK_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; }
Signature · 4 lines
Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com
PATCH 4/4 irq_work, Use llist in irq_work
In reply to Huang YingUse llist in irq_work instead of the lock-less linked list implementation in irq_work to avoid the code duplication.
--- include/linux/irq_work.h | 15 ++++--- kernel/irq_work.c | 92 ++++++++++++++++------------------------------- 2 files changed, 41 insertions(+), 66 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 +32 -60
174 lines not on this page · raw message
Re: [PATCH -mm 4/4] irq_work, Use llist in irq_work
Quoted 10 lines · * Huang Ying ([email protected]) wrote:
Use llist in
irq_workinstead of the lock-less linked list implementation inirq_workto avoid the code duplication.Signed-off-by Huang Ying <[email protected]>Cc Peter Zijlstra <[email protected]>--- include/linux/irq_work.h | 15 ++++--- kernel/irq_work.c | 92 ++++++++++++++++------------------------------- 2 files changed, 41 insertions(+), 66 deletions(-)
[...]
Quoted 7 lines
kernel/irq_work.c +1
-3-static void __irq_work_queue (struct irq_work *entry) +static void __irq_work_queue (struct irq_work *work) { -struct irq_work *next; -preempt_disable ();
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 65
Quoted 10 lines
kernel/irq_work.c +2
-7-do { - next =__this_cpu_read (irq_work_list); -/* Can assign non-atomic because we keep the flags set. */ - entry->next =next_flags (next,IRQ_WORK_FLAGS ); - }while (this_cpu_cmpxchg (irq_work_list, next, entry) != next); - +llist_add (&work->llnode, &__get_cpu_var (irq_work_list));/* The list was empty, raise self-interrupt to start processing. */ -if (!irq_work_next (entry)) +if (!work->llnode.next)
Hrm. What happens if this function gets delayed between llist_add and "if (!work->llnode.next)" ? It seems like the threads performing llist_del_all would be within its right to free the memory pointed to by work in the meantime.
Thanks,
Mathieu
Signature · 4 lines
Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com
Re: [PATCH -mm 4/4] irq_work, Use llist in irq_work
Quoted 19 lines · Mathieu Desnoyers
Quoted 10 lines · * Huang Ying ([email protected]) wrote:
Use llist in
irq_workinstead of the lock-less linked list implementation inirq_workto avoid the code duplication.Signed-off-by Huang Ying <[email protected]>Cc Peter Zijlstra <[email protected]>--- include/linux/irq_work.h | 15 ++++--- kernel/irq_work.c | 92 ++++++++++++++++------------------------------- 2 files changed, 41 insertions(+), 66 deletions(-)[...]
Quoted 7 lines
kernel/irq_work.c +1
-3-static void __irq_work_queue (struct irq_work *entry) +static void __irq_work_queue (struct irq_work *work) { -struct irq_work *next; -preempt_disable ();
Quoted 16 lines
kernel/irq_work.c void __weak arch_irq_work_raise(void) · line 65
Quoted 10 lines
kernel/irq_work.c +2
-7-do { - next =__this_cpu_read (irq_work_list); -/* Can assign non-atomic because we keep the flags set. */ - entry->next =next_flags (next,IRQ_WORK_FLAGS ); - }while (this_cpu_cmpxchg (irq_work_list, next, entry) != next); - +llist_add (&work->llnode, &__get_cpu_var (irq_work_list));/* The list was empty, raise self-interrupt to start processing. */ -if (!irq_work_next (entry)) +if (!work->llnode.next)Hrm. What happens if this function gets delayed between
llist_addand "if (!work->llnode.next)" ? It seems like the threads performingllist_del_allwould be within its right to free the memory pointed to by work in the meantime.
Yes. This is an issue. This can be fixed in several way
1) use another flag to indicate whether list is empty
2) make llist_add return whether list is empty before adding
3) request irq_work users to free the memory with call_rcu() or after synchronize_rcu().
Personally I prefer 1), which will not expose llist implementation details too.
Best Regards,
Huang Ying
Re: [PATCH -mm 4/4] irq_work, Use llist in irq_work
Quoted 1 line · Huang Ying
2) make
llist_addreturn whether list is empty before adding
That seems the sanest approach, it needs to set entry->next anyway, so it might as well return the last known state.
Quoted 2 lines · * Huang Ying ([email protected]) wrote:
Because llist may be used in performance critical code path, make all llist functions inline to avoid function calling overhead.
Thanks,
Mathieu
Quoted 318 lines
Signed-off-by Huang Ying <[email protected]>Cc Mathieu Desnoyers <[email protected]>Cc Peter Zijlstra <[email protected]>--- 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.cdrivers/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 reportinclude/linux/llist.h +116
-6@@ -37,8 +37,28 @@* 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. +* +* Copyright 2010,2011 Intel Corp. +* Author: Huang Ying <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation; +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <linux/kernel.h> +#include <asm/system.h> +#include <asm/processor.h> +struct llist_head {struct llist_node *first; };@@ -113,14 +133,104 @@ static inline void init_llist_head(struc* test whether the list is empty without deleting something from the * list. */ -static inline int llist_empty (const struct llist_head *head) +static inline bool llist_empty (const struct llist_head *head) {return ACCESS_ONCE (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); +/** +* llist_add - add a new entry +* @new: new entry to be added +* @head: the head for your lock-less list +*/ +static inline void llist_add (struct llist_node *new,struct llist_head *head) +{ +struct llist_node *entry, *old_entry; + +#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG +BUG_ON (in_nmi ()); +#endif + + entry = head->first; +do { + old_entry = entry; + new->next = entry; +cpu_relax (); + }while ((entry =cmpxchg (&head->first, old_entry, new)) != old_entry); +} + +/** +* llist_add_batch - add several linked entries in batch +* @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 +*/ +static inline void llist_add_batch (struct llist_node *new_first, +struct llist_node *new_last, +struct llist_head *head) +{ +struct llist_node *entry, *old_entry; + +#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG +BUG_ON (in_nmi ()); +#endif + + entry = head->first; +do { + old_entry = entry; + new_last->next = entry; +cpu_relax (); + }while ((entry =cmpxchg (&head->first, old_entry, new_first)) != old_entry); +} + +/** +* llist_del_first - delete the first entry of lock-less list +* @head: the head for your lock-less list +* +* If list is empty, return NULL, otherwise, return the first entry +* deleted, this is the newest added one. +* +* Only one llist_del_first user can be used simultaneously with +* multiple llist_add users without lock. Because otherwise +* llist_del_first, llist_add, llist_add (or llist_del_all, llist_add, +* llist_add) sequence in another user may change @head->first->next, +* but keep @head->first. If multiple consumers are needed, please +* use llist_del_all or use lock between consumers. +*/ +static inline struct llist_node *llist_del_first (struct llist_head *head) +{ +struct llist_node *entry, *old_entry, *next; + +#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG +BUG_ON (in_nmi ()); +#endif + + entry = head->first; +do { +if (entry ==NULL ) +return NULL ; + old_entry = entry; + next = entry->next; +cpu_relax (); + }while ((entry =cmpxchg (&head->first, old_entry, next)) != old_entry); + +return entry; +} + +/** +* llist_del_all - delete all entries from lock-less list +* @head: the head of lock-less list to delete all entries +* +* If list is empty, return NULL, otherwise, delete all entries and +* return the pointer to the first entry. The order of entries +* deleted is from the newest to the oldest added one. +*/ +static inline struct llist_node *llist_del_all (struct llist_head *head) +{ +#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG +BUG_ON (in_nmi ()); +#endif + +return xchg (&head->first,NULL ); +}#endif /* LLIST_H */ 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 - endmenulib/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.hlib/llist.c deleted +0
-129@@ -1,129 +0,0 @@ -/* -* Lock-less NULL terminated single linked list -* -* 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. -* -* Copyright 2010,2011 Intel Corp. -* Author: Huang Ying <[email protected]> -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License version -* 2 as published by the Free Software Foundation; -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/interrupt.h> -#include <linux/llist.h> - -#include <asm/system.h> - -/** -* llist_add - add a new entry -* @new: new entry to be added -* @head: the head for your lock-less list -*/ -void llist_add (struct llist_node *new,struct llist_head *head) -{ -struct llist_node *entry, *old_entry; - -#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -BUG_ON (in_nmi ()); -#endif - - entry = head->first; -do { - old_entry = entry; - new->next = entry; -cpu_relax (); - }while ((entry =cmpxchg (&head->first, old_entry, new)) != old_entry); -} -EXPORT_SYMBOL_GPL (llist_add); - -/** -* llist_add_batch - add several linked entries in batch -* @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 -*/ -void llist_add_batch (struct llist_node *new_first,struct llist_node *new_last, -struct llist_head *head) -{ -struct llist_node *entry, *old_entry; - -#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -BUG_ON (in_nmi ()); -#endif - - entry = head->first; -do { - old_entry = entry; - new_last->next = entry; -cpu_relax (); - }while ((entry =cmpxchg (&head->first, old_entry, new_first)) != old_entry); -} -EXPORT_SYMBOL_GPL (llist_add_batch); - -/** -* llist_del_first - delete the first entry of lock-less list -* @head: the head for your lock-less list -* -* If list is empty, return NULL, otherwise, return the first entry -* deleted, this is the newest added one. -* -* Only one llist_del_first user can be used simultaneously with -* multiple llist_add users without lock. Because otherwise -* llist_del_first, llist_add, llist_add (or llist_del_all, llist_add, -* llist_add) sequence in another user may change @head->first->next, -* but keep @head->first. If multiple consumers are needed, please -* use llist_del_all or use lock between consumers. -*/ -struct llist_node *llist_del_first (struct llist_head *head) -{ -struct llist_node *entry, *old_entry, *next; - -#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -BUG_ON (in_nmi ()); -#endif - - entry = head->first; -do { -if (entry ==NULL ) -return NULL ; - old_entry = entry; - next = entry->next; -cpu_relax (); - }while ((entry =cmpxchg (&head->first, old_entry, next)) != old_entry); - -return entry; -} -EXPORT_SYMBOL_GPL (llist_del_first); - -/** -* llist_del_all - delete all entries from lock-less list -* @head: the head of lock-less list to delete all entries -* -* If list is empty, return NULL, otherwise, delete all entries and -* return the pointer to the first entry. The order of entries -* deleted is from the newest to the oldest added one. -*/ -struct llist_node *llist_del_all (struct llist_head *head) -{ -#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG -BUG_ON (in_nmi ()); -#endif - -return xchg (&head->first,NULL ); -} -EXPORT_SYMBOL_GPL (llist_del_all);
Signature · 4 lines
Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com