diff options
author | Nick Piggin <npiggin@suse.de> | 2008-01-30 07:31:21 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:31:21 -0500 |
commit | 314cdbefd1fd0a7acf3780e9628465b77ea6a836 (patch) | |
tree | 2d2e743433ef61864728e4031e2d17be53efa3bc /include/asm-x86/paravirt.h | |
parent | 95c354fe9f7d6decc08a92aa26eb233ecc2155bf (diff) |
x86: FIFO ticket spinlocks
Introduce ticket lock spinlocks for x86 which are FIFO. The implementation
is described in the comments. The straight-line lock/unlock instruction
sequence is slightly slower than the dec based locks on modern x86 CPUs,
however the difference is quite small on Core2 and Opteron when working out of
cache, and becomes almost insignificant even on P4 when the lock misses cache.
trylock is more significantly slower, but they are relatively rare.
On an 8 core (2 socket) Opteron, spinlock unfairness is extremely noticable,
with a userspace test having a difference of up to 2x runtime per thread, and
some threads are starved or "unfairly" granted the lock up to 1 000 000 (!)
times. After this patch, all threads appear to finish at exactly the same
time.
The memory ordering of the lock does conform to x86 standards, and the
implementation has been reviewed by Intel and AMD engineers.
The algorithm also tells us how many CPUs are contending the lock, so
lockbreak becomes trivial and we no longer have to waste 4 bytes per
spinlock for it.
After this, we can no longer spin on any locks with preempt enabled
and cannot reenable interrupts when spinning on an irq safe lock, because
at that point we have already taken a ticket and the would deadlock if
the same CPU tries to take the lock again. These are questionable anyway:
if the lock happens to be called under a preempt or interrupt disabled section,
then it will just have the same latency problems. The real fix is to keep
critical sections short, and ensure locks are reasonably fair (which this
patch does).
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/asm-x86/paravirt.h')
-rw-r--r-- | include/asm-x86/paravirt.h | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/include/asm-x86/paravirt.h b/include/asm-x86/paravirt.h index 4f23f434a1f3..24406703007f 100644 --- a/include/asm-x86/paravirt.h +++ b/include/asm-x86/paravirt.h | |||
@@ -1077,27 +1077,6 @@ static inline unsigned long __raw_local_irq_save(void) | |||
1077 | return f; | 1077 | return f; |
1078 | } | 1078 | } |
1079 | 1079 | ||
1080 | #define CLI_STRING \ | ||
1081 | _paravirt_alt("pushl %%ecx; pushl %%edx;" \ | ||
1082 | "call *%[paravirt_cli_opptr];" \ | ||
1083 | "popl %%edx; popl %%ecx", \ | ||
1084 | "%c[paravirt_cli_type]", "%c[paravirt_clobber]") | ||
1085 | |||
1086 | #define STI_STRING \ | ||
1087 | _paravirt_alt("pushl %%ecx; pushl %%edx;" \ | ||
1088 | "call *%[paravirt_sti_opptr];" \ | ||
1089 | "popl %%edx; popl %%ecx", \ | ||
1090 | "%c[paravirt_sti_type]", "%c[paravirt_clobber]") | ||
1091 | |||
1092 | #define CLI_STI_CLOBBERS , "%eax" | ||
1093 | #define CLI_STI_INPUT_ARGS \ | ||
1094 | , \ | ||
1095 | [paravirt_cli_type] "i" (PARAVIRT_PATCH(pv_irq_ops.irq_disable)), \ | ||
1096 | [paravirt_cli_opptr] "m" (pv_irq_ops.irq_disable), \ | ||
1097 | [paravirt_sti_type] "i" (PARAVIRT_PATCH(pv_irq_ops.irq_enable)), \ | ||
1098 | [paravirt_sti_opptr] "m" (pv_irq_ops.irq_enable), \ | ||
1099 | paravirt_clobber(CLBR_EAX) | ||
1100 | |||
1101 | /* Make sure as little as possible of this mess escapes. */ | 1080 | /* Make sure as little as possible of this mess escapes. */ |
1102 | #undef PARAVIRT_CALL | 1081 | #undef PARAVIRT_CALL |
1103 | #undef __PVOP_CALL | 1082 | #undef __PVOP_CALL |