Subject: Re: splraiseipl()
To: None <tech-kern@NetBSD.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 09/19/2006 22:25:25
i've created a branch for implementing the following api.
(why a branch?  because netbt already uses splraiseipl...)

i'm slowly converting each ports.  (see doc/BRANCHES for the current status)
if anyone can help, please step up.

YAMAMOTO Takashi

> how about having another opaque type as the following?
> 
> - make sure that each IPL_xxx has different values, so that they can
>   be converted to SPL_xxx when necessary.
> - move a possibly slow part of splraiseipl (eg. IPL_xxx -> SPL_xxx conversion)
>   into another function, makeiplcookie(), so that it isn't executed
>   frequently.
> 
> 	/*
> 	 * ipl_t: IPL_BIO, IPL_NET, ....
> 	 *
> 	 * MD type.  maybe int for all ports.
> 	 */
> 	typedef int ipl_t;
> 
> 	/*
> 	 * ipl_cookie_t:
> 	 *
> 	 * MD type.
> 	 *
> 	 * for some ports, it can be the same as ipl_t.
> 	 * for other ports, it can be SPL_xxx, PSL_xxx, etc.
> 	 */
> 	typedef xxx ipl_cookie_t;
> 
> 	int splraiseipl(ipl_cookie_t);
> 
> 	/*
> 	 * makeiplcookie:
> 	 *
> 	 * calculate a cookie for splraiseipl.
> 	 *
> 	 * for some ports, this might do IPL_xxx -> SPL_xxx conversion.
> 	 */
> 	ipl_cookie_t makeiplcookie(ipl_t);
> 
> 
> the following is an example of their usage.
> 
> 	typedef struct {
> 		ipl_cookie_t iplcookie;
> 		int savedipl;
> 		struct simplelock lock;
> 	} lock_t; /* a simple ipl-protected spin lock */
> 
> 	void
> 	lk_init(lock_t *lk, ipl_t ipl)
> 	{
> 
> 		lk->iplcookie = makeiplcookie(ipl);
> 		simple_lock_init(&lk->lock);
> 	}
> 
> 	void
> 	lk_acquire(lock_t *lk)
> 	{
> 		int s = splraiseipl(lk->iplcookie);
> 		simple_lock(&lk->lock);
> 		lk->savedipl = s;
> 	}
> 
> 	void
> 	lk_release(lock_t *lk)
> 	{
> 		int s = lk->savedipl;
> 		simple_unlock(&lk->lock);
> 		splx(s);
> 	}
> 
> YAMAMOTO Takashi