lkml.org 
[lkml]   [2018]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] semaphore: use raw_spin_lock_irq instead of raw_spin_lock_irqsave
The sleeping functions down, down_interruptible, down_killable and
down_timeout can't be called with interrupts disabled, so we don't have to
save and restore interrupt flag.

This patch avoids the costly pushf and popf instructions on the semaphore
path.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
kernel/locking/semaphore.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

Index: linux-2.6/kernel/locking/semaphore.c
===================================================================
--- linux-2.6.orig/kernel/locking/semaphore.c 2017-06-03 00:22:44.000000000 +0200
+++ linux-2.6/kernel/locking/semaphore.c 2018-05-30 14:46:35.000000000 +0200
@@ -53,14 +53,12 @@ static noinline void __up(struct semapho
*/
void down(struct semaphore *sem)
{
- unsigned long flags;
-
- raw_spin_lock_irqsave(&sem->lock, flags);
+ raw_spin_lock_irq(&sem->lock);
if (likely(sem->count > 0))
sem->count--;
else
__down(sem);
- raw_spin_unlock_irqrestore(&sem->lock, flags);
+ raw_spin_unlock_irq(&sem->lock);
}
EXPORT_SYMBOL(down);

@@ -75,15 +73,14 @@ EXPORT_SYMBOL(down);
*/
int down_interruptible(struct semaphore *sem)
{
- unsigned long flags;
int result = 0;

- raw_spin_lock_irqsave(&sem->lock, flags);
+ raw_spin_lock_irq(&sem->lock);
if (likely(sem->count > 0))
sem->count--;
else
result = __down_interruptible(sem);
- raw_spin_unlock_irqrestore(&sem->lock, flags);
+ raw_spin_unlock_irq(&sem->lock);

return result;
}
@@ -101,15 +98,14 @@ EXPORT_SYMBOL(down_interruptible);
*/
int down_killable(struct semaphore *sem)
{
- unsigned long flags;
int result = 0;

- raw_spin_lock_irqsave(&sem->lock, flags);
+ raw_spin_lock_irq(&sem->lock);
if (likely(sem->count > 0))
sem->count--;
else
result = __down_killable(sem);
- raw_spin_unlock_irqrestore(&sem->lock, flags);
+ raw_spin_unlock_irq(&sem->lock);

return result;
}
@@ -155,15 +151,14 @@ EXPORT_SYMBOL(down_trylock);
*/
int down_timeout(struct semaphore *sem, long timeout)
{
- unsigned long flags;
int result = 0;

- raw_spin_lock_irqsave(&sem->lock, flags);
+ raw_spin_lock_irq(&sem->lock);
if (likely(sem->count > 0))
sem->count--;
else
result = __down_timeout(sem, timeout);
- raw_spin_unlock_irqrestore(&sem->lock, flags);
+ raw_spin_unlock_irq(&sem->lock);

return result;
}
\
 
 \ /
  Last update: 2018-05-30 17:25    [W:0.396 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site