--- //depot/projects/sparc64/sys/kern/kern_exit.c 2002/02/23 10:11:35 +++ //depot/user/jake/sparc64-jake/sys/kern/kern_exit.c 2002/02/23 15:37:32 @@ -448,6 +448,7 @@ PROC_UNLOCK(p); cnt.v_swtch++; + cpu_sched_exit(td); cpu_throw(); panic("exit1"); } --- //depot/projects/sparc64/sys/sparc64/sparc64/pmap.c 2002/03/03 19:27:01 +++ //depot/user/jake/sparc64-jake/sys/sparc64/sparc64/pmap.c 2002/03/04 11:21:05 @@ -1830,6 +1826,7 @@ context = pmap_context_alloc(); pm->pm_context[PCPU_GET(cpuid)] = context; pm->pm_active |= PCPU_GET(cpumask); + PCPU_SET(vmspace, vm); stxa(AA_DMMU_PCXR, ASI_DMMU, context); membar(Sync); mtx_unlock_spin(&sched_lock); --- //depot/projects/sparc64/sys/sparc64/sparc64/swtch.s 2002/03/03 23:49:59 +++ //depot/user/jake/sparc64-jake/sys/sparc64/sparc64/swtch.s 2002/03/03 23:53:49 @@ -121,11 +121,11 @@ wrpr %g0, PSTATE_KERNEL, %pstate /* - * Point to the vmspaces of the new and old processes. + * Point to the vmspaces of the new process, and of the last non-kernel + * process to run. */ -2: ldx [%l0 + TD_PROC], %l2 ldx [%o0 + TD_PROC], %o2 - ldx [%l2 + P_VMSPACE], %l2 + ldx [PCPU(VMSPACE)], %l2 ldx [%o2 + P_VMSPACE], %o2 #if KTR_COMPILE & KTR_PROC @@ -143,24 +143,30 @@ be,a,pn %xcc, 4f nop + /* + * If the new process has nucleus context we are done. + */ lduw [PCPU(CPUID)], %o3 sllx %o3, INT_SHIFT, %o3 add %o2, VM_PMAP + PM_CONTEXT, %o4 + lduw [%o3 + %o4], %o5 - lduw [PCPU(CPUID)], %l3 - sllx %l3, INT_SHIFT, %l3 - add %l2, VM_PMAP + PM_CONTEXT, %l4 +#if KTR_COMPILE & KTR_PROC + CATR(KTR_PROC, "cpu_switch: ctx=%#lx" + , %g1, %g2, %g3, 7, 8, 9) + stx %o5, [%g1 + KTR_PARM1] +9: +#endif + + brz,a,pn %o5, 4f + nop - /* - * If the old process has nucleus context we don't want to deactivate - * its pmap on this cpu. - */ - lduw [%l3 + %l4], %l5 - brz,a %l5, 2f + brz,a,pn %l2, 2f nop /* - * Mark the pmap no longer active on this cpu. + * Mark the pmap of the last non-kernel vmspace to run as no longer + * active on this cpu. */ lduw [%l2 + VM_PMAP + PM_ACTIVE], %l3 lduw [PCPU(CPUMASK)], %l4 @@ -177,25 +183,10 @@ stw %l5, [%l3 + %l4] /* - * If the new process has nucleus context we are done. - */ -2: lduw [%o3 + %o4], %o5 - -#if KTR_COMPILE & KTR_PROC - CATR(KTR_PROC, "cpu_switch: ctx=%#lx" - , %g1, %g2, %g3, 7, 8, 9) - stx %o5, [%g1 + KTR_PARM1] -9: -#endif - - brz,a,pn %o5, 4f - nop - - /* * Find the current free tlb context for this cpu and install it as * the new primary context. */ - lduw [PCPU(TLB_CTX)], %o5 +2: lduw [PCPU(TLB_CTX)], %o5 stw %o5, [%o3 + %o4] mov AA_DMMU_PCXR, %o4 stxa %o5, [%o4] ASI_DMMU @@ -246,6 +237,11 @@ stw %o3, [%o2 + VM_PMAP + PM_ACTIVE] /* + * Make note of the change in vmspace. + */ + stx %o2, [PCPU(VMSPACE)] + + /* * Load the address of the tsb, switch to mmu globals, and install * the preloaded tsb pointer. */ --- //depot/projects/sparc64/sys/sparc64/sparc64/vm_machdep.c 2002/03/03 23:49:59 +++ //depot/user/jake/sparc64-jake/sys/sparc64/sparc64/vm_machdep.c 2002/03/03 23:53:49 @@ -85,6 +85,26 @@ } } +void +cpu_sched_exit(struct thread *td) +{ + struct vmspace *vm; + struct pcpu *pc; + struct proc *p; + + p = td->td_proc; + vm = p->p_vmspace; + + mtx_assert(&sched_lock, MA_OWNED); + SLIST_FOREACH(pc, &cpuhead, pc_allcpu) { + if (pc->pc_vmspace == vm && vm->vm_refcnt == 1) { + vm->vm_pmap.pm_active &= ~pc->pc_cpumask; + vm->vm_pmap.pm_context[pc->pc_cpuid] = -1; + pc->pc_vmspace = NULL; + } + } +} + /* * Finish a fork operation, with process p2 nearly set up. * Copy and update the pcb, set up the stack so that the child