Subject: Re: Lock benchmarks
To: None <>
From: Jason R Thorpe <>
List: tech-kern
Date: 09/17/2002 22:44:39
On Tue, Sep 17, 2002 at 10:03:00AM +1200, Gregory McGarry wrote:

 > The assembler routines will be the ones used in the pthread library
 > if it is decided that RAS locks should be used by default on
 > uniprocessor machines.  I guess the jury is still out on that one.

I have some comments on the asm:

	1. In a RAS locking scheme, you only ever want to provide
	   or use the "lock_try" version.  This is because if the
	   lock is held, know either: (a) you need to context
	   switch, (b) you need to croak (deadlock).  If you spin
	   around, then you're just consuming cpu time, and might
	   deadlock if your threads aren't being timesliced against
	   each other.

	   You can assume these things because RAS is only used on
	   a uniprocessor.  This is also why RAS doesn't need to
	   do memory barrier ops (no other processor to notify, and
	   the compiler already sees a memory clobber because it
	   called a function).

	2. The critical section of most of them is longer than it
	   needs to be.  Case in point, the Alpha in your version:

LEAF(__ras_simple_lock, 1)
XLEAF(__ras_simple_lock_start, 1)
1:      ldl     t0, 0(a0)
        bne     t0, 1b
        ldi     t0, 1
        stl     t0, 0(a0)
XLEAF(__ras_simple_lock_end, 1)
        ret     zero, (ra), 1

	   I'd probably write it like this (including the "lock_try" bit):

	.globl __ras_simple_lock_start
	.globl __ras_simple_lock_end

LEAF(__ras_simple_lock_try, 1)
	ldl	t0, 0(a0)
	bne	t0, 1f
	stl	t1, 0(a0)
	ldi	v0, 1
	mov	zero, v0

        -- Jason R. Thorpe <>