Subject: Re: New spl level: splsched()
To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Eduardo E. Horvath <eeh@one-o.com>
List: tech-kern
Date: 03/06/1997 10:18:51
On Wed, 5 Mar 1997, Jason Thorpe wrote:

> I would like to see some of these changes made, tho... basically,
> I think that we should start using things like:
> 
> 	mutex_enter(...);
> 
> 	/* do stuff */
> 
> 	mutex_exit(...);
> 
> For now, these could be implemented something like:
> 
> typedef	int	mutex_t;
> 
> #define	mutex_enter(m)	(m) = splwhatever()
> #define	mutex_exit(m)	splx((m))
> 
> ..obviously, not that simple, since you have to know which spl to go
> to... but that might be a reasonable thing to start doing, so that
> we can just drop in new guts for the mutex primitives when the kernel
> becomes multi-threaded.

Each mutex needs an associated spl because it must ensure that no
no interrupts can can occur that will attempt to access a mutex that
is held by the process that was interrupted.  Here's a better model:

typedef struct mutex {
	int spl;
	int oldspl;
} mutex_t;

#define mutex_init(m,s)		(m).spl=(s)

#define mutex_enter(m)		(m).oldspl = splraise((m).spl)
#define mutex_exit(m)		splx((m).oldspl)

You will need to replace all the spl stuff with this.  Then you can
start worrying about isolating critical sections that are not currently
protected due to our single-threaded kernel design.  

=========================================================================
Eduardo Horvath				eeh@btr.com
"Cliffs are for climbing.  That's why God invented grappling hooks."
					- Benton Frasier