Source-Changes-HG archive

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

[src/trunk]: src/sys More cleanup. Use a union (pmap_segtab) and a typedef (...



details:   https://anonhg.NetBSD.org/src/rev/b68a9160593f
branches:  trunk
changeset: 780050:b68a9160593f
user:      matt <matt%NetBSD.org@localhost>
date:      Mon Jul 09 17:45:22 2012 +0000

description:
More cleanup.  Use a union (pmap_segtab) and a typedef (pmap_segtab_t).  Add
more functionality from the mips pmap and try to make it more common to ease
the transition for mips in the future.

diffstat:

 sys/arch/powerpc/booke/booke_pmap.c |   20 ++--
 sys/arch/powerpc/booke/trap.c       |   12 +-
 sys/arch/powerpc/include/cpu.h      |    4 +-
 sys/common/pmap/tlb/pmap.c          |    6 +-
 sys/common/pmap/tlb/pmap.h          |   13 +-
 sys/common/pmap/tlb/pmap_segtab.c   |  177 ++++++++++++++++++++++++-----------
 6 files changed, 147 insertions(+), 85 deletions(-)

diffs (truncated from 563 to 300 lines):

diff -r f3b7931071fb -r b68a9160593f sys/arch/powerpc/booke/booke_pmap.c
--- a/sys/arch/powerpc/booke/booke_pmap.c       Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/arch/powerpc/booke/booke_pmap.c       Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: booke_pmap.c,v 1.14 2012/07/05 17:25:36 matt Exp $     */
+/*     $NetBSD: booke_pmap.c,v 1.15 2012/07/09 17:45:22 matt Exp $     */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.14 2012/07/05 17:25:36 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.15 2012/07/09 17:45:22 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/kcore.h>
@@ -57,9 +57,9 @@
 #define        PMAP_SIZE       sizeof(struct pmap)
 #endif
 
-CTASSERT(sizeof(struct pmap_segtab) == NBPG);
+CTASSERT(sizeof(pmap_segtab_t) == NBPG);
 
-struct pmap_segtab pmap_kernel_segtab;
+pmap_segtab_t pmap_kernel_segtab;
 
 void
 pmap_procwr(struct proc *p, vaddr_t va, size_t len)
@@ -124,9 +124,9 @@
 
 #ifdef PMAP_MINIMALTLB
 static pt_entry_t *
-kvtopte(const struct pmap_segtab *stp, vaddr_t va)
+kvtopte(const pmap_segtab_t *stp, vaddr_t va)
 {
-       pt_entry_t * const ptep = stp->seg_ptr[va >> SEGSHIFT];
+       pt_entry_t * const ptep = stp->seg_tab[va >> SEGSHIFT];
        if (ptep == NULL)
                return NULL;
        return &ptep[(va & SEGOFSET) >> PAGE_SHIFT];
@@ -135,7 +135,7 @@
 vaddr_t
 pmap_kvptefill(vaddr_t sva, vaddr_t eva, pt_entry_t pt_entry)
 {
-       const struct pmap_segtab * const stp = pmap_kernel()->pm_segtab;
+       const pmap_segtab_t * const stp = pmap_kernel()->pm_segtab;
        KASSERT(sva == trunc_page(sva));
        pt_entry_t *ptep = kvtopte(stp, sva);
        for (; sva < eva; sva += NBPG) {
@@ -153,7 +153,7 @@
 pmap_bootstrap(vaddr_t startkernel, vaddr_t endkernel,
        phys_ram_seg_t *avail, size_t cnt)
 {
-       struct pmap_segtab * const stp = &pmap_kernel_segtab;
+       pmap_segtab_t * const stp = &pmap_kernel_segtab;
 
        /*
         * Initialize the kernel segment table.
@@ -226,7 +226,7 @@
         * an extra page for the segment table and allows the user/kernel
         * access to be common.
         */
-       void **ptp = &stp->seg_ptr[VM_MIN_KERNEL_ADDRESS >> SEGSHIFT];
+       pt_entry_t **ptp = &stp->seg_tab[VM_MIN_KERNEL_ADDRESS >> SEGSHIFT];
        pt_entry_t *ptep = (void *)kv_segtabs;
        memset(ptep, 0, NBPG * kv_nsegtabs);
        for (size_t i = 0; i < kv_nsegtabs; i++, ptep += NPTEPG) {
@@ -244,7 +244,7 @@
        avail[0].size -= NBPG * dm_nsegtabs;
        endkernel += NBPG * dm_nsegtabs;
 
-       ptp = stp->seg_ptr;
+       ptp = stp->seg_tab;
        ptep = (void *)dm_segtabs;
        memset(ptep, 0, NBPG * dm_nsegtabs);
        for (size_t i = 0; i < dm_nsegtabs; i++, ptp++, ptep += NPTEPG) {
diff -r f3b7931071fb -r b68a9160593f sys/arch/powerpc/booke/trap.c
--- a/sys/arch/powerpc/booke/trap.c     Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/arch/powerpc/booke/trap.c     Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.16 2012/07/05 17:25:36 matt Exp $   */
+/*     $NetBSD: trap.c,v 1.17 2012/07/09 17:45:22 matt Exp $   */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.16 2012/07/05 17:25:36 matt Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.17 2012/07/09 17:45:22 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -138,17 +138,17 @@
 }
 
 /*
- * We could use pmap_pte_lookip but this slightly faster since we already
+ * We could use pmap_pte_lookup but this slightly faster since we already
  * the segtab pointers in cpu_info.
  */
 static inline pt_entry_t *
 trap_pte_lookup(struct trapframe *tf, vaddr_t va, register_t psl_mask)
 {
-       struct pmap_segtab ** const stps = &curcpu()->ci_pmap_kern_segtab;
-       struct pmap_segtab * const stp = stps[(tf->tf_srr1 / psl_mask) & 1];
+       pmap_segtab_t ** const stps = &curcpu()->ci_pmap_kern_segtab;
+       pmap_segtab_t * const stp = stps[(tf->tf_srr1 / psl_mask) & 1];
        if (__predict_false(stp == NULL))
                return NULL;
-       pt_entry_t * const ptep = stp->seg_ptr[va >> SEGSHIFT];
+       pt_entry_t * const ptep = stp->seg_tab[va >> SEGSHIFT];
        if (__predict_false(ptep == NULL))
                return NULL;
        return ptep + ((va & SEGOFSET) >> PAGE_SHIFT);
diff -r f3b7931071fb -r b68a9160593f sys/arch/powerpc/include/cpu.h
--- a/sys/arch/powerpc/include/cpu.h    Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/arch/powerpc/include/cpu.h    Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.91 2012/04/10 16:57:50 matt Exp $    */
+/*     $NetBSD: cpu.h,v 1.92 2012/07/09 17:45:22 matt Exp $    */
 
 /*
  * Copyright (C) 1999 Wolfgang Solfrank.
@@ -114,7 +114,7 @@
        register_t ci_savearea[CPUSAVE_SIZE];
 #if defined(PPC_BOOKE) || defined(MODULAR) || defined(_MODULE)
        uint32_t ci_pmap_asid_cur;
-       struct pmap_segtab *ci_pmap_segtabs[2];
+       union pmap_segtab *ci_pmap_segtabs[2];
 #define        ci_pmap_kern_segtab     ci_pmap_segtabs[0]
 #define        ci_pmap_user_segtab     ci_pmap_segtabs[1]
        struct pmap_tlb_info *ci_tlb_info;
diff -r f3b7931071fb -r b68a9160593f sys/common/pmap/tlb/pmap.c
--- a/sys/common/pmap/tlb/pmap.c        Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/common/pmap/tlb/pmap.c        Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.15 2012/07/05 16:55:11 matt Exp $   */
+/*     $NetBSD: pmap.c,v 1.16 2012/07/09 17:45:22 matt Exp $   */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.15 2012/07/05 16:55:11 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.16 2012/07/09 17:45:22 matt Exp $");
 
 /*
  *     Manages physical address maps.
@@ -530,7 +530,7 @@
        PMAP_COUNT(destroy);
        kpreempt_disable();
        pmap_tlb_asid_release_all(pmap);
-       pmap_segtab_destroy(pmap);
+       pmap_segtab_destroy(pmap, NULL, 0);
 
        pool_put(&pmap_pmap_pool, pmap);
        kpreempt_enable();
diff -r f3b7931071fb -r b68a9160593f sys/common/pmap/tlb/pmap.h
--- a/sys/common/pmap/tlb/pmap.h        Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/common/pmap/tlb/pmap.h        Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.h,v 1.15 2012/07/05 17:24:54 matt Exp $   */
+/*     $NetBSD: pmap.h,v 1.16 2012/07/09 17:45:22 matt Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -94,9 +94,10 @@
 /*
  * Each seg_tab point an array of pt_entry [NPTEPG]
  */
-struct pmap_segtab {
-       void    *seg_ptr[PMAP_SEGTABSIZE];
-};
+typedef union pmap_segtab {
+       union pmap_segtab *     seg_seg[PMAP_SEGTABSIZE];
+       pt_entry_t *            seg_tab[PMAP_SEGTABSIZE];
+} pmap_segtab_t;
 
 #ifdef _KERNEL
 struct pmap;
@@ -108,7 +109,7 @@
        uintptr_t);
 void pmap_segtab_activate(struct pmap *, struct lwp *);
 void pmap_segtab_init(struct pmap *);
-void pmap_segtab_destroy(struct pmap *);
+void pmap_segtab_destroy(struct pmap *, pte_callback_t, uintptr_t);
 extern kmutex_t pmap_segtab_lock;
 #endif /* _KERNEL */
 
@@ -137,7 +138,7 @@
        __cpuset_t              pm_onproc;      /* pmap is active on ... */
        volatile u_int          pm_shootdown_pending;
 #endif
-       struct pmap_segtab      *pm_segtab;     /* pointers to pages of PTEs */
+       pmap_segtab_t *         pm_segtab;      /* pointers to pages of PTEs */
        u_int                   pm_count;       /* pmap reference count */
        u_int                   pm_flags;
 #define        PMAP_DEFERRED_ACTIVATE  0x0001
diff -r f3b7931071fb -r b68a9160593f sys/common/pmap/tlb/pmap_segtab.c
--- a/sys/common/pmap/tlb/pmap_segtab.c Mon Jul 09 17:36:55 2012 +0000
+++ b/sys/common/pmap/tlb/pmap_segtab.c Mon Jul 09 17:45:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_segtab.c,v 1.7 2012/07/05 17:24:54 matt Exp $     */
+/*     $NetBSD: pmap_segtab.c,v 1.8 2012/07/09 17:45:22 matt Exp $     */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.7 2012/07/05 17:24:54 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_segtab.c,v 1.8 2012/07/09 17:45:22 matt Exp $");
 
 /*
  *     Manages physical address maps.
@@ -107,10 +107,10 @@
 
 #include <uvm/uvm.h>
 
-CTASSERT(NBPG >= sizeof(struct pmap_segtab));
+CTASSERT(NBPG >= sizeof(pmap_segtab_t));
 
 struct pmap_segtab_info {
-       struct pmap_segtab *free_segtab;        /* free list kept locally */
+       pmap_segtab_t *free_segtab;     /* free list kept locally */
 #ifdef DEBUG
        uint32_t nget_segtab;
        uint32_t nput_segtab;
@@ -119,27 +119,45 @@
 #else
 #define        SEGTAB_ADD(n, v)        ((void) 0)
 #endif
-} pmap_segtab_info;
+#ifdef PMAP_PTP_CACHE
+       struct pgflist ptp_pgflist;     /* Keep a list of idle page tables. */
+#endif
+} pmap_segtab_info = {
+#ifdef PMAP_PTP_CACHE
+       .ptp_pgflist = LIST_HEAD_INITIALIZER(pmap_segtab_info.ptp_pgflist),
+#endif
+};
 
 kmutex_t pmap_segtab_lock __cacheline_aligned;
 
 static inline struct vm_page *
 pmap_pte_pagealloc(void)
 {
-       return pmap_md_alloc_poolpage(UVM_PGA_ZERO|UVM_PGA_USERESERVE);
+       struct vm_page *pg;
+
+       pg = pmap_md_alloc_poolpage(UVM_PGA_ZERO|UVM_PGA_USERESERVE);
+       if (pg) {
+#ifdef UVM_PAGE_TRKOWN
+               pg->owner_tag = NULL;
+#endif
+               UVM_PAGE_OWN(pg, "pmap-ptp");
+       }
+
+       return pg;
 }
 
-static inline pt_entry_t * 
+static inline pt_entry_t *
 pmap_segmap(struct pmap *pmap, vaddr_t va)
 {
-       struct pmap_segtab *stp = pmap->pm_segtab;
+       pmap_segtab_t *stp = pmap->pm_segtab;
        KASSERT(pmap != pmap_kernel() || !pmap_md_direct_mapped_vaddr_p(va));
 #ifdef _LP64
-       stp = stp->seg_ptr[(va >> XSEGSHIFT) & (NSEGPG - 1)];
+       stp = stp->seg_seg[(va >> XSEGSHIFT) & (NSEGPG - 1)];
        if (stp == NULL)
                return NULL;
 #endif
-       return stp->seg_ptr[(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1)];
+
+       return stp->seg_tab[(va >> SEGSHIFT) & (PMAP_SEGTABSIZE - 1)];
 }
 
 pt_entry_t *
@@ -153,52 +171,74 @@
 }
 
 static void
-pmap_segtab_free(struct pmap_segtab *stp)
+pmap_segtab_free(pmap_segtab_t *stp)
 {
        /*
         * Insert the the segtab into the segtab freelist.
         */
        mutex_spin_enter(&pmap_segtab_lock);
-       stp->seg_ptr[0] = pmap_segtab_info.free_segtab;
+       stp->seg_seg[0] = pmap_segtab_info.free_segtab;



Home | Main Index | Thread Index | Old Index