aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2011-09-08 02:00:44 -0400
committerIngo Molnar <mingo@elte.hu>2011-10-04 06:43:39 -0400
commita3127336b71f6833d1483c856dce91fe558dc3a9 (patch)
treec025279c450994f25661c2ab004f0be98997cf8a
parent2c30245c65e8ebc3080b75ce65572ab8140bad0b (diff)
llist: Move cpu_relax() to after the cmpxchg()
If in llist_add()/etc. functions the first cmpxchg() call succeeds, it is not necessary to use cpu_relax() before the cmpxchg(). So cpu_relax() in a busy loop involving cmpxchg() should go after cmpxchg() instead of before that. This patch fixes this for all involved llist functions. Signed-off-by: Huang Ying <ying.huang@intel.com> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1315461646-1379-4-git-send-email-ying.huang@intel.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--include/linux/llist.h7
-rw-r--r--lib/llist.c14
2 files changed, 15 insertions, 6 deletions
diff --git a/include/linux/llist.h b/include/linux/llist.h
index 65fca1cbf514..ca91875286bf 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -148,11 +148,14 @@ static inline void llist_add(struct llist_node *new, struct llist_head *head)
148 struct llist_node *entry, *old_entry; 148 struct llist_node *entry, *old_entry;
149 149
150 entry = head->first; 150 entry = head->first;
151 do { 151 for (;;) {
152 old_entry = entry; 152 old_entry = entry;
153 new->next = entry; 153 new->next = entry;
154 entry = cmpxchg(&head->first, old_entry, new);
155 if (entry == old_entry)
156 break;
154 cpu_relax(); 157 cpu_relax();
155 } while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry); 158 }
156} 159}
157 160
158/** 161/**
diff --git a/lib/llist.c b/lib/llist.c
index b445f2c8596a..6c69f1d14c4b 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -41,11 +41,14 @@ void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
41 struct llist_node *entry, *old_entry; 41 struct llist_node *entry, *old_entry;
42 42
43 entry = head->first; 43 entry = head->first;
44 do { 44 for (;;) {
45 old_entry = entry; 45 old_entry = entry;
46 new_last->next = entry; 46 new_last->next = entry;
47 entry = cmpxchg(&head->first, old_entry, new_first);
48 if (entry == old_entry)
49 break;
47 cpu_relax(); 50 cpu_relax();
48 } while ((entry = cmpxchg(&head->first, old_entry, new_first)) != old_entry); 51 }
49} 52}
50EXPORT_SYMBOL_GPL(llist_add_batch); 53EXPORT_SYMBOL_GPL(llist_add_batch);
51 54
@@ -68,13 +71,16 @@ struct llist_node *llist_del_first(struct llist_head *head)
68 struct llist_node *entry, *old_entry, *next; 71 struct llist_node *entry, *old_entry, *next;
69 72
70 entry = head->first; 73 entry = head->first;
71 do { 74 for (;;) {
72 if (entry == NULL) 75 if (entry == NULL)
73 return NULL; 76 return NULL;
74 old_entry = entry; 77 old_entry = entry;
75 next = entry->next; 78 next = entry->next;
79 entry = cmpxchg(&head->first, old_entry, next);
80 if (entry == old_entry)
81 break;
76 cpu_relax(); 82 cpu_relax();
77 } while ((entry = cmpxchg(&head->first, old_entry, next)) != old_entry); 83 }
78 84
79 return entry; 85 return entry;
80} 86}