Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha - Track the currently-activated pmap in struc...



details:   https://anonhg.NetBSD.org/src/rev/8cdf87075d9a
branches:  trunk
changeset: 942715:8cdf87075d9a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Aug 17 00:57:37 2020 +0000

description:
- Track the currently-activated pmap in struct cpu_info.
- Reserve some space in struct cpu_info for future pmap changes.

diffstat:

 sys/arch/alpha/alpha/pmap.c  |  40 ++++++++++++++++++++++++++--------------
 sys/arch/alpha/include/cpu.h |   8 +++++++-
 2 files changed, 33 insertions(+), 15 deletions(-)

diffs (128 lines):

diff -r 016e75d3d3db -r 8cdf87075d9a sys/arch/alpha/alpha/pmap.c
--- a/sys/arch/alpha/alpha/pmap.c       Mon Aug 17 00:55:05 2020 +0000
+++ b/sys/arch/alpha/alpha/pmap.c       Mon Aug 17 00:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.267 2020/08/16 20:04:36 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.268 2020/08/17 00:57:37 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -140,7 +140,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.267 2020/08/16 20:04:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.268 2020/08/17 00:57:37 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2035,9 +2035,8 @@
 void
 pmap_activate(struct lwp *l)
 {
-       struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap;
-       struct pcb *pcb = lwp_getpcb(l);
-       long cpu_id = cpu_number();
+       struct pmap * const pmap = l->l_proc->p_vmspace->vm_map.pmap;
+       struct pcb * const pcb = lwp_getpcb(l);
 
 #ifdef DEBUG
        if (pmapdebug & PDB_FOLLOW)
@@ -2045,21 +2044,24 @@
 #endif
 
        KASSERT(kpreempt_disabled());
-       KASSERT(l == curlwp);
+
+       struct cpu_info * const ci = curcpu();
+
+       KASSERT(l == ci->ci_curlwp);
 
        /* Mark the pmap in use by this processor. */
-       atomic_or_ulong(&pmap->pm_cpus, (1UL << cpu_id));
+       atomic_or_ulong(&pmap->pm_cpus, (1UL << ci->ci_cpuid));
 
        /* Allocate an ASN. */
-       pmap_asn_alloc(pmap, cpu_id);
-       PMAP_ACTIVATE_ASN_SANITY(pmap, cpu_id);
+       pmap_asn_alloc(pmap, ci->ci_cpuid);
+       PMAP_ACTIVATE_ASN_SANITY(pmap, ci->ci_cpuid);
 
        u_long const old_ptbr = pcb->pcb_hw.apcb_ptbr;
        u_int const old_asn = pcb->pcb_hw.apcb_asn;
 
        pcb->pcb_hw.apcb_ptbr =
            ALPHA_K0SEG_TO_PHYS((vaddr_t)pmap->pm_lev1map) >> PGSHIFT;
-       pcb->pcb_hw.apcb_asn = (pmap)->pm_asni[cpu_id].pma_asn;
+       pcb->pcb_hw.apcb_asn = (pmap)->pm_asni[ci->ci_cpuid].pma_asn;
 
        /*
         * Check to see if the ASN or page table base has changed; if
@@ -2072,6 +2074,8 @@
            old_ptbr != pcb->pcb_hw.apcb_ptbr) {
                (void) alpha_pal_swpctx((u_long)l->l_md.md_pcbpaddr);
        }
+
+       ci->ci_pmap = pmap;
 }
 
 /*
@@ -2083,7 +2087,7 @@
 void
 pmap_deactivate(struct lwp *l)
 {
-       struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap;
+       struct pmap * const pmap = l->l_proc->p_vmspace->vm_map.pmap;
 
 #ifdef DEBUG
        if (pmapdebug & PDB_FOLLOW)
@@ -2091,16 +2095,24 @@
 #endif
 
        KASSERT(kpreempt_disabled());
-       KASSERT(l == curlwp);
-
-       atomic_and_ulong(&pmap->pm_cpus, ~(1UL << cpu_number()));
+
+       struct cpu_info * const ci = curcpu();
+
+       KASSERT(l == ci->ci_curlwp);
+
+       atomic_and_ulong(&pmap->pm_cpus, ~(1UL << ci->ci_cpuid));
 
        /*
         * There is no need to switch to a different PTBR here,
         * because a pmap_activate() or SWPCTX is guaranteed
         * before whatever lev1map we're on now is invalidated
         * or before user space is accessed again.
+        *
+        * Because only kernel mappings will be accessed before the
+        * next pmap_activate() call, we consider our CPU to be on
+        * the kernel pmap.
         */
+       ci->ci_pmap = pmap_kernel();
 }
 
 /*
diff -r 016e75d3d3db -r 8cdf87075d9a sys/arch/alpha/include/cpu.h
--- a/sys/arch/alpha/include/cpu.h      Mon Aug 17 00:55:05 2020 +0000
+++ b/sys/arch/alpha/include/cpu.h      Mon Aug 17 00:57:37 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.86 2019/12/01 15:34:44 ad Exp $ */
+/* $NetBSD: cpu.h,v 1.87 2020/08/17 00:57:37 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -128,6 +128,12 @@
        struct trapframe *ci_db_regs;   /* registers for debuggers */
        uint64_t ci_pcc_freq;           /* cpu cycles/second */
 
+#define        CPU_INFO_PMAP_DATA_NQWORDS      16
+
+       struct pmap *ci_pmap;           /* currently-activated pmap */
+                                       /* data used by pmap module */
+       u_long ci_pmap_data[CPU_INFO_PMAP_DATA_NQWORDS];
+
 #if defined(MULTIPROCESSOR)
        volatile u_long ci_flags;       /* flags; see below */
        volatile u_long ci_ipis;        /* interprocessor interrupts pending */



Home | Main Index | Thread Index | Old Index