Re: [patch 2.6.14-rc4] i386: spinlock optimization

From: linux-os (Dick Johnson)
Date: Fri Oct 14 2005 - 13:25:34 EST



On Fri, 14 Oct 2005, Chuck Ebbert wrote:

> Attempt to acquire spinlock sooner after spinning and then noticing
> it has become available. Also adds a slight delay before testing the
> spinlock again when it's not available, reducing bus traffic.
>
> This change makes spinlocks fairer in the case where the owner drops
> the lock and then immediately tries to take it again.
>
> Signed-Off-By: Chuck Ebbert <76306.1226@xxxxxxxxxxxxxx>
> ---
>
> include/asm-i386/spinlock.h | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> --- 2.6.14-rc4a.orig/include/asm-i386/spinlock.h
> +++ 2.6.14-rc4a/include/asm-i386/spinlock.h
> @@ -28,8 +28,8 @@
> "2:\t" \
> "rep;nop\n\t" \
> "cmpb $0,%0\n\t" \
> - "jle 2b\n\t" \
> - "jmp 1b\n" \
> + "jg 1b\n\t" \
> + "jmp 2b\n" \
> "3:\n\t"
>
> #define __raw_spin_lock_string_flags \
> -


I just noticed in linux-2.6.13.4 that the spinlocks are wrong.
You are trying to optimize a path that should have been granted
in the first place:

Somehow, these spin-locks got all screwed up.

Given: nobody has the lock. The lock variable is 0.

#define spin_lock_string \
"\n1:\t" \
"lock ; decb %0\n\t" \
"jns 3f\n" \ # This should have been 'js'
"2:\t" \
"rep;nop\n\t" \
"cmpb $0,%0\n\t" \
"jle 2b\n\t" \
"jmp 1b\n" \
"3:\n\t" # Got the lock, exit loop


The spin-locks should have been:

#define spin_lock_string \
"\n1:\t" \
"lock ; decb %0\n\t" \ # Bump the lock variable
"js 2f\n\t" \ # Good, we got the lock
"lock ; incb %0\n\t" \ # Release your attempt __important__
"rep ; nop \n\t" \ # pause
"jmp 1b\n" \ # Try again
"2:\n" # Exit the lock


Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.46 BogoMips).
Warning : 98.36% of all statistics are fiction.
.

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@xxxxxxxxxxxx - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.
-
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/