]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
llist: move cpu_relax after cmpxchg
authorHuang Ying <ying.huang@intel.com>
Wed, 28 Sep 2011 00:50:48 +0000 (10:50 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 30 Sep 2011 04:53:41 +0000 (14:53 +1000)
If the first cmpxchg call 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.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Andrew Morton <>
include/linux/llist.h

index 4fd3081dd68ff012f4f4192a1c97315008da86dc..32510931b23b92ed3913e6f1392810d8ff353cb3 100644 (file)
@@ -156,11 +156,14 @@ static inline void llist_add(struct llist_node *new, struct llist_head *head)
        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(struct llist_node *new_first,
        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_del_first(struct llist_head *head)
        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;
 }