diff options
author | Chuck Ebbert <76306.1226@compuserve.com> | 2006-03-23 05:59:55 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-23 10:38:06 -0500 |
commit | 42c059e04d507802006911e316d86aa8ef75eb73 (patch) | |
tree | 42eb9e4d5f0a578dca12a26beeae4b27d968cb4a | |
parent | 7c5c1e427b5e83807fd05419d1cf6991b9d87247 (diff) |
[PATCH] i386 spinlocks: disable interrupts only if we enabled them
_raw_spin_lock_flags() is entered with interrupts disabled. If it cannot
obtain a spinlock, it checks the flags that were passed and re-enables
interrupts before spinning if that's how the flags are set. When the
spinlock might be available, it disables interrupts (even if they are
already disabled) before trying to get the lock. Change that so interrupts
are only disabled if they have been enabled. This costs nine bytes of
duplicated spinloop code.
Fastpath before patch:
jle <keep looping> not-taken conditional jump
cli disable interrupts
jmp <try for lock> unconditional jump
Fastpath after patch, if interrupts were not enabled:
jg <try for lock> taken conditional branch
Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | include/asm-i386/spinlock.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/include/asm-i386/spinlock.h b/include/asm-i386/spinlock.h index a1b8a8a30e21..d76b7693cf1d 100644 --- a/include/asm-i386/spinlock.h +++ b/include/asm-i386/spinlock.h | |||
@@ -35,18 +35,23 @@ | |||
35 | #define __raw_spin_lock_string_flags \ | 35 | #define __raw_spin_lock_string_flags \ |
36 | "\n1:\t" \ | 36 | "\n1:\t" \ |
37 | "lock ; decb %0\n\t" \ | 37 | "lock ; decb %0\n\t" \ |
38 | "jns 4f\n\t" \ | 38 | "jns 5f\n" \ |
39 | "2:\t" \ | 39 | "2:\t" \ |
40 | "testl $0x200, %1\n\t" \ | 40 | "testl $0x200, %1\n\t" \ |
41 | "jz 3f\n\t" \ | 41 | "jz 4f\n\t" \ |
42 | "sti\n\t" \ | 42 | "sti\n" \ |
43 | "3:\t" \ | 43 | "3:\t" \ |
44 | "rep;nop\n\t" \ | 44 | "rep;nop\n\t" \ |
45 | "cmpb $0, %0\n\t" \ | 45 | "cmpb $0, %0\n\t" \ |
46 | "jle 3b\n\t" \ | 46 | "jle 3b\n\t" \ |
47 | "cli\n\t" \ | 47 | "cli\n\t" \ |
48 | "jmp 1b\n" \ | 48 | "jmp 1b\n" \ |
49 | "4:\n\t" | 49 | "4:\t" \ |
50 | "rep;nop\n\t" \ | ||
51 | "cmpb $0, %0\n\t" \ | ||
52 | "jg 1b\n\t" \ | ||
53 | "jmp 4b\n" \ | ||
54 | "5:\n\t" | ||
50 | 55 | ||
51 | #define __raw_spin_lock_string_up \ | 56 | #define __raw_spin_lock_string_up \ |
52 | "\n\tdecb %0" | 57 | "\n\tdecb %0" |