lkml.org 
[lkml]   [2011]   [Sep]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH -mm 3/4] llist, Move cpu_relax after cmpxchg
    * Huang Ying (ying.huang@intel.com) wrote:
    > If 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.
    >

    Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

    Thanks!

    MAthieu

    > Signed-off-by: Huang Ying <ying.huang@intel.com>
    > Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    > Cc: Peter Zijlstra <peterz@infradead.org>
    > ---
    > include/linux/llist.h | 21 +++++++++++++++------
    > 1 file changed, 15 insertions(+), 6 deletions(-)
    >
    > --- a/include/linux/llist.h
    > +++ b/include/linux/llist.h
    > @@ -156,11 +156,14 @@ static inline void llist_add(struct llis
    > 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(struc
    > 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_d
    > 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;
    > }

    --
    Mathieu Desnoyers
    Operating System Efficiency R&D Consultant
    EfficiOS Inc.
    http://www.efficios.com


    \
     
     \ /
      Last update: 2011-09-06 12:55    [W:2.686 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site