Skip to content

Commit

Permalink
rwsem: avoid taking wait_lock in rwsem_down_write_failed
Browse files Browse the repository at this point in the history
In rwsem_down_write_failed(), if there are active locks after we wake up
(i.e.  the lock got stolen from us), skip taking the wait_lock and go
back to sleep immediately.

Signed-off-by: Michel Lespinasse <[email protected]>
Reviewed-by: Peter Hurley <[email protected]>
Acked-by: Davidlohr Bueso <[email protected]>
Acked-by: Rik van Riel <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
walken-google authored and torvalds committed May 7, 2013
1 parent 5ede972 commit a7d2c57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rwsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)
sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED);

/* wait until we successfully acquire the lock */
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
while (true) {
set_task_state(tsk, TASK_UNINTERRUPTIBLE);

/* Try acquiring the write lock. */
count = RWSEM_ACTIVE_WRITE_BIAS;
Expand All @@ -226,7 +226,13 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)
break;

raw_spin_unlock_irq(&sem->wait_lock);
schedule();

/* Block until there are no active lockers. */
do {
schedule();
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
} while (sem->count & RWSEM_ACTIVE_MASK);

raw_spin_lock_irq(&sem->wait_lock);
}

Expand Down

0 comments on commit a7d2c57

Please sign in to comment.