lkml.org 
[lkml]   [2014]   [Feb]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 5/8] locking, mutex: Cancelable MCS lock for adaptive spinning
    From
    Date
    On Mon, 2014-02-10 at 22:32 +0100, Peter Zijlstra wrote:
    > On Mon, Feb 10, 2014 at 01:15:59PM -0800, Jason Low wrote:
    > > On Mon, 2014-02-10 at 20:58 +0100, Peter Zijlstra wrote:
    > > > +void osq_unlock(struct optimistic_spin_queue **lock)
    > > > +{
    > > > + struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node);
    > > > + struct optimistic_spin_queue *next;
    > > > +
    > > > + /*
    > > > + * Fast path for the uncontended case.
    > > > + */
    > > > + if (likely(cmpxchg(lock, node, NULL) == node))
    > > > + return;
    > >
    > > Can we can also add the following code here as I'm noticing next != NULL
    > > is the much more likely scenario on my box:
    > >
    > > next = xchg(&node->next, NULL);
    > > if (next) {
    > > ACCESS_ONCE(next->locked) = 1;
    > > return;
    >
    > Is adding that really much faster than the relatively straight path
    > oqs_wait_next() would walk to bit the same exit?
    >
    > The only reason I pulled out the above cmpxchg() is because its the
    > uncontended fast path, which seems like a special enough case.

    So it would avoid 2 extra checks (*lock == node) and (node->next) in the
    oqs_wait_next() path, which aren't necessary when node->next != NULL.

    And I think node->next != NULL can be considered a special enough case
    after the cmpxchg() fails because in the contended case, we're expecting
    the node->next to be pointing at something. The only times node->next is
    NULL after cmpxchg() fails are during a very small race window with the
    osq_lock(), and when the next node is unqueuing due to need_resched,
    which is also a very small window.



    \
     
     \ /
      Last update: 2014-02-11 00:01    [W:3.800 / U:0.884 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site