Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jun 2002 00:25:12 -0700 (PDT)
From:      Julian Elischer <julian@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 13103 for review
Message-ID:  <200206180725.g5I7PCQ51323@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=13103

Change 13103 by julian@julian_ref on 2002/06/18 00:24:27

	Start cleaning up the mess I made when I changed APIs.
	still doesn't quite work, but I've tracked down a lot of brainos
	including a couple I haven't fixed yet.

Affected files ...

... //depot/projects/kse/sys/alpha/alpha/trap.c#26 edit
... //depot/projects/kse/sys/i386/i386/swtch.s#34 edit
... //depot/projects/kse/sys/i386/i386/trap.c#51 edit
... //depot/projects/kse/sys/i386/i386/vm_machdep.c#57 edit
... //depot/projects/kse/sys/kern/init_main.c#42 edit
... //depot/projects/kse/sys/kern/kern_exit.c#54 edit
... //depot/projects/kse/sys/kern/kern_fork.c#70 edit
... //depot/projects/kse/sys/kern/kern_proc.c#70 edit
... //depot/projects/kse/sys/kern/kern_thread.c#70 edit
... //depot/projects/kse/sys/sparc64/sparc64/trap.c#30 edit

Differences ...

==== //depot/projects/kse/sys/alpha/alpha/trap.c#26 (text+ko) ====

@@ -301,6 +301,7 @@
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
 		if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
+			mtx_lock_spin(&sched_lock);
 			PROC_LOCK(p);
 			thread_exit();
 			/* NOTREACHED */

==== //depot/projects/kse/sys/i386/i386/swtch.s#34 (text+ko) ====

@@ -317,12 +317,14 @@
 
 #ifdef INVARIANTS
 badsw2:
+	pushal
 	pushl	$sw0_2
 	call	panic
 
 sw0_2:	.asciz	"cpu_switch: not TDS_RUNQ"
 
 badsw3:
+	pushal
 	pushl	$sw0_3
 	call	panic
 

==== //depot/projects/kse/sys/i386/i386/trap.c#51 (text+ko) ====

@@ -270,9 +270,10 @@
 
 		/*
 		 * First check that we shouldn't just abort.
-		 * But check if the are the single thread first!
+		 * But check if we are the single thread first!
 		 */
 		if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
+			mtx_lock_spin(&sched_lock);
 			PROC_LOCK(p);
 			thread_exit();
 			/* NOTREACHED */

==== //depot/projects/kse/sys/i386/i386/vm_machdep.c#57 (text+ko) ====

@@ -325,8 +325,11 @@
 	/* XXXKSE this may be un-needed */
 	bcopy(td->td_pcb, newkse->ke_pcb, sizeof(struct pcb));
 
-	/* This copies most of the user mode register values. */
-	bzero(newkse->ke_frame, sizeof(struct trapframe));
+	/*
+	 * This initialises most of the user mode register values
+	 * to good values. Eventually set them explicitly to know values
+	 */
+	bcopy(td->td_frame, newkse->ke_frame, sizeof(struct trapframe));
 	tf->tf_edi = 0;
 	tf->tf_esi = 0;		    /* trampoline arg */
 	tf->tf_ebp = 0;

==== //depot/projects/kse/sys/kern/init_main.c#42 (text+ko) ====

@@ -323,6 +323,12 @@
 	p->p_sysent = &aout_sysvec;
 #endif
 
+	/*
+	 * proc_linkup was already done in init_i386() or alphainit() etc.
+	 * because the earlier code needed to follow td->td_proc. Otherwise
+	 * I would have done it here.. maybe this means this should be
+	 * done earlier too.
+	 */
 	ke = &proc0.p_kse;	/* XXXKSE */
 	kg = &proc0.p_ksegrp;	/* XXXKSE */
 	p->p_flag = P_SYSTEM;

==== //depot/projects/kse/sys/kern/kern_exit.c#54 (text+ko) ====

@@ -547,6 +547,8 @@
 	register int nfound;
 	register struct proc *p, *q, *t;
 	int status, error;
+	struct kse *ke;
+	struct ksegrp *kg;
 
 	q = td->td_proc;
 	if (uap->pid == 0) {
@@ -603,7 +605,6 @@
 				mtx_unlock_spin(&sched_lock);
 			}
 
-			thread_reap();	/* check for zombie threads */
 			td->td_retval[0] = p->p_pid;
 #ifdef COMPAT_43
 			if (compat)
@@ -700,9 +701,20 @@
 				p->p_procsig = NULL;
 			}
 
