Subject: L_SA tweaks
To: None <tech-kern@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 06/21/2003 16:36:46
hi,

is following patch correct?

- since sa_newcachelwp() can sleep, turn L_SA off while calling it.
- don't set L_SA again in sa_upcall_userret().  i guess it is an intent of
  rev.1.14.

YAMAMOTO Takashi

Index: kern_sa.c
===================================================================
--- kern_sa.c	(revision 168)
+++ kern_sa.c	(working copy)
@@ -636,6 +636,7 @@ sa_switchcall(void *arg)
 	p = l->l_proc;
 	sa = p->p_sa;
 	sa->sa_vp = l;
+	KASSERT(l->l_flag & L_SA);
 
 	DPRINTFN(6,("sa_switchcall(%d.%d)\n", p->p_pid, l->l_lid));
 
@@ -643,7 +644,9 @@ sa_switchcall(void *arg)
 		/* Allocate the next cache LWP */
 		DPRINTFN(6,("sa_switchcall(%d.%d) allocating LWP\n",
 		    p->p_pid, l->l_lid));
+		l->l_flag &= ~L_SA;
 		sa_newcachelwp(l);
+		l->l_flag |= L_SA;
 	}
 	upcallret(l);
 }
@@ -659,6 +662,7 @@ sa_yieldcall(void *arg)
 	p = l->l_proc;
 	sa = p->p_sa;
 	sa->sa_vp = l;
+	KASSERT(l->l_flag & L_SA);
 
 	DPRINTFN(6,("sa_yieldcall(%d.%d)\n", p->p_pid, l->l_lid));
 
@@ -666,7 +670,9 @@ sa_yieldcall(void *arg)
 		/* Allocate the next cache LWP */
 		DPRINTFN(6,("sa_yieldcall(%d.%d) allocating LWP\n",
 		    p->p_pid, l->l_lid));
+		l->l_flag &= ~L_SA;
 		sa_newcachelwp(l);
+		l->l_flag |= L_SA;
 	}
 
 	sa_yield(l);
@@ -805,14 +811,12 @@ sa_upcall_userret(struct lwp *l)
 			 * Ideally, tsleep() would have a variant that took
 			 * a LWP to switch to.
 			 */
-			l->l_flag &= ~L_SA;
 			DPRINTFN(7, ("sa_upcall_userret(%d.%d) sleeping"
 			    " for stacks\n", l->l_proc->p_pid, l->l_lid));
 			tsleep((caddr_t) &sa->sa_nstacks, PWAIT|PCATCH, 
 			    "sastacks", 0);
 			if (p->p_flag & P_WEXIT)
 				lwp_exit(l);
-			l->l_flag |= L_SA;
 		}
 		l2 = sa_vp_repossess(l);