From owner-p4-projects Tue Jun 18 18:13:42 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D965037B403; Tue, 18 Jun 2002 18:13:19 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 19AB137B400 for ; Tue, 18 Jun 2002 18:13:18 -0700 (PDT) Received: (from perforce@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g5J1DHH53692 for perforce@freebsd.org; Tue, 18 Jun 2002 18:13:17 -0700 (PDT) (envelope-from julian@freebsd.org) Date: Tue, 18 Jun 2002 18:13:17 -0700 (PDT) Message-Id: <200206190113.g5J1DHH53692@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to julian@freebsd.org using -f From: Julian Elischer Subject: PERFORCE change 13129 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://people.freebsd.org/~peter/p4db/chv.cgi?CH=13129 Change 13129 by julian@julian_ref on 2002/06/18 18:12:51 working on cleaning up a twisty maze of little passages, no wait.. maybe it was a maze of twisty.... Affected files ... ... //depot/projects/kse/sys/kern/kern_switch.c#51 edit ... //depot/projects/kse/sys/kern/kern_thread.c#71 edit Differences ... ==== //depot/projects/kse/sys/kern/kern_switch.c#51 (text+ko) ==== @@ -146,23 +146,31 @@ /* * Given a KSE (now surplus), either assign a new runable thread to it * (and put it in the run queue) or put it in the ksegrp's idle KSE list. + * Assumes the kse is not linked to any threads any more. (has been cleaned). */ void kse_reassign(struct kse *ke) { - struct ksegrp *kg = ke->ke_ksegrp; + struct ksegrp *kg; struct thread *td; - struct proc *p; + + kg = ke->ke_ksegrp; - ke->ke_state = KES_IDLE; /* temp state */ + /* + * Find the first unassigned thread + * If there is a 'last assigned' then see what's next. + * otherwise look at what is first. + */ if ((td = kg->kg_last_assigned)) { - /* If there is a 'last assigned' then see what's next. */ td = TAILQ_NEXT(td, td_runq); } else { td = TAILQ_FIRST(&kg->kg_runq); } + + /* + * If we found one assign it the kse, otherwise idle the kse. + */ if (td) { - p = ke->ke_proc; kg->kg_last_assigned = td; td->td_kse = ke; ke->ke_thread = td; ==== //depot/projects/kse/sys/kern/kern_thread.c#71 (text+ko) ==== @@ -174,56 +174,6 @@ } /* - * Unlink thread from its process, and reassign its KSE to another thread. - */ -static void -thread_unlink(struct thread *td) -{ - struct proc *p; - struct ksegrp *kg; - struct kse *ke; - - p = td->td_proc; - kg = td->td_ksegrp; - ke = td->td_kse; - - /* Reassign this thread's KSE. */ - if (ke != NULL) { - ke->ke_thread = NULL; - td->td_kse = NULL; - ke->ke_state = KES_UNQUEUED; - kse_reassign(ke); - } - - /* Unlink this thread from its proc. */ - if (p != NULL) { - TAILQ_REMOVE(&p->p_threads, td, td_plist); - if (kg != NULL) - TAILQ_REMOVE(&kg->kg_threads, td, td_kglist); - p->p_numthreads--; -#if 0 - if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) { - if (p->p_numthreads == ((p->p_flag & P_SINGLE_EXIT) ? - 1 : p->p_suspcount)) { - TAILQ_REMOVE(&p->p_suspended, - p->p_singlethread, td_runq); - setrunqueue(p->p_singlethread); - p->suspcount--; - } - } -#else - thread_unsuspend(p); /* see if it is there yet */ -#endif - } - if (kg != NULL) - kg->kg_numthreads--; - td->td_state = TDS_SURPLUS; - td->td_proc = NULL; - td->td_ksegrp = NULL; - td->td_last_kse = NULL; -} - -/* * Initialize global thread allocation resources. */ void @@ -343,10 +293,14 @@ struct thread *td; struct kse *ke; struct proc *p; + struct ksegrp *kg; td = curthread; + kg = td->td_ksegrp; p = td->td_proc; ke = td->td_kse; + + mtx_assert(&sched_lock, MA_OWNED); PROC_LOCK_ASSERT(p, MA_OWNED); CTR1(KTR_PROC, "thread_exit: thread %p", td); KASSERT(!mtx_owned(&Giant), ("dying thread owns giant")); @@ -356,7 +310,43 @@ ke->ke_tdspare = NULL; } cpu_thread_exit(td); /* XXXSMP */ - thread_unlink(td); /* Remember that this reassigns the KSE */ + + /* Reassign this thread's KSE. */ + if (ke != NULL) { + ke->ke_thread = NULL; + td->td_kse = NULL; + ke->ke_state = KES_UNQUEUED; + kse_reassign(ke); + } + + /* Unlink this thread from its proc. and the kseg */ + if (p != NULL) { + TAILQ_REMOVE(&p->p_threads, td, td_plist); + p->p_numthreads--; + if (kg != NULL) { + TAILQ_REMOVE(&kg->kg_threads, td, td_kglist); + kg->kg_numthreads--; + } +#if 0 + if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) { + if (p->p_numthreads == ((p->p_flag & P_SINGLE_EXIT) ? + 1 : p->p_suspcount)) { + TAILQ_REMOVE(&p->p_suspended, + p->p_singlethread, td_runq); + setrunqueue(p->p_singlethread); + p->suspcount--; + } + } +#else + thread_unsuspend(p); /* see if it is there yet */ +#endif + } + if (kg != NULL) + kg->kg_numthreads--; + td->td_state = TDS_SURPLUS; + td->td_proc = NULL; + td->td_ksegrp = NULL; + td->td_last_kse = NULL; ke->ke_tdspare = td; PROC_UNLOCK(p); cpu_throw(); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message