Subject: Re: Support for atomic locks in lock.h
To: Wayne Knowles <wdk@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: port-mips
Date: 11/24/2001 19:17:13
On Sun, Nov 25, 2001 at 02:01:05PM +1300, Wayne Knowles wrote:

 > To the best of my knowledge there is no atomic locking capability in the
 > R3000 processor at all.   Given that we have architectures that use that
 > processor we cannot build using -mips2 or above.  We are faced with
 > supporting the lowest common denominator for now.

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.

	* 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.

	  Then in __cpu_simple_lock_init(), use the sysctl to fetch
	  the capflags.

	  In __cpu_simple_lock(), do this:

	  if (capflags & __MIPS_CAP_LL_SC) {
		__asm __volatile(
			"	.set push		\n"
			"	.set mips2		\n"
			/* a LL/SC loop */
			"	.set pop		\n"
			...);
	  } else {
		/* Use a system call of some sort? */
	  }

 > 4)	Work out the CPU variant in userland and use ll/sc
 > 	- Will need -mips2 compiler flag everywhere

Nope, you can use ".set push; .set mips2; ... .set pop" :-)

 > 	- Still need to support R3000

Yah, use a semaphore or something in this case.  It'll be slow, but it'll
be *correct*.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>