2 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * Each cpu in a system has its own self-contained light weight kernel
27 * thread scheduler, which means that generally speaking we only need
28 * to use a critical section to prevent hicups.
30 * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.12 2003/06/30 19:50:31 dillon Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/rtprio.h>
38 #include <sys/queue.h>
39 #include <sys/thread2.h>
40 #include <sys/sysctl.h>
41 #include <sys/kthread.h>
42 #include <machine/cpu.h>
46 #include <vm/vm_param.h>
47 #include <vm/vm_kern.h>
48 #include <vm/vm_object.h>
49 #include <vm/vm_page.h>
50 #include <vm/vm_map.h>
51 #include <vm/vm_pager.h>
52 #include <vm/vm_extern.h>
53 #include <vm/vm_zone.h>
55 #include <machine/stdarg.h>
57 static int untimely_switch = 0;
58 SYSCTL_INT(_lwkt, OID_AUTO, untimely_switch, CTLFLAG_RW, &untimely_switch, 0, "");
59 static quad_t switch_count = 0;
60 SYSCTL_QUAD(_lwkt, OID_AUTO, switch_count, CTLFLAG_RW, &switch_count, 0, "");
61 static quad_t preempt_hit = 0;
62 SYSCTL_QUAD(_lwkt, OID_AUTO, preempt_hit, CTLFLAG_RW, &preempt_hit, 0, "");
63 static quad_t preempt_miss = 0;
64 SYSCTL_QUAD(_lwkt, OID_AUTO, preempt_miss, CTLFLAG_RW, &preempt_miss, 0, "");
65 static quad_t preempt_weird = 0;
66 SYSCTL_QUAD(_lwkt, OID_AUTO, preempt_weird, CTLFLAG_RW, &preempt_weird, 0, "");
69 * These helper procedures handle the runq, they can only be called from
70 * within a critical section.
74 _lwkt_dequeue(thread_t td)
76 if (td->td_flags & TDF_RUNQ) {
77 int nq = td->td_pri & TDPRI_MASK;
78 struct globaldata *gd = mycpu;
80 td->td_flags &= ~TDF_RUNQ;
81 TAILQ_REMOVE(&gd->gd_tdrunq[nq], td, td_threadq);
82 /* runqmask is passively cleaned up by the switcher */
88 _lwkt_enqueue(thread_t td)
90 if ((td->td_flags & TDF_RUNQ) == 0) {
91 int nq = td->td_pri & TDPRI_MASK;
92 struct globaldata *gd = mycpu;
94 td->td_flags |= TDF_RUNQ;
95 TAILQ_INSERT_TAIL(&gd->gd_tdrunq[nq], td, td_threadq);
96 gd->gd_runqmask |= 1 << nq;
99 * YYY needs cli/sti protection? gd_reqpri set by interrupt
100 * when made pending. need better mechanism.
102 if (gd->gd_reqpri < (td->td_pri & TDPRI_MASK))
103 gd->gd_reqpri = (td->td_pri & TDPRI_MASK);
109 * LWKTs operate on a per-cpu basis
111 * YYY implement strict priorities & round-robin at the same priority
114 lwkt_gdinit(struct globaldata *gd)
118 for (i = 0; i < sizeof(gd->gd_tdrunq)/sizeof(gd->gd_tdrunq[0]); ++i)
119 TAILQ_INIT(&gd->gd_tdrunq[i]);
124 * Initialize a thread wait structure prior to first use.
126 * NOTE! called from low level boot code, we cannot do anything fancy!
129 lwkt_init_wait(lwkt_wait_t w)
131 TAILQ_INIT(&w->wa_waitq);
135 * Create a new thread. The thread must be associated with a process context
136 * or LWKT start address before it can be scheduled.
138 * If you intend to create a thread without a process context this function
139 * does everything except load the startup and switcher function.
142 lwkt_alloc_thread(struct thread *td)
149 if (mycpu->gd_tdfreecount > 0) {
150 --mycpu->gd_tdfreecount;
151 td = TAILQ_FIRST(&mycpu->gd_tdfreeq);
152 KASSERT(td != NULL && (td->td_flags & TDF_EXITED),
153 ("lwkt_alloc_thread: unexpected NULL or corrupted td"));
154 TAILQ_REMOVE(&mycpu->gd_tdfreeq, td, td_threadq);
156 stack = td->td_kstack;
157 flags = td->td_flags & (TDF_ALLOCATED_STACK|TDF_ALLOCATED_THREAD);
160 td = zalloc(thread_zone);
161 td->td_kstack = NULL;
162 flags |= TDF_ALLOCATED_THREAD;
165 if ((stack = td->td_kstack) == NULL) {
166 stack = (void *)kmem_alloc(kernel_map, UPAGES * PAGE_SIZE);
167 flags |= TDF_ALLOCATED_STACK;
169 lwkt_init_thread(td, stack, flags, mycpu);
174 * Initialize a preexisting thread structure. This function is used by
175 * lwkt_alloc_thread() and also used to initialize the per-cpu idlethread.
177 * NOTE! called from low level boot code, we cannot do anything fancy!
180 lwkt_init_thread(thread_t td, void *stack, int flags, struct globaldata *gd)
182 bzero(td, sizeof(struct thread));
183 td->td_kstack = stack;
184 td->td_flags |= flags;
186 td->td_pri = TDPRI_CRIT;
187 pmap_init_thread(td);
191 lwkt_free_thread(struct thread *td)
193 KASSERT(td->td_flags & TDF_EXITED,
194 ("lwkt_free_thread: did not exit! %p", td));
197 if (mycpu->gd_tdfreecount < CACHE_NTHREADS &&
198 (td->td_flags & TDF_ALLOCATED_THREAD)
200 ++mycpu->gd_tdfreecount;
201 TAILQ_INSERT_HEAD(&mycpu->gd_tdfreeq, td, td_threadq);
205 if (td->td_kstack && (td->td_flags & TDF_ALLOCATED_STACK)) {
206 kmem_free(kernel_map,
207 (vm_offset_t)td->td_kstack, UPAGES * PAGE_SIZE);
208 td->td_kstack = NULL;
210 if (td->td_flags & TDF_ALLOCATED_THREAD)
211 zfree(thread_zone, td);
217 * Switch to the next runnable lwkt. If no LWKTs are runnable then
218 * switch to the idlethread. Switching must occur within a critical
219 * section to avoid races with the scheduling queue.
221 * We always have full control over our cpu's run queue. Other cpus
222 * that wish to manipulate our queue must use the cpu_*msg() calls to
223 * talk to our cpu, so a critical section is all that is needed and
224 * the result is very, very fast thread switching.
226 * We always 'own' our own thread and the threads on our run queue,l
227 * due to TDF_RUNNING or TDF_RUNQ being set. We can safely clear
228 * TDF_RUNNING while in a critical section.
230 * The td_switch() function must be called while in the critical section.
231 * This function saves as much state as is appropriate for the type of
234 * (self contained on a per cpu basis)
239 struct globaldata *gd;
240 thread_t td = curthread;
243 if (mycpu->gd_intr_nesting_level && td->td_preempted == NULL)
244 panic("lwkt_switch: cannot switch from within an interrupt, yet\n");
248 if ((ntd = td->td_preempted) != NULL) {
250 * We had preempted another thread on this cpu, resume the preempted
251 * thread. This occurs transparently, whether the preempted thread
252 * was scheduled or not (it may have been preempted after descheduling
255 KKASSERT(ntd->td_flags & TDF_PREEMPT_LOCK);
256 ntd->td_flags |= TDF_PREEMPT_DONE;
259 * Priority queue / round-robin at each priority. Note that user
260 * processes run at a fixed, low priority and the user process
261 * scheduler deals with interactions between user processes
262 * by scheduling and descheduling them from the LWKT queue as
268 if (gd->gd_runqmask) {
269 int nq = bsrl(gd->gd_runqmask);
270 if ((ntd = TAILQ_FIRST(&gd->gd_tdrunq[nq])) == NULL) {
271 gd->gd_runqmask &= ~(1 << nq);
274 TAILQ_REMOVE(&gd->gd_tdrunq[nq], ntd, td_threadq);
275 TAILQ_INSERT_TAIL(&gd->gd_tdrunq[nq], ntd, td_threadq);
280 KASSERT(ntd->td_pri >= TDPRI_CRIT,
281 ("priority problem in lwkt_switch %d %d", td->td_pri, ntd->td_pri));
288 * Request that the target thread preempt the current thread. This only
291 * + We aren't trying to preempt ourselves (it can happen!)
292 * + We are not currently being preempted
293 * + the target is not currently being preempted
295 * XXX at the moment we run the target thread in a critical section during
296 * the preemption in order to prevent the target from taking interrupts
297 * that *WE* can't. Preemption is strictly limited to interrupt threads
298 * and interrupt-like threads, outside of a critical section, and the
299 * preempted source thread will be resumed the instant the target blocks
300 * whether or not the source is scheduled (i.e. preemption is supposed to
301 * be as transparent as possible).
303 * This call is typically made from an interrupt handler like sched_ithd()
304 * which will only run if the current thread is not in a critical section,
305 * so we optimize the priority check a bit.
307 * CAREFUL! either we or the target thread may get interrupted during the
311 lwkt_preempt(struct thread *ntd, int id)
313 struct thread *td = curthread;
316 * The caller has put us in a critical section, and in order to have
317 * gotten here in the first place the thread the caller interrupted
318 * cannot have been in a critical section before.
320 KASSERT(ntd->td_pri >= TDPRI_CRIT, ("BADCRIT0 %d", ntd->td_pri));
321 KASSERT((td->td_pri & ~TDPRI_MASK) == TDPRI_CRIT, ("BADPRI %d", td->td_pri));
323 if (td == ntd || ((td->td_flags | ntd->td_flags) & TDF_PREEMPT_LOCK)) {
327 if (ntd->td_preempted) {
331 if ((ntd->td_pri & TDPRI_MASK) <= (td->td_pri & TDPRI_MASK)) {
337 ntd->td_preempted = td;
338 td->td_flags |= TDF_PREEMPT_LOCK;
340 KKASSERT(ntd->td_preempted && (td->td_flags & TDF_PREEMPT_DONE));
341 ntd->td_preempted = NULL;
342 td->td_flags &= ~(TDF_PREEMPT_LOCK|TDF_PREEMPT_DONE);
346 * Yield our thread while higher priority threads are pending. This is
347 * typically called when we leave a critical section but it can be safely
348 * called while we are in a critical section.
350 * This function will not generally yield to equal priority threads but it
351 * can occur as a side effect. Note that lwkt_switch() is called from
352 * inside the critical section to pervent its own crit_exit() from reentering
353 * lwkt_yield_quick().
355 * gd_reqpri indicates that *something* changed, e.g. an interrupt or softint
356 * came along but was blocked and made pending.
358 * (self contained on a per cpu basis)
361 lwkt_yield_quick(void)
363 thread_t td = curthread;
365 if ((td->td_pri & TDPRI_MASK) < mycpu->gd_reqpri) {
366 mycpu->gd_reqpri = 0;
371 * YYY enabling will cause wakeup() to task-switch, which really
372 * confused the old 4.x code. This is a good way to simulate
373 * preemption and MP without actually doing preemption or MP, because a
374 * lot of code assumes that wakeup() does not block.
376 if (untimely_switch && mycpu->gd_intr_nesting_level == 0) {
379 * YYY temporary hacks until we disassociate the userland scheduler
380 * from the LWKT scheduler.
382 if (td->td_flags & TDF_RUNQ) {
383 lwkt_switch(); /* will not reenter yield function */
385 lwkt_schedule_self(); /* make sure we are scheduled */
386 lwkt_switch(); /* will not reenter yield function */
387 lwkt_deschedule_self(); /* make sure we are descheduled */
394 * This implements a normal yield which, unlike _quick, will yield to equal
395 * priority threads as well. Note that gd_reqpri tests will be handled by
396 * the crit_exit() call in lwkt_switch().
398 * (self contained on a per cpu basis)
403 lwkt_schedule_self();
408 * Schedule a thread to run. As the current thread we can always safely
409 * schedule ourselves, and a shortcut procedure is provided for that
412 * (non-blocking, self contained on a per cpu basis)
415 lwkt_schedule_self(void)
417 thread_t td = curthread;
420 KASSERT(td->td_wait == NULL, ("lwkt_schedule_self(): td_wait not NULL!"));
422 if (td->td_proc && td->td_proc->p_stat == SSLEEP)
423 panic("SCHED SELF PANIC");
428 * Generic schedule. Possibly schedule threads belonging to other cpus and
429 * deal with threads that might be blocked on a wait queue.
431 * This function will queue requests asynchronously when possible, but may
432 * block if no request structures are available. Upon return the caller
433 * should note that the scheduling request may not yet have been processed
436 * YYY this is one of the best places to implement any load balancing code.
437 * Load balancing can be accomplished by requesting other sorts of actions
438 * for the thread in question.
441 lwkt_schedule(thread_t td)
443 if ((td->td_flags & TDF_PREEMPT_LOCK) == 0 && td->td_proc
444 && td->td_proc->p_stat == SSLEEP
446 printf("PANIC schedule curtd = %p (%d %d) target %p (%d %d)\n",
448 curthread->td_proc ? curthread->td_proc->p_pid : -1,
449 curthread->td_proc ? curthread->td_proc->p_stat : -1,
451 td->td_proc ? curthread->td_proc->p_pid : -1,
452 td->td_proc ? curthread->td_proc->p_stat : -1
454 panic("SCHED PANIC");
457 if (td == curthread) {
463 * If the thread is on a wait list we have to send our scheduling
464 * request to the owner of the wait structure. Otherwise we send
465 * the scheduling request to the cpu owning the thread. Races
466 * are ok, the target will forward the message as necessary (the
467 * message may chase the thread around before it finally gets
470 * (remember, wait structures use stable storage)
472 if ((w = td->td_wait) != NULL) {
473 if (lwkt_havetoken(&w->wa_token)) {
474 TAILQ_REMOVE(&w->wa_waitq, td, td_threadq);
477 if (td->td_cpu == mycpu->gd_cpuid) {
480 panic("lwkt_schedule: cpu mismatch1");
482 lwkt_cpu_msg_union_t msg = lwkt_getcpumsg();
483 initScheduleReqMsg_Wait(&msg.mu_SchedReq, td, w);
484 cpu_sendnormsg(&msg.mu_Msg);
488 panic("lwkt_schedule: cpu mismatch2");
490 lwkt_cpu_msg_union_t msg = lwkt_getcpumsg();
491 initScheduleReqMsg_Wait(&msg.mu_SchedReq, td, w);
492 cpu_sendnormsg(&msg.mu_Msg);
497 * If the wait structure is NULL and we own the thread, there
498 * is no race (since we are in a critical section). If we
499 * do not own the thread there might be a race but the
500 * target cpu will deal with it.
502 if (td->td_cpu == mycpu->gd_cpuid) {
505 panic("lwkt_schedule: cpu mismatch3");
507 lwkt_cpu_msg_union_t msg = lwkt_getcpumsg();
508 initScheduleReqMsg_Thread(&msg.mu_SchedReq, td);
509 cpu_sendnormsg(&msg.mu_Msg);
518 * Deschedule a thread.
520 * (non-blocking, self contained on a per cpu basis)
523 lwkt_deschedule_self(void)
525 thread_t td = curthread;
528 KASSERT(td->td_wait == NULL, ("lwkt_schedule_self(): td_wait not NULL!"));
534 * Generic deschedule. Descheduling threads other then your own should be
535 * done only in carefully controlled circumstances. Descheduling is
538 * This function may block if the cpu has run out of messages.
541 lwkt_deschedule(thread_t td)
544 if (td == curthread) {
547 if (td->td_cpu == mycpu->gd_cpuid) {
550 panic("lwkt_deschedule: cpu mismatch");
552 lwkt_cpu_msg_union_t msg = lwkt_getcpumsg();
553 initDescheduleReqMsg_Thread(&msg.mu_DeschedReq, td);
554 cpu_sendnormsg(&msg.mu_Msg);
562 * Set the target thread's priority. This routine does not automatically
563 * switch to a higher priority thread, LWKT threads are not designed for
564 * continuous priority changes. Yield if you want to switch.
566 * We have to retain the critical section count which uses the high bits
567 * of the td_pri field. The specified priority may also indicate zero or
568 * more critical sections by adding TDPRI_CRIT*N.
571 lwkt_setpri(thread_t td, int pri)
575 if (td->td_flags & TDF_RUNQ) {
577 td->td_pri = (td->td_pri & ~TDPRI_MASK) + pri;
580 td->td_pri = (td->td_pri & ~TDPRI_MASK) + pri;
586 lwkt_setpri_self(int pri)
588 thread_t td = curthread;
590 KKASSERT(pri >= 0 && pri <= TDPRI_MAX);
592 if (td->td_flags & TDF_RUNQ) {
594 td->td_pri = (td->td_pri & ~TDPRI_MASK) + pri;
597 td->td_pri = (td->td_pri & ~TDPRI_MASK) + pri;
603 lwkt_preempted_proc(void)
605 struct thread *td = curthread;
606 while (td->td_preempted)
607 td = td->td_preempted;
613 * This function deschedules the current thread and blocks on the specified
614 * wait queue. We obtain ownership of the wait queue in order to block
615 * on it. A generation number is used to interlock the wait queue in case
616 * it gets signalled while we are blocked waiting on the token.
618 * Note: alternatively we could dequeue our thread and then message the
619 * target cpu owning the wait queue. YYY implement as sysctl.
621 * Note: wait queue signals normally ping-pong the cpu as an optimization.
624 lwkt_block(lwkt_wait_t w, const char *wmesg, int *gen)
626 thread_t td = curthread;
628 lwkt_gettoken(&w->wa_token);
629 if (w->wa_gen == *gen) {
631 TAILQ_INSERT_TAIL(&w->wa_waitq, td, td_threadq);
634 td->td_wmesg = wmesg;
637 /* token might be lost, doesn't matter for gen update */
639 lwkt_reltoken(&w->wa_token);
643 * Signal a wait queue. We gain ownership of the wait queue in order to
644 * signal it. Once a thread is removed from the wait queue we have to
645 * deal with the cpu owning the thread.
647 * Note: alternatively we could message the target cpu owning the wait
648 * queue. YYY implement as sysctl.
651 lwkt_signal(lwkt_wait_t w)
656 lwkt_gettoken(&w->wa_token);
659 while ((td = TAILQ_FIRST(&w->wa_waitq)) != NULL && count) {
662 TAILQ_REMOVE(&w->wa_waitq, td, td_threadq);
665 if (td->td_cpu == mycpu->gd_cpuid) {
669 lwkt_cpu_msg_union_t msg = lwkt_getcpumsg();
670 initScheduleReqMsg_Thread(&msg.mu_SchedReq, td);
671 cpu_sendnormsg(&msg.mu_Msg);
673 panic("lwkt_signal: cpu mismatch");
675 lwkt_regettoken(&w->wa_token);
677 lwkt_reltoken(&w->wa_token);
681 * Aquire ownership of a token
683 * Aquire ownership of a token. The token may have spl and/or critical
684 * section side effects, depending on its purpose. These side effects
685 * guarentee that you will maintain ownership of the token as long as you
686 * do not block. If you block you may lose access to the token (but you
687 * must still release it even if you lose your access to it).
689 * Note that the spl and critical section characteristics of a token
690 * may not be changed once the token has been initialized.
693 lwkt_gettoken(lwkt_token_t tok)
696 * Prevent preemption so the token can't be taken away from us once
697 * we gain ownership of it. Use a synchronous request which might
698 * block. The request will be forwarded as necessary playing catchup
703 while (tok->t_cpu != mycpu->gd_cpuid) {
704 lwkt_cpu_msg_union msg;
705 initTokenReqMsg(&msg.mu_TokenReq);
710 * leave us in a critical section on return. This will be undone
716 * Release your ownership of a token. Releases must occur in reverse
717 * order to aquisitions, eventually so priorities can be unwound properly
718 * like SPLs. At the moment the actual implemention doesn't care.
720 * We can safely hand a token that we own to another cpu without notifying
721 * it, but once we do we can't get it back without requesting it (unless
722 * the other cpu hands it back to us before we check).
724 * We might have lost the token, so check that.
727 lwkt_reltoken(lwkt_token_t tok)
729 if (tok->t_cpu == mycpu->gd_cpuid) {
730 tok->t_cpu = tok->t_reqcpu;
736 * Reaquire a token that might have been lost. Returns 1 if we blocked
737 * while reaquiring the token (meaning that you might have lost other
738 * tokens you held when you made this call), return 0 if we did not block.
741 lwkt_regettoken(lwkt_token_t tok)
744 if (tok->t_cpu != mycpu->gd_cpuid) {
745 while (tok->t_cpu != mycpu->gd_cpuid) {
746 lwkt_cpu_msg_union msg;
747 initTokenReqMsg(&msg.mu_TokenReq);
757 * Create a kernel process/thread/whatever. It shares it's address space
758 * with proc0 - ie: kernel only.
760 * XXX should be renamed to lwkt_create()
763 lwkt_create(void (*func)(void *), void *arg,
764 struct thread **tdp, struct thread *template, int tdflags,
765 const char *fmt, ...)
770 td = *tdp = lwkt_alloc_thread(template);
771 cpu_set_thread_handler(td, kthread_exit, func, arg);
772 td->td_flags |= TDF_VERBOSE | tdflags;
775 * Set up arg0 for 'ps' etc
778 vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap);
782 * Schedule the thread to run
784 if ((td->td_flags & TDF_STOPREQ) == 0)
787 td->td_flags &= ~TDF_STOPREQ;
792 * Destroy an LWKT thread. Warning! This function is not called when
793 * a process exits, cpu_proc_exit() directly calls cpu_thread_exit() and
794 * uses a different reaping mechanism.
799 thread_t td = curthread;
801 if (td->td_flags & TDF_VERBOSE)
802 printf("kthread %p %s has exited\n", td, td->td_comm);
804 lwkt_deschedule_self();
805 ++mycpu->gd_tdfreecount;
806 TAILQ_INSERT_TAIL(&mycpu->gd_tdfreeq, td, td_threadq);
811 * Create a kernel process/thread/whatever. It shares it's address space
812 * with proc0 - ie: kernel only. 5.x compatible.
815 kthread_create(void (*func)(void *), void *arg,
816 struct thread **tdp, const char *fmt, ...)
821 td = *tdp = lwkt_alloc_thread(NULL);
822 cpu_set_thread_handler(td, kthread_exit, func, arg);
823 td->td_flags |= TDF_VERBOSE;
826 * Set up arg0 for 'ps' etc
829 vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap);
833 * Schedule the thread to run
842 struct thread *td = curthread;
843 int lpri = td->td_pri;
846 panic("td_pri is/would-go negative! %p %d", td, lpri);
850 * Destroy an LWKT thread. Warning! This function is not called when
851 * a process exits, cpu_proc_exit() directly calls cpu_thread_exit() and
852 * uses a different reaping mechanism.
854 * XXX duplicates lwkt_exit()