From: Eric Dumazet <dada1@cosmosbay.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
linux@horizon.com, Kirill Korotaev <dev@sw.ru>
Subject: [PATCH] i386 spinlocks should use the full 32 bits, not only 8 bits
Date: Tue, 11 Oct 2005 17:32:44 +0200 [thread overview]
Message-ID: <434BDB1C.60105@cosmosbay.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0510110740050.14597@g5.osdl.org>
[-- Attachment #1: Type: text/plain, Size: 351 bytes --]
As NR_CPUS might be > 128, and every spining CPU decrements the lock, we need
to use more than 8 bits for a spinlock. The current (i386/x86_64)
implementations have a (theorical) bug in this area.
As the allocated space for spinlock_t is 32 bits, let's use full 32 bits and
let the CPUS fight :)
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: i386_spinlock --]
[-- Type: text/plain, Size: 2056 bytes --]
--- linux-2.6.14-rc4/include/asm-i386/spinlock.h 2005-10-11 03:19:19.000000000 +0200
+++ linux-2.6.14-rc4-ed/include/asm-i386/spinlock.h 2005-10-11 19:19:27.000000000 +0200
@@ -18,23 +18,24 @@
* (the type definitions are in asm/spinlock_types.h)
*/
+
#define __raw_spin_is_locked(x) \
- (*(volatile signed char *)(&(x)->slock) <= 0)
+ (*(volatile int *)(&(x)->slock) <= 0)
#define __raw_spin_lock_string \
"\n1:\t" \
- "lock ; decb %0\n\t" \
+ "lock ; decl %0\n\t" \
"jns 3f\n" \
"2:\t" \
"rep;nop\n\t" \
- "cmpb $0,%0\n\t" \
+ "cmpl $0,%0\n\t" \
"jle 2b\n\t" \
"jmp 1b\n" \
"3:\n\t"
#define __raw_spin_lock_string_flags \
"\n1:\t" \
- "lock ; decb %0\n\t" \
+ "lock ; decl %0\n\t" \
"jns 4f\n\t" \
"2:\t" \
"testl $0x200, %1\n\t" \
@@ -42,7 +43,7 @@
"sti\n\t" \
"3:\t" \
"rep;nop\n\t" \
- "cmpb $0, %0\n\t" \
+ "cmpl $0, %0\n\t" \
"jle 3b\n\t" \
"cli\n\t" \
"jmp 1b\n" \
@@ -64,9 +65,10 @@
static inline int __raw_spin_trylock(raw_spinlock_t *lock)
{
- char oldval;
+ int oldval;
+ BUILD_BUG_ON(sizeof(lock->slock) != sizeof(oldval));
__asm__ __volatile__(
- "xchgb %b0,%1"
+ "xchgl %0,%1"
:"=q" (oldval), "=m" (lock->slock)
:"0" (0) : "memory");
return oldval > 0;
@@ -75,14 +77,14 @@
/*
* __raw_spin_unlock based on writing $1 to the low byte.
* This method works. Despite all the confusion.
- * (except on PPro SMP or if we are using OOSTORE, so we use xchgb there)
+ * (except on PPro SMP or if we are using OOSTORE, so we use xchgl there)
* (PPro errata 66, 92)
*/
#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE)
#define __raw_spin_unlock_string \
- "movb $1,%0" \
+ "movl $1,%0" \
:"=m" (lock->slock) : : "memory"
@@ -96,13 +98,13 @@
#else
#define __raw_spin_unlock_string \
- "xchgb %b0, %1" \
+ "xchgl %0, %1" \
:"=q" (oldval), "=m" (lock->slock) \
:"0" (oldval) : "memory"
static inline void __raw_spin_unlock(raw_spinlock_t *lock)
{
- char oldval = 1;
+ int oldval = 1;
__asm__ __volatile__(
__raw_spin_unlock_string
next prev parent reply other threads:[~2005-10-11 15:33 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-11 4:04 i386 spinlock fairness: bizarre test results Chuck Ebbert
2005-10-11 9:42 ` Eric Dumazet
2005-10-11 13:00 ` Alan Cox
2005-10-11 14:44 ` Linus Torvalds
2005-10-11 15:32 ` Eric Dumazet [this message]
2005-10-11 16:03 ` [PATCH] i386 spinlocks should use the full 32 bits, not only 8 bits Linus Torvalds
2005-10-11 16:36 ` Eric Dumazet
2005-10-11 16:54 ` Linus Torvalds
2005-10-11 16:55 ` Linus Torvalds
2005-10-17 7:03 ` Andrew Morton
2005-10-17 7:20 ` Arjan van de Ven
2005-10-20 21:50 ` Ingo Molnar
2005-10-20 21:57 ` Linus Torvalds
2005-10-20 22:02 ` Ingo Molnar
2005-10-20 22:15 ` Linus Torvalds
2005-10-20 22:27 ` Ingo Molnar
2005-10-20 22:44 ` Andrew Morton
2005-10-20 22:53 ` Ingo Molnar
2005-10-20 23:01 ` Andrew Morton
2005-10-20 23:26 ` Ingo Molnar
2005-10-27 16:54 ` Paul Jackson
2005-10-11 17:59 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=434BDB1C.60105@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=dev@sw.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox