• Will Deacon's avatar
    locking/qrwlock: Prevent slowpath writers getting held up by fastpath · d1331661
    Will Deacon authored
    
    
    When a prospective writer takes the qrwlock locking slowpath due to the
    lock being held, it attempts to cmpxchg the wmode field from 0 to
    _QW_WAITING so that concurrent lockers also take the slowpath and queue
    on the spinlock accordingly, allowing the lockers to drain.
    
    Unfortunately, this isn't fair, because a fastpath writer that comes in
    after the lock is made available but before the _QW_WAITING flag is set
    can effectively jump the queue. If there is a steady stream of prospective
    writers, then the waiter will be held off indefinitely.
    
    This patch restores fairness by separating _QW_WAITING and _QW_LOCKED
    into two distinct fields: _QW_LOCKED continues to occupy the bottom byte
    of the lockword so that it can be cleared unconditionally when unlocking,
    but _QW_WAITING now occupies what used to be the bottom bit of the reader
    count. This then forces the slow-path for concurrent lockers.
    Tested-by: default avatarWaiman Long <longman@redhat.com>
    Teste...
    d1331661
qrwlock.c 2.79 KB