summaryrefslogtreecommitdiffstats
path: root/lib/llist.c
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2022-07-12 16:49:17 +0200
committerAndrew Morton <akpm@linux-foundation.org>2022-09-11 21:55:06 -0700
commit4f1d2a030db09af4d21695983674a18633cd0ffb (patch)
treeb149575bb927d0552a63441ab885a5a9128212f3 /lib/llist.c
parent05c6257433b7212f07a7e53479a8ab038fc1666a (diff)
downloadlinux-4f1d2a030db09af4d21695983674a18633cd0ffb.tar.gz
linux-4f1d2a030db09af4d21695983674a18633cd0ffb.tar.bz2
linux-4f1d2a030db09af4d21695983674a18633cd0ffb.zip
llist: use try_cmpxchg in llist_add_batch and llist_del_first
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in llist_add_batch and llist_del_first. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg. Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications. No functional change intended. Link: https://lkml.kernel.org/r/20220712144917.4497-1-ubizjak@gmail.com Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/llist.c b/lib/llist.c
index 611ce4881a87..7d78b736e8af 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -30,7 +30,7 @@ bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
do {
new_last->next = first = READ_ONCE(head->first);
- } while (cmpxchg(&head->first, first, new_first) != first);
+ } while (!try_cmpxchg(&head->first, &first, new_first));
return !first;
}
@@ -52,18 +52,14 @@ EXPORT_SYMBOL_GPL(llist_add_batch);
*/
struct llist_node *llist_del_first(struct llist_head *head)
{
- struct llist_node *entry, *old_entry, *next;
+ struct llist_node *entry, *next;
entry = smp_load_acquire(&head->first);
- for (;;) {
+ do {
if (entry == NULL)
return NULL;
- old_entry = entry;
next = READ_ONCE(entry->next);
- entry = cmpxchg(&head->first, old_entry, next);
- if (entry == old_entry)
- break;
- }
+ } while (!try_cmpxchg(&head->first, &entry, next));
return entry;
}