Subject: Re: Support for atomic locks in lock.h
To: Wayne Knowles <wdk@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: port-mips
Date: 11/26/2001 12:21:39
Wayne Knowles wrote:

> On Sat, 24 Nov 2001, Jason R Thorpe wrote:
> 
> > Not really.  Here's what I would suggest:
> >
> > 	* Put an #ifdef _KERNEL / #else / #endif in each function
> > 	  in <machine/lock.h>.  Make the kernel versions panic for
> > 	  now (they're not needed unless you support MULTIPROCESSOR,
> > 	  which the MIPS ports currently do not).  We can deal with
> > 	  the kernel later.
> 
> Probably better not to define the functions for #ifdef KERNEL
> and let the linker pick the problem up. (This is the current case)
> 
> 
> > 	* For the !_KERNEL version, I suggest adding a sysctl that
> > 	  has a some processor capabilities flags that you can cache.
> > 	  Add a flag that indicates presence of LL/SC.
> 
> It sounds to me like the problem needs to be solved 2 ways:
> 
> R4000:
> 	- sysctl in __cpu_simple_lock_init to determine processor
> 	  capabilities
> 	- use LL/SC along with .set mips2 as suggested by Jason
> 
> R3000:
> 	- Implement restartable atomic sequences as suggested by Nathan
> 	- syscall to send details into kernel
> 	- look at using Hash techniques to improve scalability??
> 
> Given the development is occuring on a R4000 processor at present, I will
> start with the LL/SC approach and come back to restartable atomic
> sequences after I have completed the SA and LWP functionality.

If restartable sequences prove to be faster that ll/sc on r4k+, then
I'm thinking we might want something like (which is independent of CPU
type):

 1: If sysctl(hw.ncpu) == 1, use restartable sequences
    Do we use kernel registration or designated sequences?  If the
    format, we can a sysarch() call for registration, unless we implement
    this across all kernel architectures
 2: If sysctl(machdep.have_llsc) == 1 (not implemented yet!) use LL/SC
 3: Use sysarch(TEST_AND_SET) call (not implemented yet!) or plain old
    semaphores.  Note that if we have a sysarch call, the ultrix emulation
    code can use this too.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD CDs, Support and Service:    http://www.wasabisystems.com/