[PATCH 8/8] rwsem: small optimizing rwsem_down_failed_common

From: Alex Shi
Date: Fri May 03 2013 - 02:51:25 EST


Peter Zijlstra suggest adding a preempt_enable_no_resched() to prevent
a unnecessary scheduler in raw_spin_unlock.
And we also can pack 2 raw_spin_lock to save one. So has this patch.

Thanks Peter!

Signed-off-by: Alex Shi <alex.shi@xxxxxxxxx>
---
lib/rwsem.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/rwsem.c b/lib/rwsem.c
index ad5e0df..9aacf81 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -212,23 +212,25 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
adjustment == -RWSEM_ACTIVE_WRITE_BIAS)
sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED);

- raw_spin_unlock_irq(&sem->wait_lock);
-
/* wait to be given the lock */
for (;;) {
- if (!waiter.task)
+ if (!waiter.task) {
+ raw_spin_unlock_irq(&sem->wait_lock);
break;
+ }

- raw_spin_lock_irq(&sem->wait_lock);
- /* Try to get the writer sem, may steal from the head writer: */
+ /* Try to get the writer sem, may steal from the head writer */
if (flags == RWSEM_WAITING_FOR_WRITE)
if (try_get_writer_sem(sem, &waiter)) {
raw_spin_unlock_irq(&sem->wait_lock);
return sem;
}
+ preempt_disable();
raw_spin_unlock_irq(&sem->wait_lock);
+ preempt_enable_no_resched();
schedule();
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ raw_spin_lock_irq(&sem->wait_lock);
}

tsk->state = TASK_RUNNING;
--
1.7.12

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/