diff options
author | Michel Lespinasse <walken@google.com> | 2013-05-07 09:45:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-07 10:20:16 -0400 |
commit | f7dd1cee9a4e2b1450e4a3732636dfbf28562ee4 (patch) | |
tree | 4dc69d1b121d07d25d6dac56fd33eaffd6dac91f /lib | |
parent | e2d57f782c8a906f80d5b5f54da803c1638929d7 (diff) |
rwsem: shorter spinlocked section in rwsem_down_failed_common()
This change reduces the size of the spinlocked and TASK_UNINTERRUPTIBLE
sections in rwsem_down_failed_common():
- We only need the sem->wait_lock to insert ourselves on the wait_list;
the waiter node can be prepared outside of the wait_lock.
- The task state only needs to be set to TASK_UNINTERRUPTIBLE immediately
before checking if we actually need to sleep; it doesn't need to protect
the entire function.
Signed-off-by: Michel Lespinasse <walken@google.com>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
Acked-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rwsem.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/rwsem.c b/lib/rwsem.c index 672eb33218ac..40636454cf3c 100644 --- a/lib/rwsem.c +++ b/lib/rwsem.c | |||
@@ -188,14 +188,12 @@ rwsem_down_failed_common(struct rw_semaphore *sem, | |||
188 | struct task_struct *tsk = current; | 188 | struct task_struct *tsk = current; |
189 | signed long count; | 189 | signed long count; |
190 | 190 | ||
191 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
192 | |||
193 | /* set up my own style of waitqueue */ | 191 | /* set up my own style of waitqueue */ |
194 | raw_spin_lock_irq(&sem->wait_lock); | ||
195 | waiter.task = tsk; | 192 | waiter.task = tsk; |
196 | waiter.type = type; | 193 | waiter.type = type; |
197 | get_task_struct(tsk); | 194 | get_task_struct(tsk); |
198 | 195 | ||
196 | raw_spin_lock_irq(&sem->wait_lock); | ||
199 | if (list_empty(&sem->wait_list)) | 197 | if (list_empty(&sem->wait_list)) |
200 | adjustment += RWSEM_WAITING_BIAS; | 198 | adjustment += RWSEM_WAITING_BIAS; |
201 | list_add_tail(&waiter.list, &sem->wait_list); | 199 | list_add_tail(&waiter.list, &sem->wait_list); |
@@ -218,7 +216,8 @@ rwsem_down_failed_common(struct rw_semaphore *sem, | |||
218 | raw_spin_unlock_irq(&sem->wait_lock); | 216 | raw_spin_unlock_irq(&sem->wait_lock); |
219 | 217 | ||
220 | /* wait to be given the lock */ | 218 | /* wait to be given the lock */ |
221 | for (;;) { | 219 | while (true) { |
220 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
222 | if (!waiter.task) | 221 | if (!waiter.task) |
223 | break; | 222 | break; |
224 | 223 | ||
@@ -231,7 +230,6 @@ rwsem_down_failed_common(struct rw_semaphore *sem, | |||
231 | } | 230 | } |
232 | raw_spin_unlock_irq(&sem->wait_lock); | 231 | raw_spin_unlock_irq(&sem->wait_lock); |
233 | schedule(); | 232 | schedule(); |
234 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
235 | } | 233 | } |
236 | 234 | ||
237 | tsk->state = TASK_RUNNING; | 235 | tsk->state = TASK_RUNNING; |