Re: [patch] speed up / fix the new generic semaphore code (fixAIM7 40% regression with 2.6.26-rc1)

From: Ingo Molnar
Date: Thu May 08 2008 - 08:28:39 EST



* Ingo Molnar <mingo@xxxxxxx> wrote:

> + if (unlikely(sem->count <= 0))
> __down(sem);
> + sem->count--;

Peter pointed it out that because sem->count is u32, the <= 0 is in fact
a "== 0" condition - the patch below does that. As expected gcc figured
out the same thing too so the resulting code output did not change. (so
this is just a cleanup)

i've got this lined up in sched.git and it's undergoing testing right
now. If that testing goes fine and if there are no objections i'll send
a pull request for it later today.

Ingo

---------------->
Subject: semaphores: improve code
From: Ingo Molnar <mingo@xxxxxxx>
Date: Thu May 08 14:19:23 CEST 2008

No code changed:

kernel/semaphore.o:

text data bss dec hex filename
1207 0 0 1207 4b7 semaphore.o.before
1207 0 0 1207 4b7 semaphore.o.after

md5:
c10198c2952bd345a1edaac6db891548 semaphore.o.before.asm
c10198c2952bd345a1edaac6db891548 semaphore.o.after.asm

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
kernel/semaphore.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux/kernel/semaphore.c
===================================================================
--- linux.orig/kernel/semaphore.c
+++ linux/kernel/semaphore.c
@@ -54,7 +54,7 @@ void down(struct semaphore *sem)
unsigned long flags;

spin_lock_irqsave(&sem->lock, flags);
- if (unlikely(sem->count <= 0))
+ if (unlikely(!sem->count))
__down(sem);
sem->count--;
spin_unlock_irqrestore(&sem->lock, flags);
@@ -76,7 +76,7 @@ int down_interruptible(struct semaphore
int result = 0;

spin_lock_irqsave(&sem->lock, flags);
- if (unlikely(sem->count <= 0))
+ if (unlikely(!sem->count))
result = __down_interruptible(sem);
if (!result)
sem->count--;
@@ -102,7 +102,7 @@ int down_killable(struct semaphore *sem)
int result = 0;

spin_lock_irqsave(&sem->lock, flags);
- if (unlikely(sem->count <= 0))
+ if (unlikely(!sem->count))
result = __down_killable(sem);
if (!result)
sem->count--;
@@ -156,7 +156,7 @@ int down_timeout(struct semaphore *sem,
int result = 0;

spin_lock_irqsave(&sem->lock, flags);
- if (unlikely(sem->count <= 0))
+ if (unlikely(!sem->count))
result = __down_timeout(sem, jiffies);
if (!result)
sem->count--;
--
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/