From: Matthew Dillon Date: Wed, 18 Jun 2003 06:33:40 +0000 (+0000) Subject: thread stage 1: convert curproc to curthread, embed struct thread in proc. X-Git-Tag: v2.0.1~13380 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/84b592ba68143ddda4d954d1906da535fc38054e thread stage 1: convert curproc to curthread, embed struct thread in proc. --- diff --git a/sys/i386/apic/apic_vector.s b/sys/i386/apic/apic_vector.s index cd910b7367..551e57d68b 100644 --- a/sys/i386/apic/apic_vector.s +++ b/sys/i386/apic/apic_vector.s @@ -1,7 +1,7 @@ /* * from: vector.s, 386BSD 0.1 unknown origin * $FreeBSD: src/sys/i386/isa/apic_vector.s,v 1.47.2.5 2001/09/01 22:33:38 tegge Exp $ - * $DragonFly: src/sys/i386/apic/Attic/apic_vector.s,v 1.2 2003/06/17 04:28:36 dillon Exp $ + * $DragonFly: src/sys/i386/apic/Attic/apic_vector.s,v 1.3 2003/06/18 06:33:33 dillon Exp $ */ @@ -389,7 +389,8 @@ _Xcpucheckstate: 1: movl _cpuid, %eax movl %ebx, _checkstate_cpustate(,%eax,4) - movl _curproc, %ebx + movl _curthread, %ebx + movl TD_PROC(%ebx),%ebx movl %ebx, _checkstate_curproc(,%eax,4) movl 16(%esp), %ebx movl %ebx, _checkstate_pc(,%eax,4) diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index 8cc65b254f..20b61de6b6 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.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/genassym.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -80,6 +80,9 @@ 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)); /* YYY temporary */ + +ASSYM(TD_PROC, offsetof(struct thread, td_proc)); #ifdef SMP ASSYM(P_ONCPU, offsetof(struct proc, p_oncpu)); @@ -171,12 +174,13 @@ ASSYM(BI_SYMTAB, offsetof(struct bootinfo, bi_symtab)); ASSYM(BI_ESYMTAB, offsetof(struct bootinfo, bi_esymtab)); ASSYM(BI_KERNEND, offsetof(struct bootinfo, bi_kernend)); ASSYM(GD_SIZEOF, sizeof(struct globaldata)); -ASSYM(GD_CURPROC, offsetof(struct globaldata, gd_curproc)); +ASSYM(GD_CURTHREAD, offsetof(struct globaldata, gd_curthread)); ASSYM(GD_NPXPROC, offsetof(struct globaldata, gd_npxproc)); ASSYM(GD_CURPCB, offsetof(struct globaldata, gd_curpcb)); ASSYM(GD_COMMON_TSS, offsetof(struct globaldata, gd_common_tss)); ASSYM(GD_SWITCHTIME, offsetof(struct globaldata, gd_switchtime)); ASSYM(GD_SWITCHTICKS, offsetof(struct globaldata, gd_switchticks)); +ASSYM(GD_IDLETHREAD, offsetof(struct globaldata, gd_idlethread)); ASSYM(GD_COMMON_TSSD, offsetof(struct globaldata, gd_common_tssd)); ASSYM(GD_TSS_GDT, offsetof(struct globaldata, gd_tss_gdt)); ASSYM(GD_ASTPENDING, offsetof(struct globaldata, gd_astpending)); diff --git a/sys/i386/i386/globals.s b/sys/i386/i386/globals.s index 84e9a0c778..cf91f4aa0f 100644 --- a/sys/i386/i386/globals.s +++ b/sys/i386/i386/globals.s @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/globals.s,v 1.13.2.1 2000/05/16 06:58:06 dillon Exp $ - * $DragonFly: src/sys/i386/i386/Attic/globals.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/globals.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -55,16 +55,19 @@ */ .globl globaldata #ifndef SMP + .globl UP_globaldata .data ALIGN_DATA +UP_globaldata: globaldata: .space GD_SIZEOF /* in data segment */ #else .set globaldata,0 #endif - .globl gd_curproc, gd_curpcb, gd_npxproc, gd_astpending - .globl gd_common_tss, gd_switchtime, gd_switchticks - .set gd_curproc,globaldata + GD_CURPROC + .globl gd_curthread, gd_curpcb, gd_npxproc, gd_astpending + .globl gd_common_tss, gd_switchtime, gd_switchticks, gd_idlethread + .set gd_curthread,globaldata + GD_CURTHREAD + .set gd_idlethread,globaldata + GD_IDLETHREAD .set gd_astpending,globaldata + GD_ASTPENDING .set gd_curpcb,globaldata + GD_CURPCB .set gd_npxproc,globaldata + GD_NPXPROC @@ -82,9 +85,10 @@ globaldata: #endif #ifndef SMP - .globl _curproc, _curpcb, _npxproc, _astpending - .globl _common_tss, _switchtime, _switchticks - .set _curproc,globaldata + GD_CURPROC + .globl _curthread, _curpcb, _npxproc, _astpending + .globl _common_tss, _switchtime, _switchticks, _idlethread + .set _curthread,globaldata + GD_CURTHREAD + .set _idlethread,globaldata + GD_IDLETHREAD .set _astpending,globaldata + GD_ASTPENDING .set _curpcb,globaldata + GD_CURPCB .set _npxproc,globaldata + GD_NPXPROC diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 4bbec1b806..83e820df06 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -36,7 +36,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/i386/i386/Attic/machdep.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/machdep.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "apm.h" @@ -102,8 +102,8 @@ #include /* pcb.h included via sys/user.h */ #ifdef SMP #include -#include #endif +#include #ifdef PERFMON #include #endif @@ -1857,6 +1857,7 @@ init386(first) /* table descriptors - used to load tables by microp */ struct region_descriptor r_gdt, r_idt; #endif + struct globaldata *gd; /* * Prevent lowering of the ipl if we call tsleep() early. @@ -1898,10 +1899,19 @@ init386(first) gdt_segs[GPROC0_SEL].ssd_base = (int) &SMP_prvspace[0].globaldata.gd_common_tss; SMP_prvspace[0].globaldata.gd_prvspace = &SMP_prvspace[0]; + gd = &SMP_prvspace[0].globaldata; #else gdt_segs[GPRIV_SEL].ssd_limit = atop(0 - 1); gdt_segs[GPROC0_SEL].ssd_base = (int) &common_tss; + gd = &UP_globaldata; #endif + /* + * Note: on both UP and SMP curthread must be set non-NULL + * early in the boot sequence because the system assumes + * that 'curthread' is never NULL. + */ + /* YYY use prvspace for UP too and set here rather then later */ + gd->gd_curthread = &gd->gd_idlethread; for (x = 0; x < NGDT; x++) { #ifdef BDE_DEBUGGER diff --git a/sys/i386/i386/math_emu.h b/sys/i386/i386/math_emu.h index cccdf5ea76..1dddca210d 100644 --- a/sys/i386/i386/math_emu.h +++ b/sys/i386/i386/math_emu.h @@ -4,7 +4,7 @@ * (C) 1991 Linus Torvalds * * $FreeBSD: src/sys/i386/i386/math_emu.h,v 1.7.2.1 2001/08/15 01:23:50 peter Exp $ - * $DragonFly: src/sys/i386/i386/Attic/math_emu.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/math_emu.h,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #ifndef _LINUX_MATH_EMU_H #define _LINUX_MATH_EMU_H @@ -70,7 +70,7 @@ struct i387_struct { int32_t st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */ }; -#define I387 (*(struct i387_struct *)&(((struct pcb *)curproc->p_addr)->pcb_save.sv_87)) +#define I387 (*(struct i387_struct *)&(((struct pcb *)curproc->p_addr)->pcb_save.sv_87)) /* YYY note: pcb will be moved out of UAREA! */ #define SWD (*(struct swd *) &I387.swd) #define ROUNDING ((I387.cwd >> 10) & 3) #define PRECISION ((I387.cwd >> 8) & 3) diff --git a/sys/i386/i386/math_emulate.c b/sys/i386/i386/math_emulate.c index 508236de47..b11d66f71d 100644 --- a/sys/i386/i386/math_emulate.c +++ b/sys/i386/i386/math_emulate.c @@ -7,7 +7,7 @@ * * from: 386BSD 0.1 * $FreeBSD: src/sys/i386/i386/math_emulate.c,v 1.35 1999/08/28 00:43:47 peter Exp $ - * $DragonFly: src/sys/i386/i386/Attic/math_emulate.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/math_emulate.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ /* @@ -100,6 +100,7 @@ math_emulate(struct trapframe * info) u_int32_t oldeip; /* ever used fp? */ + /* YYY NOTE: pcb will be moved out of uarea! */ if ((((struct pcb *)curproc->p_addr)->pcb_flags & FP_SOFTFP) == 0) { ((struct pcb *)curproc->p_addr)->pcb_flags |= FP_SOFTFP; I387.cwd = 0x037f; diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c index a3670cfb04..b6c858dd0b 100644 --- a/sys/i386/i386/mp_machdep.c +++ b/sys/i386/i386/mp_machdep.c @@ -23,7 +23,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.115.2.15 2003/03/14 21:22:35 jhb Exp $ - * $DragonFly: src/sys/i386/i386/Attic/mp_machdep.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/mp_machdep.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_cpu.h" @@ -2145,6 +2145,7 @@ start_all_aps(u_int boot_addr) /* prime data page for it to use */ gd->gd_cpuid = x; gd->gd_cpu_lockid = x << 24; + gd->gd_curthread = &gd->gd_idlethread; gd->gd_prv_CMAP1 = &SMPpt[pg + 1]; gd->gd_prv_CMAP2 = &SMPpt[pg + 2]; gd->gd_prv_CMAP3 = &SMPpt[pg + 3]; diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index dd23b9bc79..705cb53300 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -40,7 +40,7 @@ * * from: @(#)pmap.c 7.7 (Berkeley) 5/12/91 * $FreeBSD: src/sys/i386/i386/pmap.c,v 1.250.2.18 2002/03/06 22:48:53 silby Exp $ - * $DragonFly: src/sys/i386/i386/Attic/pmap.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/pmap.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ /* @@ -420,7 +420,6 @@ pmap_bootstrap(firstaddr, loadaddr) #endif } #endif - #ifdef SMP if (cpu_apic_address == 0) panic("pmap_bootstrap: no local apic!"); diff --git a/sys/i386/i386/support.s b/sys/i386/i386/support.s index dab83dfe0a..11b69c051d 100644 --- a/sys/i386/i386/support.s +++ b/sys/i386/i386/support.s @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/support.s,v 1.67.2.5 2001/08/15 01:23:50 peter Exp $ - * $DragonFly: src/sys/i386/i386/Attic/support.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/support.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "npx.h" @@ -1002,8 +1002,9 @@ ENTRY(fastmove) movl -4(%ebp),%edi /* stop_emulating(); */ clts -/* npxproc = curproc; */ - movl _curproc,%eax +/* npxproc = curthread->td_proc; */ + movl _curthread,%eax + movl TD_PROC(%eax),%eax movl %eax,_npxproc movl _curpcb,%eax movl $fastmove_fault,PCB_ONFAULT(%eax) diff --git a/sys/i386/i386/swtch.s b/sys/i386/i386/swtch.s index 925faa2e7c..087e9bbbe5 100644 --- a/sys/i386/i386/swtch.s +++ b/sys/i386/i386/swtch.s @@ -34,7 +34,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.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/swtch.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "npx.h" @@ -280,7 +280,8 @@ ENTRY(default_halt) ENTRY(cpu_switch) /* switch to new process. first, save context as needed */ - movl _curproc,%ecx + movl _curthread,%ecx + movl TD_PROC(%ecx),%ecx /* if no process to save, don't bother */ testl %ecx,%ecx @@ -352,7 +353,17 @@ ENTRY(cpu_switch) 1: #endif /* NNPX > 0 */ - movl $0,_curproc /* out of process */ + /* + * out of processes, set curthread to the current cpu's + * idlethread. Note that idlethread.td_proc will be NULL. + */ +#ifdef SMP + movl $gd_idlethread, %edi + addl %fs:0, %edi +#else + movl $_idlethread, %edi +#endif + movl %edi,_curthread /* save is done, now choose a new process or idle */ sw1: @@ -464,7 +475,9 @@ sw1a: movb %al, P_ONCPU(%ecx) #endif /* SMP */ movl %edx, _curpcb - movl %ecx, _curproc /* into next process */ + addl $P_THREAD,%ecx /* set current thread */ + movl %ecx, _curthread + subl $P_THREAD,%ecx /* YYY does %ecx need to be restored? */ #ifdef SMP movl _cpu_lockid, %eax diff --git a/sys/i386/i386/vm86bios.s b/sys/i386/i386/vm86bios.s index 4ffda72d45..b21d235f37 100644 --- a/sys/i386/i386/vm86bios.s +++ b/sys/i386/i386/vm86bios.s @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/vm86bios.s,v 1.15.2.1 2000/05/16 06:58:07 dillon Exp $ - * $DragonFly: src/sys/i386/i386/Attic/vm86bios.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/vm86bios.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include /* miscellaneous asm macros */ @@ -70,7 +70,8 @@ ENTRY(vm86_bioscall) #endif #if NNPX > 0 - movl _curproc,%ecx + movl _curthread,%ecx + movl TD_PROC(%ecx),%ecx cmpl %ecx,_npxproc /* do we need to save fp? */ jne 1f testl %ecx,%ecx @@ -93,6 +94,7 @@ ENTRY(vm86_bioscall) rep movsl /* copy frame to new stack */ + /* YYY when pcb is in thread vm86_bios will be in its own thread */ movl _curpcb,%eax pushl %eax /* save curpcb */ movl %edx,_curpcb /* set curpcb to vm86pcb */ diff --git a/sys/i386/include/asnames.h b/sys/i386/include/asnames.h index 8eb0f67bf7..0901222319 100644 --- a/sys/i386/include/asnames.h +++ b/sys/i386/include/asnames.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/asnames.h,v 1.44.2.8 2003/01/22 20:14:53 jhb Exp $ - * $DragonFly: src/sys/i386/include/Attic/asnames.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/asnames.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ #ifndef _MACHINE_ASNAMES_H_ @@ -343,7 +343,8 @@ #define _cpuid FS(cpuid) #define _cpu_lockid FS(cpu_lockid) #define _curpcb FS(curpcb) -#define _curproc FS(curproc) +#define _curthread FS(curthread) +#define _idlethread FS(idlethread) #define _astpending FS(astpending) #define _currentldt FS(currentldt) #define _inside_intr FS(inside_intr) diff --git a/sys/i386/include/globaldata.h b/sys/i386/include/globaldata.h index f404b0ac16..9fee7625c8 100644 --- a/sys/i386/include/globaldata.h +++ b/sys/i386/include/globaldata.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/i386/include/Attic/globaldata.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/globaldata.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ /* @@ -41,7 +41,7 @@ */ struct globaldata { struct privatespace *gd_prvspace; /* self-reference */ - struct proc *gd_curproc; + struct thread *gd_curthread; struct proc *gd_npxproc; struct pcb *gd_curpcb; struct timeval gd_switchtime; @@ -68,6 +68,7 @@ struct globaldata { unsigned *gd_prv_PADDR1; #endif u_int gd_astpending; + struct thread gd_idlethread; }; #ifdef SMP @@ -93,4 +94,8 @@ struct privatespace { extern struct privatespace SMP_prvspace[]; +#else + +extern struct globaldata UP_globaldata; + #endif diff --git a/sys/i386/include/globals.h b/sys/i386/include/globals.h index af257ba8f3..76d75b1223 100644 --- a/sys/i386/include/globals.h +++ b/sys/i386/include/globals.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/globals.h,v 1.5.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/i386/include/Attic/globals.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/globals.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ #ifndef _MACHINE_GLOBALS_H_ @@ -82,7 +82,8 @@ * other hand, kernel modules should always use these macros to maintain * portability between UP and SMP kernels. */ -#define curproc GLOBAL_RVALUE_NV(curproc, struct proc *) +#define curthread GLOBAL_RVALUE_NV(curthread, struct thread *) +#define idlethread GLOBAL_RVALUE_NV(idlethread, struct thread) #define curpcb GLOBAL_RVALUE_NV(curpcb, struct pcb *) #define npxproc GLOBAL_LVALUE(npxproc, struct proc *) #define common_tss GLOBAL_LVALUE(common_tss, struct i386tss) @@ -110,9 +111,28 @@ #define prv_CADDR3 GLOBAL_RVALUE(prv_CADDR3, caddr_t) #define prv_PADDR1 GLOBAL_RVALUE(prv_PADDR1, unsigned *) #endif -#endif /*UP kernel*/ -GLOBAL_FUNC(curproc) +#else /*UP kernel*/ +/* + * Otherwise we optimize for direct access in UP + */ +extern struct thread *curthread; /* Current running proc. */ +extern struct thread idlethread; /* Idle thread global */ +extern u_int astpending; /* software interrupt pending */ +extern int switchticks; /* `ticks' at last context switch. */ +extern struct timeval switchtime; /* Uptime at last context switch */ + +#endif + +/* + * note: curthread is never NULL, but curproc can be. curpcb is a separate + * entity in other BSDs. In Turtle it is integrated into the thread + * structure. + */ +#define curproc (curthread->td_proc) + +GLOBAL_FUNC(curthread) +GLOBAL_FUNC(idlethread) GLOBAL_FUNC(astpending) GLOBAL_FUNC(curpcb) GLOBAL_FUNC(npxproc) @@ -141,7 +161,12 @@ GLOBAL_FUNC(prv_CADDR3) GLOBAL_FUNC(prv_PADDR1) #endif -#define SET_CURPROC(x) (_global_curproc_set_nv((int)x)) +/* + * This is only used in kern/init_main.c and kern/kern_exit.c and should + * be converted to procedures. YYY + */ +#define SET_CURTHREAD(x) (_global_curthread_set_nv((int)x)) +#define CLR_CURPROC() curthread->td_proc = NULL #endif /* _KERNEL */ diff --git a/sys/i386/isa/apic_vector.s b/sys/i386/isa/apic_vector.s index 65e662343e..668129a697 100644 --- a/sys/i386/isa/apic_vector.s +++ b/sys/i386/isa/apic_vector.s @@ -1,7 +1,7 @@ /* * from: vector.s, 386BSD 0.1 unknown origin * $FreeBSD: src/sys/i386/isa/apic_vector.s,v 1.47.2.5 2001/09/01 22:33:38 tegge Exp $ - * $DragonFly: src/sys/i386/isa/Attic/apic_vector.s,v 1.2 2003/06/17 04:28:36 dillon Exp $ + * $DragonFly: src/sys/i386/isa/Attic/apic_vector.s,v 1.3 2003/06/18 06:33:33 dillon Exp $ */ @@ -389,7 +389,8 @@ _Xcpucheckstate: 1: movl _cpuid, %eax movl %ebx, _checkstate_cpustate(,%eax,4) - movl _curproc, %ebx + movl _curthread, %ebx + movl TD_PROC(%ebx),%ebx movl %ebx, _checkstate_curproc(,%eax,4) movl 16(%esp), %ebx movl %ebx, _checkstate_pc(,%eax,4) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 8611ef7f37..fc62510b91 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -40,7 +40,7 @@ * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/init_main.c,v 1.134.2.8 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/kern/init_main.c,v 1.2 2003/06/17 04:28:41 dillon Exp $ + * $DragonFly: src/sys/kern/init_main.c,v 1.3 2003/06/18 06:33:37 dillon Exp $ */ #include "opt_init_path.h" @@ -353,6 +353,7 @@ proc0_init(void *dummy __unused) trunc_page(VM_MAXUSER_ADDRESS)); vmspace0.vm_map.pmap = vmspace_pmap(&vmspace0); p->p_addr = proc0paddr; /* XXX */ + p->p_thread.td_proc = p; /* * We continue to place resource usage info and signal @@ -370,7 +371,7 @@ proc0_init(void *dummy __unused) * Initialize the current process pointer (curproc) before * any possible traps/probes to simplify trap processing. */ - SET_CURPROC(p); + SET_CURTHREAD(&p->p_thread); } SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index b0ec94a4ef..a600a8163b 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -37,7 +37,7 @@ * * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 * $FreeBSD: src/sys/kern/kern_exit.c,v 1.92.2.11 2003/01/13 22:51:16 dillon Exp $ - * $DragonFly: src/sys/kern/kern_exit.c,v 1.2 2003/06/17 04:28:41 dillon Exp $ + * $DragonFly: src/sys/kern/kern_exit.c,v 1.3 2003/06/18 06:33:37 dillon Exp $ */ #include "opt_compat.h" @@ -370,7 +370,7 @@ exit1(p, rv) * * Other substructures are freed from wait(). */ - SET_CURPROC(NULL); + CLR_CURPROC(); if (--p->p_limit->p_refcnt == 0) { FREE(p->p_limit, M_SUBPROC); p->p_limit = NULL; diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index a904afc7a3..3d76744a10 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -37,7 +37,7 @@ * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 * $FreeBSD: src/sys/kern/kern_fork.c,v 1.72.2.13 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/kern/kern_fork.c,v 1.2 2003/06/17 04:28:41 dillon Exp $ + * $DragonFly: src/sys/kern/kern_fork.c,v 1.3 2003/06/18 06:33:37 dillon Exp $ */ #include "opt_ktrace.h" @@ -274,6 +274,7 @@ fork1(p1, flags, procp) } newproc->p_wakeup = 0; + newproc->p_thread.td_proc = newproc; /* YYY */ newproc->p_vmspace = NULL; diff --git a/sys/platform/pc32/apic/apic_vector.s b/sys/platform/pc32/apic/apic_vector.s index 704e84a5fd..fe7702a4d1 100644 --- a/sys/platform/pc32/apic/apic_vector.s +++ b/sys/platform/pc32/apic/apic_vector.s @@ -1,7 +1,7 @@ /* * from: vector.s, 386BSD 0.1 unknown origin * $FreeBSD: src/sys/i386/isa/apic_vector.s,v 1.47.2.5 2001/09/01 22:33:38 tegge Exp $ - * $DragonFly: src/sys/platform/pc32/apic/apic_vector.s,v 1.2 2003/06/17 04:28:36 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/apic/apic_vector.s,v 1.3 2003/06/18 06:33:33 dillon Exp $ */ @@ -389,7 +389,8 @@ _Xcpucheckstate: 1: movl _cpuid, %eax movl %ebx, _checkstate_cpustate(,%eax,4) - movl _curproc, %ebx + movl _curthread, %ebx + movl TD_PROC(%ebx),%ebx movl %ebx, _checkstate_curproc(,%eax,4) movl 16(%esp), %ebx movl %ebx, _checkstate_pc(,%eax,4) diff --git a/sys/platform/pc32/i386/genassym.c b/sys/platform/pc32/i386/genassym.c index d6552f525a..944c705e87 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.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/genassym.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -80,6 +80,9 @@ 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)); /* YYY temporary */ + +ASSYM(TD_PROC, offsetof(struct thread, td_proc)); #ifdef SMP ASSYM(P_ONCPU, offsetof(struct proc, p_oncpu)); @@ -171,12 +174,13 @@ ASSYM(BI_SYMTAB, offsetof(struct bootinfo, bi_symtab)); ASSYM(BI_ESYMTAB, offsetof(struct bootinfo, bi_esymtab)); ASSYM(BI_KERNEND, offsetof(struct bootinfo, bi_kernend)); ASSYM(GD_SIZEOF, sizeof(struct globaldata)); -ASSYM(GD_CURPROC, offsetof(struct globaldata, gd_curproc)); +ASSYM(GD_CURTHREAD, offsetof(struct globaldata, gd_curthread)); ASSYM(GD_NPXPROC, offsetof(struct globaldata, gd_npxproc)); ASSYM(GD_CURPCB, offsetof(struct globaldata, gd_curpcb)); ASSYM(GD_COMMON_TSS, offsetof(struct globaldata, gd_common_tss)); ASSYM(GD_SWITCHTIME, offsetof(struct globaldata, gd_switchtime)); ASSYM(GD_SWITCHTICKS, offsetof(struct globaldata, gd_switchticks)); +ASSYM(GD_IDLETHREAD, offsetof(struct globaldata, gd_idlethread)); ASSYM(GD_COMMON_TSSD, offsetof(struct globaldata, gd_common_tssd)); ASSYM(GD_TSS_GDT, offsetof(struct globaldata, gd_tss_gdt)); ASSYM(GD_ASTPENDING, offsetof(struct globaldata, gd_astpending)); diff --git a/sys/platform/pc32/i386/globals.s b/sys/platform/pc32/i386/globals.s index 9005321696..65c75efff2 100644 --- a/sys/platform/pc32/i386/globals.s +++ b/sys/platform/pc32/i386/globals.s @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/globals.s,v 1.13.2.1 2000/05/16 06:58:06 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/i386/globals.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/globals.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -55,16 +55,19 @@ */ .globl globaldata #ifndef SMP + .globl UP_globaldata .data ALIGN_DATA +UP_globaldata: globaldata: .space GD_SIZEOF /* in data segment */ #else .set globaldata,0 #endif - .globl gd_curproc, gd_curpcb, gd_npxproc, gd_astpending - .globl gd_common_tss, gd_switchtime, gd_switchticks - .set gd_curproc,globaldata + GD_CURPROC + .globl gd_curthread, gd_curpcb, gd_npxproc, gd_astpending + .globl gd_common_tss, gd_switchtime, gd_switchticks, gd_idlethread + .set gd_curthread,globaldata + GD_CURTHREAD + .set gd_idlethread,globaldata + GD_IDLETHREAD .set gd_astpending,globaldata + GD_ASTPENDING .set gd_curpcb,globaldata + GD_CURPCB .set gd_npxproc,globaldata + GD_NPXPROC @@ -82,9 +85,10 @@ globaldata: #endif #ifndef SMP - .globl _curproc, _curpcb, _npxproc, _astpending - .globl _common_tss, _switchtime, _switchticks - .set _curproc,globaldata + GD_CURPROC + .globl _curthread, _curpcb, _npxproc, _astpending + .globl _common_tss, _switchtime, _switchticks, _idlethread + .set _curthread,globaldata + GD_CURTHREAD + .set _idlethread,globaldata + GD_IDLETHREAD .set _astpending,globaldata + GD_ASTPENDING .set _curpcb,globaldata + GD_CURPCB .set _npxproc,globaldata + GD_NPXPROC diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index ac16ce2df0..abf643f121 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -36,7 +36,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "apm.h" @@ -102,8 +102,8 @@ #include /* pcb.h included via sys/user.h */ #ifdef SMP #include -#include #endif +#include #ifdef PERFMON #include #endif @@ -1857,6 +1857,7 @@ init386(first) /* table descriptors - used to load tables by microp */ struct region_descriptor r_gdt, r_idt; #endif + struct globaldata *gd; /* * Prevent lowering of the ipl if we call tsleep() early. @@ -1898,10 +1899,19 @@ init386(first) gdt_segs[GPROC0_SEL].ssd_base = (int) &SMP_prvspace[0].globaldata.gd_common_tss; SMP_prvspace[0].globaldata.gd_prvspace = &SMP_prvspace[0]; + gd = &SMP_prvspace[0].globaldata; #else gdt_segs[GPRIV_SEL].ssd_limit = atop(0 - 1); gdt_segs[GPROC0_SEL].ssd_base = (int) &common_tss; + gd = &UP_globaldata; #endif + /* + * Note: on both UP and SMP curthread must be set non-NULL + * early in the boot sequence because the system assumes + * that 'curthread' is never NULL. + */ + /* YYY use prvspace for UP too and set here rather then later */ + gd->gd_curthread = &gd->gd_idlethread; for (x = 0; x < NGDT; x++) { #ifdef BDE_DEBUGGER diff --git a/sys/platform/pc32/i386/math_emu.h b/sys/platform/pc32/i386/math_emu.h index 6e2fe97f54..6d730f881c 100644 --- a/sys/platform/pc32/i386/math_emu.h +++ b/sys/platform/pc32/i386/math_emu.h @@ -4,7 +4,7 @@ * (C) 1991 Linus Torvalds * * $FreeBSD: src/sys/i386/i386/math_emu.h,v 1.7.2.1 2001/08/15 01:23:50 peter Exp $ - * $DragonFly: src/sys/platform/pc32/i386/math_emu.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/math_emu.h,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #ifndef _LINUX_MATH_EMU_H #define _LINUX_MATH_EMU_H @@ -70,7 +70,7 @@ struct i387_struct { int32_t st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */ }; -#define I387 (*(struct i387_struct *)&(((struct pcb *)curproc->p_addr)->pcb_save.sv_87)) +#define I387 (*(struct i387_struct *)&(((struct pcb *)curproc->p_addr)->pcb_save.sv_87)) /* YYY note: pcb will be moved out of UAREA! */ #define SWD (*(struct swd *) &I387.swd) #define ROUNDING ((I387.cwd >> 10) & 3) #define PRECISION ((I387.cwd >> 8) & 3) diff --git a/sys/platform/pc32/i386/math_emulate.c b/sys/platform/pc32/i386/math_emulate.c index a39920feb9..327efe173d 100644 --- a/sys/platform/pc32/i386/math_emulate.c +++ b/sys/platform/pc32/i386/math_emulate.c @@ -7,7 +7,7 @@ * * from: 386BSD 0.1 * $FreeBSD: src/sys/i386/i386/math_emulate.c,v 1.35 1999/08/28 00:43:47 peter Exp $ - * $DragonFly: src/sys/platform/pc32/i386/math_emulate.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/math_emulate.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ /* @@ -100,6 +100,7 @@ math_emulate(struct trapframe * info) u_int32_t oldeip; /* ever used fp? */ + /* YYY NOTE: pcb will be moved out of uarea! */ if ((((struct pcb *)curproc->p_addr)->pcb_flags & FP_SOFTFP) == 0) { ((struct pcb *)curproc->p_addr)->pcb_flags |= FP_SOFTFP; I387.cwd = 0x037f; diff --git a/sys/platform/pc32/i386/mp_machdep.c b/sys/platform/pc32/i386/mp_machdep.c index 138e98842d..dfd97a4973 100644 --- a/sys/platform/pc32/i386/mp_machdep.c +++ b/sys/platform/pc32/i386/mp_machdep.c @@ -23,7 +23,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.115.2.15 2003/03/14 21:22:35 jhb Exp $ - * $DragonFly: src/sys/platform/pc32/i386/mp_machdep.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/mp_machdep.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_cpu.h" @@ -2145,6 +2145,7 @@ start_all_aps(u_int boot_addr) /* prime data page for it to use */ gd->gd_cpuid = x; gd->gd_cpu_lockid = x << 24; + gd->gd_curthread = &gd->gd_idlethread; gd->gd_prv_CMAP1 = &SMPpt[pg + 1]; gd->gd_prv_CMAP2 = &SMPpt[pg + 2]; gd->gd_prv_CMAP3 = &SMPpt[pg + 3]; diff --git a/sys/platform/pc32/i386/pmap.c b/sys/platform/pc32/i386/pmap.c index 106f550050..c04c193949 100644 --- a/sys/platform/pc32/i386/pmap.c +++ b/sys/platform/pc32/i386/pmap.c @@ -40,7 +40,7 @@ * * from: @(#)pmap.c 7.7 (Berkeley) 5/12/91 * $FreeBSD: src/sys/i386/i386/pmap.c,v 1.250.2.18 2002/03/06 22:48:53 silby Exp $ - * $DragonFly: src/sys/platform/pc32/i386/pmap.c,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/pmap.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ /* @@ -420,7 +420,6 @@ pmap_bootstrap(firstaddr, loadaddr) #endif } #endif - #ifdef SMP if (cpu_apic_address == 0) panic("pmap_bootstrap: no local apic!"); diff --git a/sys/platform/pc32/i386/support.s b/sys/platform/pc32/i386/support.s index b0dccbf33e..15a481cbc2 100644 --- a/sys/platform/pc32/i386/support.s +++ b/sys/platform/pc32/i386/support.s @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/support.s,v 1.67.2.5 2001/08/15 01:23:50 peter Exp $ - * $DragonFly: src/sys/platform/pc32/i386/support.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/support.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "npx.h" @@ -1002,8 +1002,9 @@ ENTRY(fastmove) movl -4(%ebp),%edi /* stop_emulating(); */ clts -/* npxproc = curproc; */ - movl _curproc,%eax +/* npxproc = curthread->td_proc; */ + movl _curthread,%eax + movl TD_PROC(%eax),%eax movl %eax,_npxproc movl _curpcb,%eax movl $fastmove_fault,PCB_ONFAULT(%eax) diff --git a/sys/platform/pc32/i386/swtch.s b/sys/platform/pc32/i386/swtch.s index 0915c5718a..d108405cd1 100644 --- a/sys/platform/pc32/i386/swtch.s +++ b/sys/platform/pc32/i386/swtch.s @@ -34,7 +34,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.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "npx.h" @@ -280,7 +280,8 @@ ENTRY(default_halt) ENTRY(cpu_switch) /* switch to new process. first, save context as needed */ - movl _curproc,%ecx + movl _curthread,%ecx + movl TD_PROC(%ecx),%ecx /* if no process to save, don't bother */ testl %ecx,%ecx @@ -352,7 +353,17 @@ ENTRY(cpu_switch) 1: #endif /* NNPX > 0 */ - movl $0,_curproc /* out of process */ + /* + * out of processes, set curthread to the current cpu's + * idlethread. Note that idlethread.td_proc will be NULL. + */ +#ifdef SMP + movl $gd_idlethread, %edi + addl %fs:0, %edi +#else + movl $_idlethread, %edi +#endif + movl %edi,_curthread /* save is done, now choose a new process or idle */ sw1: @@ -464,7 +475,9 @@ sw1a: movb %al, P_ONCPU(%ecx) #endif /* SMP */ movl %edx, _curpcb - movl %ecx, _curproc /* into next process */ + addl $P_THREAD,%ecx /* set current thread */ + movl %ecx, _curthread + subl $P_THREAD,%ecx /* YYY does %ecx need to be restored? */ #ifdef SMP movl _cpu_lockid, %eax diff --git a/sys/platform/pc32/i386/vm86bios.s b/sys/platform/pc32/i386/vm86bios.s index 5fd41da350..32ca474f8d 100644 --- a/sys/platform/pc32/i386/vm86bios.s +++ b/sys/platform/pc32/i386/vm86bios.s @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/vm86bios.s,v 1.15.2.1 2000/05/16 06:58:07 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/i386/vm86bios.s,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/vm86bios.s,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include /* miscellaneous asm macros */ @@ -70,7 +70,8 @@ ENTRY(vm86_bioscall) #endif #if NNPX > 0 - movl _curproc,%ecx + movl _curthread,%ecx + movl TD_PROC(%ecx),%ecx cmpl %ecx,_npxproc /* do we need to save fp? */ jne 1f testl %ecx,%ecx @@ -93,6 +94,7 @@ ENTRY(vm86_bioscall) rep movsl /* copy frame to new stack */ + /* YYY when pcb is in thread vm86_bios will be in its own thread */ movl _curpcb,%eax pushl %eax /* save curpcb */ movl %edx,_curpcb /* set curpcb to vm86pcb */ diff --git a/sys/platform/pc32/include/asnames.h b/sys/platform/pc32/include/asnames.h index 472d9f3c9f..2b343d4024 100644 --- a/sys/platform/pc32/include/asnames.h +++ b/sys/platform/pc32/include/asnames.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/asnames.h,v 1.44.2.8 2003/01/22 20:14:53 jhb Exp $ - * $DragonFly: src/sys/platform/pc32/include/Attic/asnames.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/include/Attic/asnames.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ #ifndef _MACHINE_ASNAMES_H_ @@ -343,7 +343,8 @@ #define _cpuid FS(cpuid) #define _cpu_lockid FS(cpu_lockid) #define _curpcb FS(curpcb) -#define _curproc FS(curproc) +#define _curthread FS(curthread) +#define _idlethread FS(idlethread) #define _astpending FS(astpending) #define _currentldt FS(currentldt) #define _inside_intr FS(inside_intr) diff --git a/sys/platform/pc32/include/globaldata.h b/sys/platform/pc32/include/globaldata.h index 879aa5ae41..e4b16f0d01 100644 --- a/sys/platform/pc32/include/globaldata.h +++ b/sys/platform/pc32/include/globaldata.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/include/globaldata.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/include/globaldata.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ /* @@ -41,7 +41,7 @@ */ struct globaldata { struct privatespace *gd_prvspace; /* self-reference */ - struct proc *gd_curproc; + struct thread *gd_curthread; struct proc *gd_npxproc; struct pcb *gd_curpcb; struct timeval gd_switchtime; @@ -68,6 +68,7 @@ struct globaldata { unsigned *gd_prv_PADDR1; #endif u_int gd_astpending; + struct thread gd_idlethread; }; #ifdef SMP @@ -93,4 +94,8 @@ struct privatespace { extern struct privatespace SMP_prvspace[]; +#else + +extern struct globaldata UP_globaldata; + #endif diff --git a/sys/platform/pc32/include/globals.h b/sys/platform/pc32/include/globals.h index b5683a7342..bd68ba8677 100644 --- a/sys/platform/pc32/include/globals.h +++ b/sys/platform/pc32/include/globals.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/globals.h,v 1.5.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/include/Attic/globals.h,v 1.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/include/Attic/globals.h,v 1.3 2003/06/18 06:33:29 dillon Exp $ */ #ifndef _MACHINE_GLOBALS_H_ @@ -82,7 +82,8 @@ * other hand, kernel modules should always use these macros to maintain * portability between UP and SMP kernels. */ -#define curproc GLOBAL_RVALUE_NV(curproc, struct proc *) +#define curthread GLOBAL_RVALUE_NV(curthread, struct thread *) +#define idlethread GLOBAL_RVALUE_NV(idlethread, struct thread) #define curpcb GLOBAL_RVALUE_NV(curpcb, struct pcb *) #define npxproc GLOBAL_LVALUE(npxproc, struct proc *) #define common_tss GLOBAL_LVALUE(common_tss, struct i386tss) @@ -110,9 +111,28 @@ #define prv_CADDR3 GLOBAL_RVALUE(prv_CADDR3, caddr_t) #define prv_PADDR1 GLOBAL_RVALUE(prv_PADDR1, unsigned *) #endif -#endif /*UP kernel*/ -GLOBAL_FUNC(curproc) +#else /*UP kernel*/ +/* + * Otherwise we optimize for direct access in UP + */ +extern struct thread *curthread; /* Current running proc. */ +extern struct thread idlethread; /* Idle thread global */ +extern u_int astpending; /* software interrupt pending */ +extern int switchticks; /* `ticks' at last context switch. */ +extern struct timeval switchtime; /* Uptime at last context switch */ + +#endif + +/* + * note: curthread is never NULL, but curproc can be. curpcb is a separate + * entity in other BSDs. In Turtle it is integrated into the thread + * structure. + */ +#define curproc (curthread->td_proc) + +GLOBAL_FUNC(curthread) +GLOBAL_FUNC(idlethread) GLOBAL_FUNC(astpending) GLOBAL_FUNC(curpcb) GLOBAL_FUNC(npxproc) @@ -141,7 +161,12 @@ GLOBAL_FUNC(prv_CADDR3) GLOBAL_FUNC(prv_PADDR1) #endif -#define SET_CURPROC(x) (_global_curproc_set_nv((int)x)) +/* + * This is only used in kern/init_main.c and kern/kern_exit.c and should + * be converted to procedures. YYY + */ +#define SET_CURTHREAD(x) (_global_curthread_set_nv((int)x)) +#define CLR_CURPROC() curthread->td_proc = NULL #endif /* _KERNEL */ diff --git a/sys/platform/pc32/isa/apic_vector.s b/sys/platform/pc32/isa/apic_vector.s index bad18f2d8a..aa49ccb9cd 100644 --- a/sys/platform/pc32/isa/apic_vector.s +++ b/sys/platform/pc32/isa/apic_vector.s @@ -1,7 +1,7 @@ /* * from: vector.s, 386BSD 0.1 unknown origin * $FreeBSD: src/sys/i386/isa/apic_vector.s,v 1.47.2.5 2001/09/01 22:33:38 tegge Exp $ - * $DragonFly: src/sys/platform/pc32/isa/Attic/apic_vector.s,v 1.2 2003/06/17 04:28:36 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/isa/Attic/apic_vector.s,v 1.3 2003/06/18 06:33:33 dillon Exp $ */ @@ -389,7 +389,8 @@ _Xcpucheckstate: 1: movl _cpuid, %eax movl %ebx, _checkstate_cpustate(,%eax,4) - movl _curproc, %ebx + movl _curthread, %ebx + movl TD_PROC(%ebx),%ebx movl %ebx, _checkstate_curproc(,%eax,4) movl 16(%esp), %ebx movl %ebx, _checkstate_pc(,%eax,4) diff --git a/sys/platform/vkernel/i386/genassym.c b/sys/platform/vkernel/i386/genassym.c index 085ec8147e..3e25c73980 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.2 2003/06/17 04:28:35 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/genassym.c,v 1.3 2003/06/18 06:33:24 dillon Exp $ */ #include "opt_user_ldt.h" @@ -80,6 +80,9 @@ 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)); /* YYY temporary */ + +ASSYM(TD_PROC, offsetof(struct thread, td_proc)); #ifdef SMP ASSYM(P_ONCPU, offsetof(struct proc, p_oncpu)); @@ -171,12 +174,13 @@ ASSYM(BI_SYMTAB, offsetof(struct bootinfo, bi_symtab)); ASSYM(BI_ESYMTAB, offsetof(struct bootinfo, bi_esymtab)); ASSYM(BI_KERNEND, offsetof(struct bootinfo, bi_kernend)); ASSYM(GD_SIZEOF, sizeof(struct globaldata)); -ASSYM(GD_CURPROC, offsetof(struct globaldata, gd_curproc)); +ASSYM(GD_CURTHREAD, offsetof(struct globaldata, gd_curthread)); ASSYM(GD_NPXPROC, offsetof(struct globaldata, gd_npxproc)); ASSYM(GD_CURPCB, offsetof(struct globaldata, gd_curpcb)); ASSYM(GD_COMMON_TSS, offsetof(struct globaldata, gd_common_tss)); ASSYM(GD_SWITCHTIME, offsetof(struct globaldata, gd_switchtime)); ASSYM(GD_SWITCHTICKS, offsetof(struct globaldata, gd_switchticks)); +ASSYM(GD_IDLETHREAD, offsetof(struct globaldata, gd_idlethread)); ASSYM(GD_COMMON_TSSD, offsetof(struct globaldata, gd_common_tssd)); ASSYM(GD_TSS_GDT, offsetof(struct globaldata, gd_tss_gdt)); ASSYM(GD_ASTPENDING, offsetof(struct globaldata, gd_astpending)); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index b560987b1a..5ea9aebe26 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.2 2003/06/17 04:28:58 dillon Exp $ + * $DragonFly: src/sys/sys/proc.h,v 1.3 2003/06/18 06:33:40 dillon Exp $ */ #ifndef _SYS_PROC_H_ @@ -55,6 +55,8 @@ #include #include /* For struct klist */ +#include + /* * One structure allocated per session. */ @@ -246,6 +248,7 @@ struct proc { struct proc *p_leader; struct pasleep p_asleep; /* Used by asleep()/await(). */ void *p_emuldata; /* process-specific emulator state data */ + struct thread p_thread; /* temporarily embed thread struct in proc */ }; #define p_session p_pgrp->pg_session @@ -372,16 +375,12 @@ extern u_long pidhash; extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl; extern u_long pgrphash; +#if 0 #ifndef SET_CURPROC #define SET_CURPROC(p) (curproc = (p)) #endif - -#ifndef curproc -extern struct proc *curproc; /* Current running proc. */ -extern u_int astpending; /* software interrupt pending */ -extern int switchticks; /* `ticks' at last context switch. */ -extern struct timeval switchtime; /* Uptime at last context switch */ #endif + extern struct proc proc0; /* Process slot for swapper. */ extern int hogticks; /* Limit on kernel cpu hogs. */ extern int nprocs, maxproc; /* Current and max number of procs. */