From: miod Date: Fri, 29 Mar 2024 21:27:53 +0000 (+0000) Subject: Store the physical address of each pcb in struct mdproc, and use this in X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8ad6162f58ae810f64077ecbb551d6b4a69595a3;p=openbsd Store the physical address of each pcb in struct mdproc, and use this in order to speed up window spills, rather than doing an inline pmap_extract (well, pseg_get). ok claudio@ kettenis@ --- diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h index 65864762b56..de9c7cc617e 100644 --- a/sys/arch/sparc64/include/cpu.h +++ b/sys/arch/sparc64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.106 2024/03/29 21:09:04 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.107 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ /* @@ -113,6 +113,7 @@ struct cpu_info { /* Most important fields first */ struct proc *ci_curproc; struct pcb *ci_cpcb; /* also initial stack */ + paddr_t ci_cpcbpaddr; struct cpu_info *ci_next; struct proc *ci_fpproc; diff --git a/sys/arch/sparc64/include/proc.h b/sys/arch/sparc64/include/proc.h index 721d856ab50..31739faddfa 100644 --- a/sys/arch/sparc64/include/proc.h +++ b/sys/arch/sparc64/include/proc.h @@ -47,4 +47,5 @@ struct mdproc { struct trapframe *md_tf; /* trap/syscall registers */ struct fpstate *md_fpstate; /* fpu state, if any; always resident */ volatile int md_astpending; + paddr_t md_pcbpaddr; }; diff --git a/sys/arch/sparc64/sparc64/db_interface.c b/sys/arch/sparc64/sparc64/db_interface.c index 570285b90a8..0351dfc15e9 100644 --- a/sys/arch/sparc64/sparc64/db_interface.c +++ b/sys/arch/sparc64/sparc64/db_interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_interface.c,v 1.62 2024/02/23 18:19:03 cheloha Exp $ */ +/* $OpenBSD: db_interface.c,v 1.63 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: db_interface.c,v 1.61 2001/07/31 06:55:47 eeh Exp $ */ /* @@ -1009,6 +1009,7 @@ db_setpcb(db_expr_t addr, int have_addr, db_expr_t count, char *modif) if (p->p_stat && p->p_tid == addr) { curproc = p; curpcb = (struct pcb*)p->p_addr; + curcpu()->ci_cpcbpaddr = p->p_md.md_pcbpaddr; if (p->p_vmspace->vm_map.pmap->pm_ctx) { switchtoctx(p->p_vmspace->vm_map.pmap->pm_ctx); return; diff --git a/sys/arch/sparc64/sparc64/genassym.cf b/sys/arch/sparc64/sparc64/genassym.cf index 9ac36443741..ec32585dd56 100644 --- a/sys/arch/sparc64/sparc64/genassym.cf +++ b/sys/arch/sparc64/sparc64/genassym.cf @@ -1,4 +1,4 @@ -# $OpenBSD: genassym.cf,v 1.43 2024/03/29 21:14:56 miod Exp $ +# $OpenBSD: genassym.cf,v 1.44 2024/03/29 21:27:53 miod Exp $ # $NetBSD: genassym.cf,v 1.23 2001/08/08 00:09:30 eeh Exp $ # @@ -91,6 +91,7 @@ member p_vmspace member p_cpu member P_FPSTATE p_md.md_fpstate member P_MD_ASTPENDING p_md.md_astpending +member P_MD_PCBPADDR p_md.md_pcbpaddr export SONPROC @@ -116,6 +117,7 @@ struct cpu_info member ci_self member ci_curproc member ci_cpcb +member ci_cpcbpaddr member ci_fpproc member ci_handled_intr_level member ci_intrpending diff --git a/sys/arch/sparc64/sparc64/locore.s b/sys/arch/sparc64/sparc64/locore.s index e7d4fe3ea3f..d34a8562683 100644 --- a/sys/arch/sparc64/sparc64/locore.s +++ b/sys/arch/sparc64/sparc64/locore.s @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.s,v 1.213 2024/03/29 21:25:55 miod Exp $ */ +/* $OpenBSD: locore.s,v 1.214 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */ /* @@ -157,7 +157,7 @@ sun4u_mtp_patch_end: #ifdef SUN4V #define GET_CPUINFO_PA(ci) \ - mov 0x10, ci ;\ + mov 0x10, ci ;\ ldxa [ci] ASI_SCRATCHPAD, ci #define GET_MMFSA(mmfsa) \ @@ -1927,61 +1927,9 @@ winfixspill: wrpr %g5, 0, %cwp ! return here and write out all dirty windows. #endif /* 1 */ wrpr %g2, 0, %tl ! Restore trap level for now XXXX - GET_CPCB(%g6) -#ifdef DEBUG - set 0x12, %g5 ! debug - sethi %hi(DATA_START), %g7 ! debug - stb %g5, [%g7 + 0x20] ! debug - CHKPT %g5,%g7,0x11 -#endif /* DEBUG */ - - /* - * Traverse kernel map to find paddr of cpcb and only us ASI_PHYS_CACHED to - * prevent any faults while saving the windows. BTW if it isn't mapped, we - * will trap and hopefully panic. - */ - -! ba 0f ! DEBUG -- don't use phys addresses - wr %g0, ASI_NUCLEUS, %asi ! In case of problems finding PA - sethi %hi(ctxbusy), %g1 - ldx [%g1 + %lo(ctxbusy)], %g1 ! Load start of ctxbusy -#ifdef DEBUG - srax %g6, HOLESHIFT, %g7 ! Check for valid address - brz,pt %g7, 1f ! Should be zero or -1 - addcc %g7, 1, %g7 ! Make -1 -> 0 - tnz %xcc, 1 ! Invalid address??? How did this happen? -1: -#endif /* DEBUG */ - srlx %g6, STSHIFT, %g7 - ldx [%g1], %g1 ! Load pointer to kernel_pmap - and %g7, STMASK, %g7 - sll %g7, 3, %g7 - add %g7, %g1, %g1 - ldxa [%g1] ASI_PHYS_CACHED, %g1 ! Load pointer to directory - - srlx %g6, PDSHIFT, %g7 ! Do page directory - and %g7, PDMASK, %g7 - sll %g7, 3, %g7 - brz,pn %g1, 0f - add %g7, %g1, %g1 - ldxa [%g1] ASI_PHYS_CACHED, %g1 - - srlx %g6, PTSHIFT, %g7 ! Convert to ptab offset - and %g7, PTMASK, %g7 - brz %g1, 0f - sll %g7, 3, %g7 - add %g1, %g7, %g7 - ldxa [%g7] ASI_PHYS_CACHED, %g7 ! This one is not - brgez %g7, 0f - srlx %g7, PGSHIFT, %g7 ! Isolate PA part - sll %g6, 32-PGSHIFT, %g6 ! And offset - sllx %g7, PGSHIFT+17, %g7 ! There are 17 bits to the left of the PA in the TTE - srl %g6, 32-PGSHIFT, %g6 - srax %g7, 17, %g7 - or %g7, %g6, %g6 ! Then combine them to form PA - + GET_CPUINFO_VA(%g6) + ldx [%g6 + CI_CPCBPADDR], %g6 wr %g0, ASI_PHYS_CACHED, %asi ! Use ASI_PHYS_CACHED to prevent possible page faults -0: /* * Now save all user windows to cpcb. */ @@ -3145,41 +3093,8 @@ pcbspill_others: pcbspill: GET_CPUINFO_PA(%g6) - wr %g0, ASI_PHYS_CACHED, %asi - ldxa [%g6 + CI_CPCB] %asi, %g6 - - sethi %hi(ctxbusy), %g1 - ldx [%g1 + %lo(ctxbusy)], %g1 - ldx [%g1], %g1 - - srlx %g6, STSHIFT, %g7 - and %g7, STMASK, %g7 - sll %g7, 3, %g7 - add %g7, %g1, %g1 - ldxa [%g1] ASI_PHYS_CACHED, %g1 ! Load pointer to directory - - srlx %g6, PDSHIFT, %g7 ! Do page directory - and %g7, PDMASK, %g7 - sll %g7, 3, %g7 - brz,pn %g1, pcbspill_fail - add %g7, %g1, %g1 - ldxa [%g1] ASI_PHYS_CACHED, %g1 - - srlx %g6, PTSHIFT, %g7 ! Convert to ptab offset - and %g7, PTMASK, %g7 - brz %g1, pcbspill_fail - sll %g7, 3, %g7 - add %g1, %g7, %g7 - ldxa [%g7] ASI_PHYS_CACHED, %g7 ! This one is not - brgez %g7, pcbspill_fail - srlx %g7, PGSHIFT, %g7 ! Isolate PA part - sll %g6, 32-PGSHIFT, %g6 ! And offset - sllx %g7, PGSHIFT+8, %g7 ! There are 8 bits to the left of the PA in the TTE - srl %g6, 32-PGSHIFT, %g6 - srax %g7, 8, %g7 - or %g7, %g6, %g6 ! Then combine them to form PA - -! wr %g0, ASI_PHYS_CACHED, %asi ! Use ASI_PHYS_CACHED to prevent possible page faults + wr %g0, ASI_PHYS_CACHED, %asi ! Use ASI_PHYS_CACHED to prevent possible page faults + ldxa [%g6 + CI_CPCBPADDR] %asi, %g6 lduba [%g6 + PCB_NSAVED] %asi, %g7 sllx %g7, 7, %g5 @@ -3197,10 +3112,6 @@ pcbspill: retry NOTREACHED -pcbspill_fail: - db_enter() - NOTREACHED - sun4v_datatrap: GET_MMFSA(%g3) @@ -5885,9 +5796,11 @@ ENTRY(cpu_switchto) * We also must load up the `in' and `local' registers. */ Lsw_load: - /* set new cpcb */ - stx %i1, [%g7 + CI_CURPROC] ! curproc = newproc; - stx %l1, [%g7 + CI_CPCB] ! cpcb = newpcb; + /* set new cpcb and cpcbpaddr */ + stx %i1, [%g7 + CI_CURPROC] ! curproc = newproc; + ldx [%i1 + P_MD_PCBPADDR], %o2 + stx %l1, [%g7 + CI_CPCB] ! cpcb = newpcb; + stx %o2, [%g7 + CI_CPCBPADDR] ldx [%l1 + PCB_SP], %i6 ldx [%l1 + PCB_PC], %i7 diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c index ddd1c5c72f3..68cadc29a41 100644 --- a/sys/arch/sparc64/sparc64/machdep.c +++ b/sys/arch/sparc64/sparc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.214 2024/03/29 21:26:38 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.215 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */ /*- @@ -205,6 +205,8 @@ cpu_startup(void) #endif proc0.p_addr = proc0paddr; + (void)pmap_extract(pmap_kernel(), (vaddr_t)proc0paddr, + &proc0.p_md.md_pcbpaddr); /* * Good {morning,afternoon,evening,night}. diff --git a/sys/arch/sparc64/sparc64/pmap.c b/sys/arch/sparc64/sparc64/pmap.c index 0b9082b4e6d..c7702065296 100644 --- a/sys/arch/sparc64/sparc64/pmap.c +++ b/sys/arch/sparc64/sparc64/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.115 2024/03/29 21:26:38 miod Exp $ */ +/* $OpenBSD: pmap.c,v 1.116 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: pmap.c,v 1.107 2001/08/31 16:47:41 eeh Exp $ */ /* * @@ -1174,6 +1174,8 @@ remap_data: cpus->ci_next = NULL; /* Redundant, I know. */ cpus->ci_curproc = &proc0; cpus->ci_cpcb = (struct pcb *)u0[0]; /* Need better source */ + cpus->ci_cpcbpaddr = pseg_get(pmap_kernel(), u0[0]) & + TLB_PA_MASK; cpus->ci_upaid = cpu_myid(); cpus->ci_cpuid = 0; cpus->ci_flags = CPUF_RUNNING; diff --git a/sys/arch/sparc64/sparc64/vm_machdep.c b/sys/arch/sparc64/sparc64/vm_machdep.c index ea8c23b71ef..73bf75ecbe0 100644 --- a/sys/arch/sparc64/sparc64/vm_machdep.c +++ b/sys/arch/sparc64/sparc64/vm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_machdep.c,v 1.44 2024/03/29 21:12:58 miod Exp $ */ +/* $OpenBSD: vm_machdep.c,v 1.45 2024/03/29 21:27:53 miod Exp $ */ /* $NetBSD: vm_machdep.c,v 1.38 2001/06/30 00:02:20 eeh Exp $ */ /* @@ -103,6 +103,13 @@ cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb, size_t pcbsz; extern struct proc proc0; + /* + * Cache the physical address of the pcb, to speed up window + * spills in locore. + */ + (void)pmap_extract(pmap_kernel(), (vaddr_t)npcb, + &p2->p_md.md_pcbpaddr); + /* * Save all user registers to p1's stack or, in the case of * user registers and invalid stack pointers, to opcb.