-			/* Free the KSE spare thread. */
-			if (p->p_kse.ke_tdspare != NULL)
-				thread_free(p->p_kse.ke_tdspare);
+			/*
+			 * There should only be one KSE/KSEGRP but
+			 * do it right anyhow.
+			 */
+			FOREACH_KSEGRP_IN_PROC(p, kg) {
+				FOREACH_KSE_IN_GROUP(kg, ke) {
+					/* Free the KSE spare thread. */
+					if (ke->ke_tdspare != NULL) {
+						thread_free(ke->ke_tdspare);
+						p->p_kse.ke_tdspare = NULL;
+					}
+				}
+			}
+			thread_reap();	/* check for zombie threads */
 
 			/*
 			 * Give vm and machine-dependent layer a chance

==== //depot/projects/kse/sys/kern/kern_fork.c#70 (text+ko) ====

@@ -513,7 +513,7 @@
 	TAILQ_REMOVE(&kg2->kg_iq, ke2, ke_kgrlist);
 	ke2->ke_state = KES_UNQUEUED;
 	kg2->kg_idle_kses--;
-	td2->td_flags &= ~TDF_UNBOUND; /* For the rest of this sycall. */
+	td2->td_flags &= ~TDF_UNBOUND; /* For the rest of this syscall. */
 
 	/* note.. XXXKSE no pcb or u-area yet */
 

==== //depot/projects/kse/sys/kern/kern_proc.c#70 (text+ko) ====

@@ -218,8 +218,10 @@
 	int err;
 
 	p = td->td_proc;
+printf("got here 0\n");
 	if ((err = copyin(uap->mbx, &mbx, sizeof(mbx))))
 		return (err);
+printf("got here 1\n");
 	PROC_LOCK(p);
 	/*
 	 * If we have no KSE mode set, just set it, and skip KSE and KSEGRP
@@ -246,6 +248,7 @@
 		 */
 		newkse = td->td_kse;
 	}
+printf("got here 2\n");
 	/*
 	 * Fill out the KSE-mode specific fields of the new kse.
 	 */
@@ -261,7 +264,7 @@
 	cpu_save_upcall(td, newkse);
 	PROC_UNLOCK(p);
 	/* Note that we are the returning syscall */
-	td->td_retval[0] = 1;
+	td->td_retval[0] = 0;
 	td->td_retval[1] = 0;
 
 	if ((td->td_proc->p_flag & P_KSES) || (uap->new_grp_flag)) {

==== //depot/projects/kse/sys/kern/kern_thread.c#70 (text+ko) ====

@@ -254,15 +254,21 @@
 {
 	struct thread *td_reaped;
 
-	mtx_lock_spin(&zombie_thread_lock);
-	while (!TAILQ_EMPTY(&zombie_threads)) {
-		td_reaped = TAILQ_FIRST(&zombie_threads);
-		TAILQ_REMOVE(&zombie_threads, td_reaped, td_runq);
+	/*
+	 * don't even bother to lock if none at this instant
+	 * We really don't care about the next instant..
+	 */
+	if (!TAILQ_EMPTY(&zombie_threads)) {
+		mtx_lock_spin(&zombie_thread_lock);
+		while (!TAILQ_EMPTY(&zombie_threads)) {
+			td_reaped = TAILQ_FIRST(&zombie_threads);
+			TAILQ_REMOVE(&zombie_threads, td_reaped, td_runq);
+			mtx_unlock_spin(&zombie_thread_lock);
+			thread_free(td_reaped);
+			mtx_lock_spin(&zombie_thread_lock);
+		}
 		mtx_unlock_spin(&zombie_thread_lock);
-		thread_free(td_reaped);
-		mtx_lock_spin(&zombie_thread_lock);
 	}
-	mtx_unlock_spin(&zombie_thread_lock);
 }
 
 /*
@@ -347,9 +353,10 @@
 
 	if (ke->ke_tdspare != NULL) {
 		thread_stash(ke->ke_tdspare);
+		ke->ke_tdspare = NULL;
 	}
 	cpu_thread_exit(td);	/* XXXSMP */
-	thread_unlink(td);
+	thread_unlink(td); 	/* Remember that this reassigns the KSE */
 	ke->ke_tdspare = td;
 	PROC_UNLOCK(p);
 	cpu_throw();
@@ -405,7 +412,8 @@
 	     td, td->td_proc->p_pid, td->td_proc->p_comm);
 	thread_link(td2, ke->ke_ksegrp);
 	cpu_set_upcall(td2, ke->ke_pcb);
-printf("thread_schedule_upcall: Scheduled td %p kse %p\n", td2, ke);
+printf("thread_schedule_upcall: Scheduled td %p, my td %p, kse %p\n",
+td2, td, ke);
 	td2->td_ucred = crhold(td->td_ucred);
 	td2->td_kse = NULL;	/* Back as it was. */
 	td2->td_flags = TDF_UNBOUND|TDF_UPCALLING;

==== //depot/projects/kse/sys/sparc64/sparc64/trap.c#30 (text+ko) ====

@@ -192,6 +192,7 @@
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
 		if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) {
+			mtx_lock_spin(&sched_lock);
 			thread_exit();
 			/* NOTREACHED */
 		}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206180725.g5I7PCQ51323>