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>
This commit is contained in:
		
					parent
					
						
							
								2c30245c65
							
						
					
				
			
			
				commit
				
					
						a3127336b7
					
				
			
		
					 2 changed files with 15 additions and 6 deletions
				
			
		| 
						 | 
					@ -148,11 +148,14 @@ static inline void llist_add(struct llist_node *new, struct llist_head *head)
 | 
				
			||||||
	struct llist_node *entry, *old_entry;
 | 
						struct llist_node *entry, *old_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entry = head->first;
 | 
						entry = head->first;
 | 
				
			||||||
	do {
 | 
						for (;;) {
 | 
				
			||||||
		old_entry = entry;
 | 
							old_entry = entry;
 | 
				
			||||||
		new->next = entry;
 | 
							new->next = entry;
 | 
				
			||||||
 | 
							entry = cmpxchg(&head->first, old_entry, new);
 | 
				
			||||||
 | 
							if (entry == old_entry)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		cpu_relax();
 | 
							cpu_relax();
 | 
				
			||||||
	} while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry);
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								lib/llist.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								lib/llist.c
									
										
									
									
									
								
							| 
						 | 
					@ -41,11 +41,14 @@ void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
 | 
				
			||||||
	struct llist_node *entry, *old_entry;
 | 
						struct llist_node *entry, *old_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entry = head->first;
 | 
						entry = head->first;
 | 
				
			||||||
	do {
 | 
						for (;;) {
 | 
				
			||||||
		old_entry = entry;
 | 
							old_entry = entry;
 | 
				
			||||||
		new_last->next = entry;
 | 
							new_last->next = entry;
 | 
				
			||||||
 | 
							entry = cmpxchg(&head->first, old_entry, new_first);
 | 
				
			||||||
 | 
							if (entry == old_entry)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		cpu_relax();
 | 
							cpu_relax();
 | 
				
			||||||
	} while ((entry = cmpxchg(&head->first, old_entry, new_first)) != old_entry);
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(llist_add_batch);
 | 
					EXPORT_SYMBOL_GPL(llist_add_batch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,13 +71,16 @@ struct llist_node *llist_del_first(struct llist_head *head)
 | 
				
			||||||
	struct llist_node *entry, *old_entry, *next;
 | 
						struct llist_node *entry, *old_entry, *next;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entry = head->first;
 | 
						entry = head->first;
 | 
				
			||||||
	do {
 | 
						for (;;) {
 | 
				
			||||||
		if (entry == NULL)
 | 
							if (entry == NULL)
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		old_entry = entry;
 | 
							old_entry = entry;
 | 
				
			||||||
		next = entry->next;
 | 
							next = entry->next;
 | 
				
			||||||
 | 
							entry = cmpxchg(&head->first, old_entry, next);
 | 
				
			||||||
 | 
							if (entry == old_entry)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		cpu_relax();
 | 
							cpu_relax();
 | 
				
			||||||
	} while ((entry = cmpxchg(&head->first, old_entry, next)) != old_entry);
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return entry;
 | 
						return entry;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue