From 0cfcada1ab2de5ec9d36df5da677b4b3af225de2 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 27 Jun 2003 01:53:26 +0000 Subject: [PATCH] proc->thread stage 6: kernel threads now create processless LWKT threads. A number of obvious curproc cases were removed, tsleep/wakeup was made to work with threads (wmesg, ident, and timeout features moved to threads). There are probably a few curproc cases left to fix. --- sys/bus/usb/usb.c | 4 +- sys/bus/usb/usb_port.h | 4 +- sys/dev/misc/pcic/i82365.c | 4 +- sys/dev/raid/aac/aac.c | 4 +- sys/i386/i386/genassym.c | 4 +- sys/i386/i386/swtch.s | 21 ++- sys/i386/i386/vm_machdep.c | 14 +- sys/i386/include/md_var.h | 3 +- sys/kern/kern_kthread.c | 116 ++++++------- sys/kern/kern_linker.c | 5 +- sys/kern/kern_shutdown.c | 6 +- sys/kern/kern_sig.c | 4 +- sys/kern/kern_synch.c | 251 ++++++++++++--------------- sys/kern/lwkt_thread.c | 5 +- sys/kern/sys_generic.c | 4 +- sys/kern/vfs_bio.c | 4 +- sys/kern/vfs_subr.c | 15 +- sys/kern/vfs_syscalls.c | 5 +- sys/kern/vfs_vnops.c | 4 +- sys/netinet6/in6_prefix.c | 4 +- sys/netproto/smb/smb_iod.c | 4 +- sys/platform/pc32/i386/genassym.c | 4 +- sys/platform/pc32/i386/swtch.s | 21 ++- sys/platform/pc32/i386/vm_machdep.c | 14 +- sys/platform/pc32/include/md_var.h | 3 +- sys/platform/vkernel/i386/genassym.c | 4 +- sys/sys/kthread.h | 6 +- sys/sys/proc.h | 11 +- sys/sys/thread.h | 7 +- sys/vfs/ufs/ffs_softdep.c | 18 +- 30 files changed, 294 insertions(+), 279 deletions(-) diff --git a/sys/bus/usb/usb.c b/sys/bus/usb/usb.c index cd6f5c4b0d..91e9eeea39 100644 --- a/sys/bus/usb/usb.c +++ b/sys/bus/usb/usb.c @@ -1,6 +1,6 @@ /* $NetBSD: usb.c,v 1.33 1999/11/22 21:57:09 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb.c,v 1.26.2.9 2002/11/13 15:15:22 joe Exp $ */ -/* $DragonFly: src/sys/bus/usb/usb.c,v 1.4 2003/06/25 03:55:50 dillon Exp $ */ +/* $DragonFly: src/sys/bus/usb/usb.c,v 1.5 2003/06/27 01:53:24 dillon Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -314,7 +314,7 @@ usb_event_thread(void *arg) wakeup(sc); DPRINTF(("usb_event_thread: exit\n")); - kthread_exit(0); + kthread_exit(); } int diff --git a/sys/bus/usb/usb_port.h b/sys/bus/usb/usb_port.h index 04d3b5f8d4..05ac120415 100644 --- a/sys/bus/usb/usb_port.h +++ b/sys/bus/usb/usb_port.h @@ -1,6 +1,6 @@ /* $NetBSD: usb_port.h,v 1.15 1999/11/16 12:04:28 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.25.2.7 2002/08/12 14:19:49 joe Exp $ */ -/* $DragonFly: src/sys/bus/usb/usb_port.h,v 1.3 2003/06/23 17:55:36 dillon Exp $ */ +/* $DragonFly: src/sys/bus/usb/usb_port.h,v 1.4 2003/06/27 01:53:24 dillon Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -280,7 +280,7 @@ typedef struct thread *usb_proc_ptr; #define bswap32(x) swap32(x) #define kthread_create1(function, sc, priv, string, name) #define kthread_create(create_function, sc) -#define kthread_exit(err) +#define kthread_exit() #define usb_timeout(f, d, t, h) ((h) = timeout((f), (d), (t))) #define usb_untimeout(f, d, h) untimeout((f), (d), (h)) diff --git a/sys/dev/misc/pcic/i82365.c b/sys/dev/misc/pcic/i82365.c index 46b8130016..e21410574c 100644 --- a/sys/dev/misc/pcic/i82365.c +++ b/sys/dev/misc/pcic/i82365.c @@ -1,6 +1,6 @@ /* $NetBSD: i82365.c,v 1.25 1999/10/15 06:07:27 haya Exp $ */ /* $FreeBSD: src/sys/dev/pcic/i82365.c,v 1.16.2.1 2000/05/23 03:57:02 imp Exp $ */ -/* $DragonFly: src/sys/dev/misc/pcic/Attic/i82365.c,v 1.2 2003/06/17 04:28:29 dillon Exp $ */ +/* $DragonFly: src/sys/dev/misc/pcic/Attic/i82365.c,v 1.3 2003/06/27 01:53:23 dillon Exp $ */ /* * Copyright (c) 1997 Marc Horowitz. All rights reserved. @@ -580,7 +580,7 @@ pcic_event_thread(void *arg) /* In case parent is waiting for us to exit. */ wakeup(sc); - kthread_exit(0); + kthread_exit(); } void diff --git a/sys/dev/raid/aac/aac.c b/sys/dev/raid/aac/aac.c index 63f3e30528..10ec4bda26 100644 --- a/sys/dev/raid/aac/aac.c +++ b/sys/dev/raid/aac/aac.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aac.c,v 1.9.2.14 2003/04/08 13:22:08 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aac.c,v 1.2 2003/06/17 04:28:21 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aac.c,v 1.3 2003/06/27 01:53:21 dillon Exp $ */ /* @@ -793,7 +793,7 @@ aac_host_command(struct aac_softc *sc) #if __FreeBSD_version > 500005 mtx_lock(&Giant); #endif - kthread_exit(0); + kthread_exit(); } /* diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index f047243b91..f522c2e29b 100644 --- a/sys/i386/i386/genassym.c +++ b/sys/i386/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/i386/i386/Attic/genassym.c,v 1.12 2003/06/23 23:36:05 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/genassym.c,v 1.13 2003/06/27 01:53:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -78,7 +78,6 @@ ASSYM(VM_PMAP, offsetof(struct vmspace, vm_pmap)); ASSYM(PM_ACTIVE, offsetof(struct pmap, pm_active)); ASSYM(P_ADDR, offsetof(struct proc, p_addr)); ASSYM(P_STAT, offsetof(struct proc, p_stat)); -ASSYM(P_WCHAN, offsetof(struct proc, p_wchan)); ASSYM(P_THREAD, offsetof(struct proc, p_thread)); ASSYM(TD_PROC, offsetof(struct thread, td_proc)); @@ -87,6 +86,7 @@ ASSYM(TD_SP, offsetof(struct thread, td_sp)); ASSYM(TD_PRI, offsetof(struct thread, td_pri)); ASSYM(TD_MACH, offsetof(struct thread, td_mach)); ASSYM(TD_RWLOCK, offsetof(struct thread, td_rwlock)); +ASSYM(TD_WCHAN, offsetof(struct thread, td_wchan)); ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); diff --git a/sys/i386/i386/swtch.s b/sys/i386/i386/swtch.s index e1601aa772..f9c790865e 100644 --- a/sys/i386/i386/swtch.s +++ b/sys/i386/i386/swtch.s @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.10 2003/01/23 03:36:24 ps Exp $ - * $DragonFly: src/sys/i386/i386/Attic/swtch.s,v 1.12 2003/06/22 17:08:39 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/swtch.s,v 1.13 2003/06/27 01:53:24 dillon Exp $ */ #include "npx.h" @@ -468,6 +468,8 @@ badsw4: sw0_4: .asciz "cpu_switch: do not have lock" #endif /* SMP && DIAGNOSTIC */ +string: .asciz "SWITCHING\n" + /* * savectx(pcb) * Update pcb, saving current processor state. @@ -541,6 +543,23 @@ ENTRY(cpu_idle_restore) pushl $0 jmp cpu_idle +/* + * cpu_kthread_restore() (current thread is %eax on entry) + * + * Don't bother setting up any regs other then %ebp so backtraces + * don't die. This restore function is used to bootstrap into an + * LWKT based kernel thread only. cpu_lwkt_switch() will be used + * after this. + */ +ENTRY(cpu_kthread_restore) + movl TD_PCB(%eax),%ebx + movl $0,%ebp + popl %edx /* kthread exit function */ + pushl PCB_EBX(%ebx) /* argument to ESI function */ + pushl %edx /* set exit func as return address */ + movl PCB_ESI(%ebx),%eax + jmp *%eax + /* * cpu_lwkt_switch() * diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index 4677ae7997..845ce55390 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -39,7 +39,7 @@ * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.132.2.9 2003/01/25 19:02:23 dillon Exp $ - * $DragonFly: src/sys/i386/i386/Attic/vm_machdep.c,v 1.10 2003/06/25 03:55:53 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/vm_machdep.c,v 1.11 2003/06/27 01:53:24 dillon Exp $ */ #include "npx.h" @@ -244,6 +244,18 @@ cpu_set_fork_handler(p, func, arg) p->p_thread->td_pcb->pcb_ebx = (int) arg; /* first arg */ } +void +cpu_set_thread_handler(thread_t td, void (*rfunc)(void), void *func, void *arg) +{ + td->td_pcb->pcb_esi = (int)func; + td->td_pcb->pcb_ebx = (int) arg; + td->td_switch = cpu_lwkt_switch; + td->td_sp -= sizeof(void *); + *(void **)td->td_sp = rfunc; /* exit function on return */ + td->td_sp -= sizeof(void *); + *(void **)td->td_sp = cpu_kthread_restore; +} + void cpu_exit(p) register struct proc *p; diff --git a/sys/i386/include/md_var.h b/sys/i386/include/md_var.h index 57695bab8f..01d97e6945 100644 --- a/sys/i386/include/md_var.h +++ b/sys/i386/include/md_var.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/md_var.h,v 1.35.2.4 2003/01/22 20:14:53 jhb Exp $ - * $DragonFly: src/sys/i386/include/Attic/md_var.h,v 1.5 2003/06/21 17:31:14 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/md_var.h,v 1.6 2003/06/27 01:53:24 dillon Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -83,6 +83,7 @@ void cpu_switch_load_gs __P((void)) __asm(__STRING(cpu_switch_load_gs)); void cpu_heavy_restore __P((void)); /* cannot be called from C */ void cpu_lwkt_restore __P((void)); /* cannot be called from C */ void cpu_idle_restore __P((void)); /* cannot be called from C */ +void cpu_kthread_restore __P((void));/* cannot be called from C */ void cpu_exit_idleptd __P((void)); /* disassociate proc MMU */ void cpu_exit_switch __P((struct thread *next)); void doreti_iret __P((void)) __asm(__STRING(doreti_iret)); diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index 8fbaf93690..18ee90a3c2 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_kthread.c,v 1.5.2.3 2001/12/25 01:51:14 dillon Exp $ - * $DragonFly: src/sys/kern/kern_kthread.c,v 1.5 2003/06/23 17:55:41 dillon Exp $ + * $DragonFly: src/sys/kern/kern_kthread.c,v 1.6 2003/06/27 01:53:25 dillon Exp $ */ #include @@ -65,46 +65,43 @@ kproc_start(udata) */ int kthread_create(void (*func)(void *), void *arg, - struct thread **newpp, const char *fmt, ...) + struct thread **tdp, const char *fmt, ...) { - int error; + struct thread *td; va_list ap; - struct proc *p2; - - if (!proc0.p_stats /* || proc0.p_stats->p_start.tv_sec == 0 */) { - panic("kthread_create called too soon"); - } - error = fork1(&proc0, RFMEM | RFFDG | RFPROC, &p2); - if (error) - return error; + td = *tdp = lwkt_alloc_thread(); + cpu_set_thread_handler(td, kthread_exit, func, arg); - /* save a global descriptor, if desired */ - if (newpp != NULL) - *newpp = p2->p_thread; - - /* this is a non-swapped system process */ - p2->p_flag |= P_INMEM | P_SYSTEM; - p2->p_procsig->ps_flag |= PS_NOCLDWAIT; - PHOLD(p2); - - /* set up arg0 for 'ps', et al */ + /* + * Set up arg0 for 'ps' etc + */ va_start(ap, fmt); - vsnprintf(p2->p_comm, sizeof(p2->p_comm), fmt, ap); + vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap); va_end(ap); - /* call the processes' main()... */ - cpu_set_fork_handler(p2, func, arg); - start_forked_proc(&proc0, p2); - + /* + * Schedule the thread to run + */ + lwkt_schedule(td); return 0; } +/* + * YYY kthread_exit() should get rid of the kthread. We have to put it on + * some sort of wait list and set our switcher to interlock against + * the reaper. + */ void -kthread_exit(int ecode) +kthread_exit(void) { - proc_reparent(curproc, initproc); - exit1(W_EXITCODE(ecode, 0)); + thread_t td = curthread; + + printf("kthread %p %s has exited\n", td, td->td_comm); /* YYY */ + for (;;) { + td->td_flags |= TDF_STOPREQ; + kproc_suspend_loop(); + } } /* @@ -114,45 +111,34 @@ kthread_exit(int ecode) int suspend_kproc(struct thread *td, int timo) { - struct proc *p = td->td_proc; - - /* - * Make sure this is indeed a system process and we can safely - * use the p_siglist field. - */ - if ((p->p_flag & P_SYSTEM) == 0) - return (EINVAL); - KASSERT(p != NULL, ("suspend_kproc: no proc context: %p", td)); - SIGADDSET(p->p_siglist, SIGSTOP); - wakeup(p); - return tsleep((caddr_t)&p->p_siglist, PPAUSE, "suspkp", timo); -} - -int -resume_kproc(struct thread *td) -{ - struct proc *p = td->td_proc; - - /* - * Make sure this is indeed a system process and we can safely - * use the p_siglist field. - */ - if ((p->p_flag & P_SYSTEM) == 0) - return (EINVAL); - KASSERT(p != NULL, ("suspend_kproc: no proc context: %p", td)); - SIGDELSET(p->p_siglist, SIGSTOP); - wakeup((caddr_t)&p->p_siglist); - return (0); + if (td->td_proc == NULL) { + td->td_flags |= TDF_STOPREQ; /* request thread exit */ + wakeup(td); + while (td->td_flags & TDF_STOPREQ) { + int error = tsleep(td, PPAUSE, "suspkp", timo); + if (error == EWOULDBLOCK) + break; + } + td->td_flags &= ~TDF_STOPREQ; + return(0); + } else { + return(EINVAL); /* not a kernel thread */ + } } void -kproc_suspend_loop(struct thread *td) +kproc_suspend_loop(void) { - struct proc *p = td->td_proc; - - KASSERT(p != NULL, ("suspend_kproc: no proc context: %p", td)); - while (SIGISMEMBER(p->p_siglist, SIGSTOP)) { - wakeup((caddr_t)&p->p_siglist); - tsleep((caddr_t)&p->p_siglist, PPAUSE, "kpsusp", 0); + struct thread *td = curthread; + + if (td->td_flags & TDF_STOPREQ) { + td->td_flags &= ~TDF_STOPREQ; + while ((td->td_flags & TDF_WAKEREQ) == 0) { + wakeup(td); + tsleep(td, PPAUSE, "kpsusp", 0); + } + td->td_flags &= ~TDF_WAKEREQ; + wakeup(td); } } + diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index 30b061b756..09af10271d 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_linker.c,v 1.41.2.3 2001/11/21 17:50:35 luigi Exp $ - * $DragonFly: src/sys/kern/kern_linker.c,v 1.5 2003/06/26 05:55:14 dillon Exp $ + * $DragonFly: src/sys/kern/kern_linker.c,v 1.6 2003/06/27 01:53:25 dillon Exp $ */ #include "opt_ddb.h" @@ -1008,13 +1008,10 @@ linker_search_path(const char *name) { struct nameidata nd; struct thread *td = curthread; - struct proc *p = td->td_proc; char *cp, *ep, *result; int error; enum vtype type; - KKASSERT(p != NULL); - /* qualified at all? */ if (index(name, '/')) return(linker_strdup(name)); diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index a2c1ad78f9..a66d2005a6 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -37,7 +37,7 @@ * * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/kern_shutdown.c,v 1.72.2.12 2002/02/21 19:15:10 dillon Exp $ - * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.6 2003/06/25 03:55:57 dillon Exp $ + * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.7 2003/06/27 01:53:25 dillon Exp $ */ #include "opt_ddb.h" @@ -640,8 +640,8 @@ shutdown_kproc(void *arg, int howto) printf("Waiting (max %d seconds) for system process `%s' to stop...", kproc_shutdown_wait, p->p_comm); } else { - printf("Waiting (max %d seconds) for system thread %p to stop...", - kproc_shutdown_wait, td); + printf("Waiting (max %d seconds) for system thread %s to stop...", + kproc_shutdown_wait, td->td_comm); } error = suspend_kproc(td, kproc_shutdown_wait * hz); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 04434935ba..edc8f589eb 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -37,7 +37,7 @@ * * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 * $FreeBSD: src/sys/kern/kern_sig.c,v 1.72.2.17 2003/05/16 16:34:34 obrien Exp $ - * $DragonFly: src/sys/kern/kern_sig.c,v 1.6 2003/06/26 05:55:14 dillon Exp $ + * $DragonFly: src/sys/kern/kern_sig.c,v 1.7 2003/06/27 01:53:25 dillon Exp $ */ #include "opt_compat.h" @@ -1144,7 +1144,7 @@ psignal(p, sig) * the process runnable, leave it stopped. */ if (p->p_wchan && (p->p_flag & P_SINTR)) - unsleep(p); + unsleep(p->p_thread); goto out; default: diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 7a0a360602..ed5f8d56fc 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -37,7 +37,7 @@ * * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 * $FreeBSD: src/sys/kern/kern_synch.c,v 1.87.2.6 2002/10/13 07:29:53 kbyanc Exp $ - * $DragonFly: src/sys/kern/kern_synch.c,v 1.8 2003/06/25 03:55:57 dillon Exp $ + * $DragonFly: src/sys/kern/kern_synch.c,v 1.9 2003/06/27 01:53:25 dillon Exp $ */ #include "opt_ktrace.h" @@ -376,7 +376,7 @@ updatepri(p) * of 2. Shift right by 8, i.e. drop the bottom 256 worth. */ #define TABLESIZE 128 -static TAILQ_HEAD(slpquehead, proc) slpque[TABLESIZE]; +static TAILQ_HEAD(slpquehead, thread) slpque[TABLESIZE]; #define LOOKUP(x) (((intptr_t)(x) >> 8) & (TABLESIZE - 1)) /* @@ -419,15 +419,15 @@ tsleep(ident, priority, wmesg, timo) const char *wmesg; { struct thread *td = curthread; - struct proc *p = td->td_proc; - int s, sig, catch = priority & PCATCH; + struct proc *p = td->td_proc; /* may be NULL */ + int s, sig = 0, catch = priority & PCATCH; int id = LOOKUP(ident); struct callout_handle thandle; -#ifdef KTRACE - if (KTRPOINT(td, KTR_CSW)) - ktrcsw(p->p_tracep, 1, 0); -#endif + /* + * NOTE: removed KTRPOINT, it could cause races due to blocking + * even in stable. Just scrap it for now. + */ s = splhigh(); if (cold || panicstr) { @@ -441,16 +441,20 @@ tsleep(ident, priority, wmesg, timo) splx(s); return (0); } - KASSERT(p != NULL, ("tsleep1")); - KASSERT(ident != NULL && p->p_stat == SRUN, ("tsleep %p %s %d", ident, wmesg, p->p_stat)); - - p->p_wchan = ident; - p->p_wmesg = wmesg; - p->p_slptime = 0; - p->p_priority = priority & PRIMASK; - TAILQ_INSERT_TAIL(&slpque[id], p, p_procq); + KASSERT(ident != NULL, ("tsleep: no ident")); + KASSERT(p == NULL || p->p_stat == SRUN, ("tsleep %p %s %d", + ident, wmesg, p->p_stat)); + + td->td_wchan = ident; + td->td_wmesg = wmesg; + if (p) { + p->p_slptime = 0; + p->p_priority = priority & PRIMASK; + } + lwkt_deschedule_self(); + TAILQ_INSERT_TAIL(&slpque[id], td, td_threadq); if (timo) - thandle = timeout(endtsleep, (void *)p, timo); + thandle = timeout(endtsleep, (void *)td, timo); /* * We put ourselves on the sleep queue and start our timeout * before calling CURSIG, as we could stop there, and a wakeup @@ -460,54 +464,53 @@ tsleep(ident, priority, wmesg, timo) * when CURSIG is called. If the wakeup happens while we're * stopped, p->p_wchan will be 0 upon return from CURSIG. */ - if (catch) { - p->p_flag |= P_SINTR; - if ((sig = CURSIG(p))) { - if (p->p_wchan) - unsleep(p); - p->p_stat = SRUN; - goto resume; - } - if (p->p_wchan == 0) { - catch = 0; - goto resume; + if (p) { + if (catch) { + p->p_flag |= P_SINTR; + if ((sig = CURSIG(p))) { + if (td->td_wchan) + unsleep(td); + p->p_stat = SRUN; + goto resume; + } + if (p->p_wchan == 0) { + catch = 0; + goto resume; + } + } else { + sig = 0; } - } else - sig = 0; - p->p_stat = SSLEEP; - p->p_stats->p_ru.ru_nvcsw++; - mi_switch(); + p->p_stat = SSLEEP; + p->p_stats->p_ru.ru_nvcsw++; + mi_switch(); + } else { + lwkt_switch(); + } resume: - curpriority = p->p_usrpri; + if (p) { + curpriority = p->p_usrpri; + p->p_flag &= ~P_SINTR; + } splx(s); - p->p_flag &= ~P_SINTR; - if (p->p_flag & P_TIMEOUT) { - p->p_flag &= ~P_TIMEOUT; - if (sig == 0) { -#ifdef KTRACE - if (KTRPOINT(td, KTR_CSW)) - ktrcsw(p->p_tracep, 0, 0); -#endif + if (td->td_flags & TDF_TIMEOUT) { + td->td_flags &= ~TDF_TIMEOUT; + if (sig == 0) return (EWOULDBLOCK); + } else if (timo) { + untimeout(endtsleep, (void *)td, thandle); + } + if (p) { + if (catch && (sig != 0 || (sig = CURSIG(p)))) { + if (SIGISMEMBER(p->p_sigacts->ps_sigintr, sig)) + return (EINTR); + return (ERESTART); } - } else if (timo) - untimeout(endtsleep, (void *)p, thandle); - if (catch && (sig != 0 || (sig = CURSIG(p)))) { -#ifdef KTRACE - if (KTRPOINT(td, KTR_CSW)) - ktrcsw(p->p_tracep, 0, 0); -#endif - if (SIGISMEMBER(p->p_sigacts->ps_sigintr, sig)) - return (EINTR); - return (ERESTART); } -#ifdef KTRACE - if (KTRPOINT(td, KTR_CSW)) - ktrcsw(p->p_tracep, 0, 0); -#endif return (0); } +#if 0 + /* * General sleep call. Suspends the current process until a wakeup is * performed on the specified xwait structure. The process will then be made @@ -629,28 +632,33 @@ resume: return (0); } +#endif + /* - * Implement timeout for tsleep or xsleep - * - * If process hasn't been awakened (wchan non-zero), - * set timeout flag and undo the sleep. If proc - * is stopped, just unsleep so it will remain stopped. + * Implement the timeout for tsleep. We interlock against + * wchan when setting TDF_TIMEOUT. For processes we remove + * the sleep if the process is stopped rather then sleeping, + * so it remains stopped. */ static void -endtsleep(arg) - void *arg; +endtsleep(void *arg) { - register struct proc *p; + thread_t td = arg; + struct proc *p; int s; - p = (struct proc *)arg; s = splhigh(); - if (p->p_wchan) { - if (p->p_stat == SSLEEP) - setrunnable(p); - else - unsleep(p); - p->p_flag |= P_TIMEOUT; + if (td->td_wchan) { + td->td_flags |= TDF_TIMEOUT; + if ((p = td->td_proc) != NULL) { + if (p->p_stat == SSLEEP) + setrunnable(p); + else + unsleep(td); + } else { + unsleep(td); + lwkt_schedule(td); + } } splx(s); } @@ -659,25 +667,26 @@ endtsleep(arg) * Remove a process from its wait queue */ void -unsleep(p) - register struct proc *p; +unsleep(struct thread *td) { int s; s = splhigh(); - if (p->p_wchan) { + if (td->td_wchan) { +#if 0 if (p->p_flag & P_XSLEEP) { struct xwait *w = p->p_wchan; TAILQ_REMOVE(&w->waitq, p, p_procq); p->p_flag &= ~P_XSLEEP; - } else { - TAILQ_REMOVE(&slpque[LOOKUP(p->p_wchan)], p, p_procq); - } - p->p_wchan = NULL; + } else +#endif + TAILQ_REMOVE(&slpque[LOOKUP(td->td_wchan)], td, td_threadq); + td->td_wchan = NULL; } splx(s); } +#if 0 /* * Make all processes sleeping on the explicit lock structure runnable. */ @@ -712,29 +721,30 @@ xwakeup(struct xwait *w) } splx(s); } +#endif /* * Make all processes sleeping on the specified identifier runnable. */ -void -wakeup(ident) - register void *ident; +static void +_wakeup(void *ident, int count) { - register struct slpquehead *qp; - register struct proc *p; - struct proc *np; + struct slpquehead *qp; + struct thread *td; + struct thread *ntd; + struct proc *p; int s; int id = LOOKUP(ident); s = splhigh(); qp = &slpque[id]; restart: - for (p = TAILQ_FIRST(qp); p != NULL; p = np) { - np = TAILQ_NEXT(p, p_procq); - if (p->p_wchan == ident) { - TAILQ_REMOVE(qp, p, p_procq); - p->p_wchan = NULL; - if (p->p_stat == SSLEEP) { + for (td = TAILQ_FIRST(qp); td != NULL; td = ntd) { + ntd = TAILQ_NEXT(td, td_threadq); + if (td->td_wchan == ident) { + TAILQ_REMOVE(qp, td, td_threadq); + td->td_wchan = NULL; + if ((p = td->td_proc) != NULL && p->p_stat == SSLEEP) { /* OPTIMIZED EXPANSION OF setrunnable(p); */ if (p->p_slptime > 1) updatepri(p); @@ -748,57 +758,27 @@ restart: wakeup((caddr_t)&proc0); } /* END INLINE EXPANSION */ - goto restart; + } else if (p == NULL) { + lwkt_schedule(td); } + if (--count == 0) + break; + goto restart; } } splx(s); } -/* - * Make a process sleeping on the specified identifier runnable. - * May wake more than one process if a target process is currently - * swapped out. - */ void -wakeup_one(ident) - register void *ident; +wakeup(void *ident) { - register struct slpquehead *qp; - register struct proc *p; - struct proc *np; - int s; - int id = LOOKUP(ident); - - s = splhigh(); - qp = &slpque[id]; + _wakeup(ident, 0); +} -restart: - for (p = TAILQ_FIRST(qp); p != NULL; p = np) { - np = TAILQ_NEXT(p, p_procq); - if (p->p_wchan == ident) { - TAILQ_REMOVE(qp, p, p_procq); - p->p_wchan = 0; - if (p->p_stat == SSLEEP) { - /* OPTIMIZED EXPANSION OF setrunnable(p); */ - if (p->p_slptime > 1) - updatepri(p); - p->p_slptime = 0; - p->p_stat = SRUN; - if (p->p_flag & P_INMEM) { - setrunqueue(p); - maybe_resched(p); - break; - } else { - p->p_flag |= P_SWAPINREQ; - wakeup((caddr_t)&proc0); - } - /* END INLINE EXPANSION */ - goto restart; - } - } - } - splx(s); +void +wakeup_one(void *ident) +{ + _wakeup(ident, 1); } /* @@ -880,10 +860,9 @@ mi_switch() * and awakening the swapper if it isn't in memory. */ void -setrunnable(p) - register struct proc *p; +setrunnable(struct proc *p) { - register int s; + int s; s = splhigh(); switch (p->p_stat) { @@ -894,7 +873,7 @@ setrunnable(p) panic("setrunnable"); case SSTOP: case SSLEEP: - unsleep(p); /* e.g. when sending signals */ + unsleep(p->p_thread); /* e.g. when sending signals */ break; case SIDL: diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index 1ef5ce8a3f..d94bed3dc6 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -27,7 +27,7 @@ * thread scheduler, which means that generally speaking we only need * to use a critical section to prevent hicups. * - * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.4 2003/06/22 04:30:42 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.5 2003/06/27 01:53:25 dillon Exp $ */ #include @@ -100,6 +100,9 @@ lwkt_init_wait(lwkt_wait_t w) /* * Create a new thread. The thread must be associated with a process context * or LWKT start address before it can be scheduled. + * + * If you intend to create a thread without a process context this function + * does everything except load the startup and switcher function. */ thread_t lwkt_alloc_thread(void) diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 6161a96c49..8e6c140b7f 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -37,7 +37,7 @@ * * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/sys_generic.c,v 1.55.2.10 2001/03/17 10:39:32 peter Exp $ - * $DragonFly: src/sys/kern/sys_generic.c,v 1.4 2003/06/25 03:55:57 dillon Exp $ + * $DragonFly: src/sys/kern/sys_generic.c,v 1.5 2003/06/27 01:53:25 dillon Exp $ */ #include "opt_ktrace.h" @@ -1044,7 +1044,7 @@ selwakeup(struct selinfo *sip) if (p->p_stat == SSLEEP) setrunnable(p); else - unsleep(p); + unsleep(p->p_thread); } else if (p->p_flag & P_SELECT) p->p_flag &= ~P_SELECT; splx(s); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 539aa09dcd..778615ba55 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -12,7 +12,7 @@ * John S. Dyson. * * $FreeBSD: src/sys/kern/vfs_bio.c,v 1.242.2.20 2003/05/28 18:38:10 alc Exp $ - * $DragonFly: src/sys/kern/vfs_bio.c,v 1.6 2003/06/26 20:27:51 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_bio.c,v 1.7 2003/06/27 01:53:25 dillon Exp $ */ /* @@ -1776,7 +1776,7 @@ buf_daemon() s = splbio(); for (;;) { - kproc_suspend_loop(bufdaemonthread); + kproc_suspend_loop(); /* * Do the flush. Limit the amount of in-transit I/O we diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 003a8e9220..ec02f91a37 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.7 2003/06/26 05:55:14 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.8 2003/06/27 01:53:25 dillon Exp $ */ /* @@ -518,19 +518,18 @@ vnlru_proc(void) struct mount *mp, *nmp; int s; int done; - struct thread *td = vnlruthread; - struct proc *p = td->td_proc; + struct thread *td = curthread; EVENTHANDLER_REGISTER(shutdown_pre_sync, shutdown_kproc, td, SHUTDOWN_PRI_FIRST); s = splbio(); for (;;) { - kproc_suspend_loop(td); + kproc_suspend_loop(); if (numvnodes - freevnodes <= desiredvnodes * 9 / 10) { vnlruproc_sig = 0; wakeup(&vnlruproc_sig); - tsleep(p, PVFS, "vlruwt", hz); + tsleep(td, PVFS, "vlruwt", hz); continue; } done = 0; @@ -548,7 +547,7 @@ vnlru_proc(void) simple_unlock(&mountlist_slock); if (done == 0) { vnlru_nowhere++; - tsleep(p, PPAUSE, "vlrup", hz * 3); + tsleep(td, PPAUSE, "vlrup", hz * 3); } } splx(s); @@ -1119,13 +1118,13 @@ sched_sync(void) struct vnode *vp; long starttime; int s; - struct thread *td = updatethread; + struct thread *td = curthread; EVENTHANDLER_REGISTER(shutdown_pre_sync, shutdown_kproc, td, SHUTDOWN_PRI_LAST); for (;;) { - kproc_suspend_loop(td); + kproc_suspend_loop(); starttime = time_second; diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index a2e2e52918..b9e472317f 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -37,7 +37,7 @@ * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 * $FreeBSD: src/sys/kern/vfs_syscalls.c,v 1.151.2.18 2003/04/04 20:35:58 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.6 2003/06/26 05:55:14 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.7 2003/06/27 01:53:25 dillon Exp $ */ /* For 4.3 integer FS ID compatibility */ @@ -479,9 +479,6 @@ dounmount(struct mount *mp, int flags, struct thread *td) struct vnode *coveredvp; int error; int async_flag; - struct proc *p = td->td_proc; - - KKASSERT(p); simple_lock(&mountlist_slock); if (mp->mnt_kern_flag & MNTK_UNMOUNT) { diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 0eda6662ee..9899527667 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -37,7 +37,7 @@ * * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/vfs_vnops.c,v 1.87.2.13 2002/12/29 18:19:53 dillon Exp $ - * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.5 2003/06/26 05:55:14 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.6 2003/06/27 01:53:25 dillon Exp $ */ #include @@ -449,13 +449,11 @@ vn_statfile(struct file *fp, struct stat *sb, struct thread *td) int vn_stat(struct vnode *vp, struct stat *sb, struct thread *td) { - struct proc *p = td->td_proc; struct vattr vattr; struct vattr *vap; int error; u_short mode; - KKASSERT(p); vap = &vattr; error = VOP_GETATTR(vp, vap, td); if (error) diff --git a/sys/netinet6/in6_prefix.c b/sys/netinet6/in6_prefix.c index 7c870004f8..f37f6e1661 100644 --- a/sys/netinet6/in6_prefix.c +++ b/sys/netinet6/in6_prefix.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_prefix.c,v 1.4.2.3 2001/07/03 11:01:52 ume Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_prefix.c,v 1.2 2003/06/17 04:28:52 dillon Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_prefix.c,v 1.3 2003/06/27 01:53:25 dillon Exp $ */ /* $KAME: in6_prefix.c,v 1.47 2001/03/25 08:41:39 itojun Exp $ */ /* @@ -650,7 +650,7 @@ add_each_addr(struct socket *so, struct rr_prefix *rpp, struct rp_addr *rap) if (rap->ra_flags.anycast != 0) ifra.ifra_flags |= IN6_IFF_ANYCAST; error = in6_control(so, SIOCAIFADDR_IN6, (caddr_t)&ifra, rpp->rp_ifp, - curproc); + curthread); if (error != 0) { log(LOG_ERR, "in6_prefix.c: add_each_addr: addition of an addr" "%s/%d failed because in6_control failed for error %d\n", diff --git a/sys/netproto/smb/smb_iod.c b/sys/netproto/smb/smb_iod.c index 9176fd79db..8df762d2a8 100644 --- a/sys/netproto/smb/smb_iod.c +++ b/sys/netproto/smb/smb_iod.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_iod.c,v 1.1.2.2 2002/04/23 03:45:01 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_iod.c,v 1.3 2003/06/25 03:56:06 dillon Exp $ + * $DragonFly: src/sys/netproto/smb/smb_iod.c,v 1.4 2003/06/27 01:53:26 dillon Exp $ */ #include @@ -648,7 +648,7 @@ smb_iod_thread(void *arg) break; tsleep(&iod->iod_flags, PWAIT, "90idle", iod->iod_sleeptimo); } - kthread_exit(0); + kthread_exit(); } int diff --git a/sys/platform/pc32/i386/genassym.c b/sys/platform/pc32/i386/genassym.c index 6ec619419e..87ef05611e 100644 --- a/sys/platform/pc32/i386/genassym.c +++ b/sys/platform/pc32/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/platform/pc32/i386/genassym.c,v 1.12 2003/06/23 23:36:05 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/genassym.c,v 1.13 2003/06/27 01:53:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -78,7 +78,6 @@ ASSYM(VM_PMAP, offsetof(struct vmspace, vm_pmap)); ASSYM(PM_ACTIVE, offsetof(struct pmap, pm_active)); ASSYM(P_ADDR, offsetof(struct proc, p_addr)); ASSYM(P_STAT, offsetof(struct proc, p_stat)); -ASSYM(P_WCHAN, offsetof(struct proc, p_wchan)); ASSYM(P_THREAD, offsetof(struct proc, p_thread)); ASSYM(TD_PROC, offsetof(struct thread, td_proc)); @@ -87,6 +86,7 @@ ASSYM(TD_SP, offsetof(struct thread, td_sp)); ASSYM(TD_PRI, offsetof(struct thread, td_pri)); ASSYM(TD_MACH, offsetof(struct thread, td_mach)); ASSYM(TD_RWLOCK, offsetof(struct thread, td_rwlock)); +ASSYM(TD_WCHAN, offsetof(struct thread, td_wchan)); ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); diff --git a/sys/platform/pc32/i386/swtch.s b/sys/platform/pc32/i386/swtch.s index 484d3b9733..65376ef229 100644 --- a/sys/platform/pc32/i386/swtch.s +++ b/sys/platform/pc32/i386/swtch.s @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.10 2003/01/23 03:36:24 ps Exp $ - * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.12 2003/06/22 17:08:39 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.13 2003/06/27 01:53:24 dillon Exp $ */ #include "npx.h" @@ -468,6 +468,8 @@ badsw4: sw0_4: .asciz "cpu_switch: do not have lock" #endif /* SMP && DIAGNOSTIC */ +string: .asciz "SWITCHING\n" + /* * savectx(pcb) * Update pcb, saving current processor state. @@ -541,6 +543,23 @@ ENTRY(cpu_idle_restore) pushl $0 jmp cpu_idle +/* + * cpu_kthread_restore() (current thread is %eax on entry) + * + * Don't bother setting up any regs other then %ebp so backtraces + * don't die. This restore function is used to bootstrap into an + * LWKT based kernel thread only. cpu_lwkt_switch() will be used + * after this. + */ +ENTRY(cpu_kthread_restore) + movl TD_PCB(%eax),%ebx + movl $0,%ebp + popl %edx /* kthread exit function */ + pushl PCB_EBX(%ebx) /* argument to ESI function */ + pushl %edx /* set exit func as return address */ + movl PCB_ESI(%ebx),%eax + jmp *%eax + /* * cpu_lwkt_switch() * diff --git a/sys/platform/pc32/i386/vm_machdep.c b/sys/platform/pc32/i386/vm_machdep.c index 4f077410fa..b33d9fc16a 100644 --- a/sys/platform/pc32/i386/vm_machdep.c +++ b/sys/platform/pc32/i386/vm_machdep.c @@ -39,7 +39,7 @@ * from: @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91 * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$ * $FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.132.2.9 2003/01/25 19:02:23 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/i386/vm_machdep.c,v 1.10 2003/06/25 03:55:53 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/vm_machdep.c,v 1.11 2003/06/27 01:53:24 dillon Exp $ */ #include "npx.h" @@ -244,6 +244,18 @@ cpu_set_fork_handler(p, func, arg) p->p_thread->td_pcb->pcb_ebx = (int) arg; /* first arg */ } +void +cpu_set_thread_handler(thread_t td, void (*rfunc)(void), void *func, void *arg) +{ + td->td_pcb->pcb_esi = (int)func; + td->td_pcb->pcb_ebx = (int) arg; + td->td_switch = cpu_lwkt_switch; + td->td_sp -= sizeof(void *); + *(void **)td->td_sp = rfunc; /* exit function on return */ + td->td_sp -= sizeof(void *); + *(void **)td->td_sp = cpu_kthread_restore; +} + void cpu_exit(p) register struct proc *p; diff --git a/sys/platform/pc32/include/md_var.h b/sys/platform/pc32/include/md_var.h index 90a720602b..2381a03dcd 100644 --- a/sys/platform/pc32/include/md_var.h +++ b/sys/platform/pc32/include/md_var.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/md_var.h,v 1.35.2.4 2003/01/22 20:14:53 jhb Exp $ - * $DragonFly: src/sys/platform/pc32/include/md_var.h,v 1.5 2003/06/21 17:31:14 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/include/md_var.h,v 1.6 2003/06/27 01:53:24 dillon Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -83,6 +83,7 @@ void cpu_switch_load_gs __P((void)) __asm(__STRING(cpu_switch_load_gs)); void cpu_heavy_restore __P((void)); /* cannot be called from C */ void cpu_lwkt_restore __P((void)); /* cannot be called from C */ void cpu_idle_restore __P((void)); /* cannot be called from C */ +void cpu_kthread_restore __P((void));/* cannot be called from C */ void cpu_exit_idleptd __P((void)); /* disassociate proc MMU */ void cpu_exit_switch __P((struct thread *next)); void doreti_iret __P((void)) __asm(__STRING(doreti_iret)); diff --git a/sys/platform/vkernel/i386/genassym.c b/sys/platform/vkernel/i386/genassym.c index bdcca5be2c..3eb6aab5d9 100644 --- a/sys/platform/vkernel/i386/genassym.c +++ b/sys/platform/vkernel/i386/genassym.c @@ -35,7 +35,7 @@ * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 * $FreeBSD: src/sys/i386/i386/genassym.c,v 1.86.2.3 2002/03/03 05:42:49 nyan Exp $ - * $DragonFly: src/sys/platform/vkernel/i386/genassym.c,v 1.12 2003/06/23 23:36:05 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/genassym.c,v 1.13 2003/06/27 01:53:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -78,7 +78,6 @@ ASSYM(VM_PMAP, offsetof(struct vmspace, vm_pmap)); ASSYM(PM_ACTIVE, offsetof(struct pmap, pm_active)); ASSYM(P_ADDR, offsetof(struct proc, p_addr)); ASSYM(P_STAT, offsetof(struct proc, p_stat)); -ASSYM(P_WCHAN, offsetof(struct proc, p_wchan)); ASSYM(P_THREAD, offsetof(struct proc, p_thread)); ASSYM(TD_PROC, offsetof(struct thread, td_proc)); @@ -87,6 +86,7 @@ ASSYM(TD_SP, offsetof(struct thread, td_sp)); ASSYM(TD_PRI, offsetof(struct thread, td_pri)); ASSYM(TD_MACH, offsetof(struct thread, td_mach)); ASSYM(TD_RWLOCK, offsetof(struct thread, td_rwlock)); +ASSYM(TD_WCHAN, offsetof(struct thread, td_wchan)); ASSYM(RW_OWNER, offsetof(struct lwkt_rwlock, rw_owner)); diff --git a/sys/sys/kthread.h b/sys/sys/kthread.h index 0ed6c5ab76..83cfe69d4c 100644 --- a/sys/sys/kthread.h +++ b/sys/sys/kthread.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/kthread.h,v 1.2 2000/01/07 08:36:44 luoqi Exp $ - * $DragonFly: src/sys/sys/kthread.h,v 1.3 2003/06/22 17:39:46 dillon Exp $ + * $DragonFly: src/sys/sys/kthread.h,v 1.4 2003/06/27 01:53:26 dillon Exp $ */ #ifndef _SYS_KTHREAD_H_ @@ -47,11 +47,11 @@ struct kproc_desc { void kproc_start __P((const void *)); int kthread_create __P((void (*)(void *), void *, struct thread **, const char *, ...)) __printflike(4, 5); -void kthread_exit __P((int)) __dead2; +void kthread_exit __P((void)) __dead2; int suspend_kproc __P((struct thread *, int)); int resume_kproc __P((struct thread *)); -void kproc_suspend_loop __P((struct thread *)); +void kproc_suspend_loop __P((void)); void shutdown_kproc __P((void *, int)); #endif diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 7157e9b308..683d1a39ce 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -37,7 +37,7 @@ * * @(#)proc.h 8.15 (Berkeley) 5/19/95 * $FreeBSD: src/sys/sys/proc.h,v 1.99.2.9 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/sys/proc.h,v 1.15 2003/06/25 03:56:10 dillon Exp $ + * $DragonFly: src/sys/sys/proc.h,v 1.16 2003/06/27 01:53:26 dillon Exp $ */ #ifndef _SYS_PROC_H_ @@ -163,8 +163,6 @@ struct proc { u_int p_estcpu; /* Time averaged value of p_cpticks. */ int p_cpticks; /* Ticks of cpu time. */ fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */ - void *p_wchan; /* Sleep address. */ - const char *p_wmesg; /* Reason for sleep. */ u_int p_swtime; /* Time swapped in or out. */ u_int p_slptime; /* Time since last blocked. */ @@ -234,6 +232,8 @@ struct proc { struct thread *p_thread; /* temporarily embed thread struct in proc */ }; +#define p_wchan p_thread->td_wchan +#define p_wmesg p_thread->td_wmesg #define p_session p_pgrp->pg_session #define p_pgid p_pgrp->pg_id @@ -254,7 +254,7 @@ struct proc { #define P_SINTR 0x00080 /* Sleep is interruptible. */ #define P_SUGID 0x00100 /* Had set id privileges since last exec. */ #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */ -#define P_TIMEOUT 0x00400 /* Timing out during sleep. */ +#define P_UNUSED00400 0x00400 /* (was Timing out during sleep.) */ #define P_TRACED 0x00800 /* Debugged process being traced. */ #define P_WAITED 0x01000 /* Debugging process has waited for child. */ #define P_WEXIT 0x02000 /* Working on exiting. */ @@ -412,12 +412,13 @@ int suser_cred __P((struct ucred *cred, int flag)); void remrunqueue __P((struct proc *)); void cpu_heavy_switch __P((struct thread *)); void cpu_lwkt_switch __P((struct thread *)); -void unsleep __P((struct proc *)); +void unsleep __P((struct thread *)); void cpu_exit __P((struct proc *)) __dead2; void exit1 __P((int)) __dead2; void cpu_fork __P((struct proc *, struct proc *, int)); void cpu_set_fork_handler __P((struct proc *, void (*)(void *), void *)); +void cpu_set_thread_handler(struct thread *td, void (*retfunc)(void), void *func, void *arg); int fork1 __P((struct proc *, int, struct proc **)); void start_forked_proc __P((struct proc *, struct proc *)); int trace_req __P((struct proc *)); diff --git a/sys/sys/thread.h b/sys/sys/thread.h index 54c39a1c5b..60d5f2f075 100644 --- a/sys/sys/thread.h +++ b/sys/sys/thread.h @@ -4,7 +4,7 @@ * Implements the architecture independant portion of the LWKT * subsystem. * - * $DragonFly: src/sys/sys/thread.h,v 1.9 2003/06/25 03:56:10 dillon Exp $ + * $DragonFly: src/sys/sys/thread.h,v 1.10 2003/06/27 01:53:26 dillon Exp $ */ #ifndef _SYS_THREAD_H_ @@ -123,6 +123,7 @@ struct thread { struct proc *td_proc; /* (optional) associated process */ struct pcb *td_pcb; /* points to pcb and top of kstack */ const char *td_wmesg; /* string name for blockage */ + void *td_wchan; /* waiting on channel */ int td_cpu; /* cpu owning the thread */ int td_pri; /* 0-31, 0=highest priority */ int td_flags; /* THF flags */ @@ -136,6 +137,7 @@ struct thread { u_int64_t td_sticks; /* Statclock hits in system mode (uS) */ u_int64_t td_iticks; /* Statclock hits processing intr (uS) */ int td_locks; /* lockmgr lock debugging YYY */ + char td_comm[MAXCOMLEN+1]; /* typ 16+1 bytes */ struct mi_thread td_mach; }; @@ -150,6 +152,9 @@ struct thread { #define TDF_RUNNING 0x0001 /* currently running */ #define TDF_RUNQ 0x0002 /* on run queue */ #define TDF_DEADLKTREAT 0x1000 /* special lockmgr deadlock treatment */ +#define TDF_STOPREQ 0x2000 /* suspend_kproc */ +#define TDF_WAKEREQ 0x4000 /* resume_kproc */ +#define TDF_TIMEOUT 0x8000 /* tsleep timeout */ /* * Thread priorities. Typically only one thread from any given diff --git a/sys/vfs/ufs/ffs_softdep.c b/sys/vfs/ufs/ffs_softdep.c index b19ad92670..756bbfb41e 100644 --- a/sys/vfs/ufs/ffs_softdep.c +++ b/sys/vfs/ufs/ffs_softdep.c @@ -37,7 +37,7 @@ * * from: @(#)ffs_softdep.c 9.59 (McKusick) 6/21/00 * $FreeBSD: src/sys/ufs/ffs/ffs_softdep.c,v 1.57.2.11 2002/02/05 18:46:53 dillon Exp $ - * $DragonFly: src/sys/vfs/ufs/ffs_softdep.c,v 1.5 2003/06/26 05:55:20 dillon Exp $ + * $DragonFly: src/sys/vfs/ufs/ffs_softdep.c,v 1.6 2003/06/27 01:53:26 dillon Exp $ */ /* @@ -780,12 +780,8 @@ int softdep_flushfiles(struct mount *oldmnt, int flags, struct thread *td) { struct vnode *devvp; - struct ucred *cred; int error, loopcnt; - KKASSERT(td->td_proc); - cred = td->td_proc->p_ucred; - /* * Await our turn to clear out the queue, then serialize access. */ @@ -2796,15 +2792,12 @@ handle_workitem_remove(dirrem) struct dirrem *dirrem; { struct thread *td = curthread; /* XXX */ - struct ucred *cred; struct inodedep *inodedep; struct vnode *vp; struct inode *ip; ino_t oldinum; int error; - KKASSERT(td->td_proc); - cred = td->td_proc->p_ucred; if ((error = VFS_VGET(dirrem->dm_mnt, dirrem->dm_oldinum, &vp)) != 0) { softdep_error("handle_workitem_remove: vget", error); return; @@ -2847,7 +2840,7 @@ handle_workitem_remove(dirrem) } inodedep->id_nlinkdelta = ip->i_nlink - ip->i_effnlink; FREE_LOCK(&lk); - if ((error = UFS_TRUNCATE(vp, (off_t)0, 0,cred, td)) != 0) + if ((error = UFS_TRUNCATE(vp, (off_t)0, 0, proc0.p_ucred, td)) != 0) softdep_error("handle_workitem_remove: truncate", error); /* * Rename a directory to a new parent. Since, we are both deleting @@ -3923,13 +3916,10 @@ softdep_fsync(vp) struct buf *bp; struct fs *fs; struct thread *td = curthread; /* XXX */ - struct proc *p = td->td_proc; int error, flushparent; ino_t parentino; ufs_lbn_t lbn; - KKASSERT(p); - ip = VTOI(vp); fs = ip->i_fs; ACQUIRE_LOCK(&lk); @@ -4681,10 +4671,6 @@ clear_remove(struct thread *td) struct vnode *vp; int error, cnt; ino_t ino; - struct ucred *cred; - - KKASSERT(td->td_proc); - cred = td->td_proc->p_ucred; ACQUIRE_LOCK(&lk); for (cnt = 0; cnt < pagedep_hash; cnt++) { -- 2.41.0