Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm/pmap convert to use actual __BITMAP_*() macros from ...



details:   https://anonhg.NetBSD.org/src/rev/10575f65f1ab
branches:  trunk
changeset: 829961:10575f65f1ab
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Mon Feb 19 22:01:15 2018 +0000

description:
convert to use actual __BITMAP_*() macros from <sys/bitops.h>, and make
it possible to override the ASID bitmap length; default to 256 ASIDs as before

XXX NFCI; compile tested only on evbpcc and evbmips, unfortunately didn't
find any combination of port using the MI pmap_tlb.c and working in QEMU

diffstat:

 sys/uvm/pmap/pmap_tlb.c |  64 +++++++++++++++++++++---------------------------
 sys/uvm/pmap/pmap_tlb.h |   8 ++++-
 2 files changed, 34 insertions(+), 38 deletions(-)

diffs (199 lines):

diff -r 118cdbe5e166 -r 10575f65f1ab sys/uvm/pmap/pmap_tlb.c
--- a/sys/uvm/pmap/pmap_tlb.c   Mon Feb 19 21:40:45 2018 +0000
+++ b/sys/uvm/pmap/pmap_tlb.c   Mon Feb 19 22:01:15 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_tlb.c,v 1.24 2018/02/19 21:40:45 jdolecek Exp $   */
+/*     $NetBSD: pmap_tlb.c,v 1.25 2018/02/19 22:01:15 jdolecek Exp $   */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.24 2018/02/19 21:40:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_tlb.c,v 1.25 2018/02/19 22:01:15 jdolecek Exp $");
 
 /*
  * Manages address spaces in a TLB.
@@ -140,6 +140,10 @@
 
 #define        IFCONSTANT(x)   (__builtin_constant_p((x)) ? (x) : 0)
 
+#if KERNEL_PID > 31
+#error "KERNEL_PID expected in range 0-31"
+#endif
+
 struct pmap_tlb_info pmap_tlb0_info = {
        .ti_name = "tlb0",
        .ti_asid_hint = KERNEL_PID + 1,
@@ -147,7 +151,7 @@
        .ti_asid_max = IFCONSTANT(PMAP_TLB_NUM_PIDS - 1),
        .ti_asids_free = IFCONSTANT(PMAP_TLB_NUM_PIDS - (1 + KERNEL_PID)),
 #endif
-       .ti_asid_bitmap[0] = (2 << KERNEL_PID) - 1,
+       .ti_asid_bitmap._b[0] = __BIT(KERNEL_PID),
 #ifdef PMAP_TLB_WIRED_UPAGES
        .ti_wired = PMAP_TLB_WIRED_UPAGES,
 #endif
@@ -167,22 +171,19 @@
 u_int pmap_ntlbs = 1;
 #endif
 
-#define        __BITMAP_SET(bm, n) \
-       ((bm)[(n) / (8*sizeof(bm[0]))] |= 1LU << ((n) % (8*sizeof(bm[0]))))
-#define        __BITMAP_CLR(bm, n) \
-       ((bm)[(n) / (8*sizeof(bm[0]))] &= ~(1LU << ((n) % (8*sizeof(bm[0])))))
-#define        __BITMAP_ISSET_P(bm, n) \
-       (((bm)[(n) / (8*sizeof(bm[0]))] & (1LU << ((n) % (8*sizeof(bm[0]))))) != 0)
-
 #define        TLBINFO_ASID_MARK_UNUSED(ti, asid) \
-       __BITMAP_CLR((ti)->ti_asid_bitmap, (asid))
+       __BITMAP_CLR((asid), &(ti)->ti_asid_bitmap)
 #define        TLBINFO_ASID_MARK_USED(ti, asid) \
-       __BITMAP_SET((ti)->ti_asid_bitmap, (asid))
+       __BITMAP_SET((asid), &(ti)->ti_asid_bitmap)
 #define        TLBINFO_ASID_INUSE_P(ti, asid) \
-       __BITMAP_ISSET_P((ti)->ti_asid_bitmap, (asid))
+       __BITMAP_ISSET((asid), &(ti)->ti_asid_bitmap)
+#define        TLBINFO_ASID_RESET(ti) \
+       do {                                            \
+               __BITMAP_ZERO(&ti->ti_asid_bitmap);     \
+               TLBINFO_ASID_MARK_USED(ti, KERNEL_PID); \
+       } while (0)
 #define        TLBINFO_ASID_INITIAL_FREE(ti) \
        ((ti)->ti_asid_max + 1 /* 0 */ - 1 /* reserved KERNEL_PID */)
-       
 
 #ifdef MULTIPROCESSOR
 __unused static inline bool
@@ -337,7 +338,7 @@
                KASSERT(pmap_tlbs[pmap_ntlbs] == NULL);
 
                ti->ti_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
-               ti->ti_asid_bitmap[0] = (2 << KERNEL_PID) - 1;
+               TLBINFO_ASID_MARK_USED(ti, KERNEL_PID);
                ti->ti_asid_hint = KERNEL_PID + 1;
                ti->ti_asid_max = pmap_tlbs[0]->ti_asid_max;
                ti->ti_asids_free = TLBINFO_ASID_INITIAL_FREE(ti);
@@ -350,6 +351,8 @@
                snprintf(ti->ti_name, sizeof(ti->ti_name), "tlb%u",
                    ti->ti_index);
                pmap_tlb_info_evcnt_attach(ti);
+
+               KASSERT(ti->ti_asid_max < PMAP_TLB_BITMAP_LENGTH);
                return;
        }
 #endif
@@ -368,7 +371,7 @@
                ti->ti_asids_free = TLBINFO_ASID_INITIAL_FREE(ti);
        }
 
-       KASSERT(ti->ti_asid_max < sizeof(ti->ti_asid_bitmap)*8);
+       KASSERT(ti->ti_asid_max < PMAP_TLB_BITMAP_LENGTH);
 }
 
 #if defined(MULTIPROCESSOR)
@@ -413,9 +416,6 @@
 static void
 pmap_tlb_asid_reinitialize(struct pmap_tlb_info *ti, enum tlb_invalidate_op op)
 {
-       const size_t asid_bitmap_words =
-           ti->ti_asid_max / (8 * sizeof(ti->ti_asid_bitmap[0]));
-
        UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
        UVMHIST_LOG(maphist, "(ti=%#jx, op=%ju)", (uintptr_t)ti, op, 0, 0);
 
@@ -429,10 +429,7 @@
         */
        ti->ti_asids_free = TLBINFO_ASID_INITIAL_FREE(ti);
        ti->ti_asid_hint = KERNEL_PID + 1;
-       ti->ti_asid_bitmap[0] = (2 << KERNEL_PID) - 1;
-       for (size_t word = 1; word <= asid_bitmap_words; word++) {
-               ti->ti_asid_bitmap[word] = 0;
-       }
+       TLBINFO_ASID_RESET(ti);
 
        switch (op) {
 #if defined(MULTIPROCESSOR) && defined(PMAP_TLB_NEED_SHOOTDOWN)
@@ -455,8 +452,8 @@
                 */
 #if !defined(MULTIPROCESSOR) || defined(PMAP_TLB_NEED_SHOOTDOWN)
                pmap_tlb_asid_check();
-               const u_int asids_found = tlb_record_asids(ti->ti_asid_bitmap,
-                   ti->ti_asid_max);
+               const u_int asids_found = tlb_record_asids(
+                   ti->ti_asid_bitmap._b, ti->ti_asid_max);
                pmap_tlb_asid_check();
                KASSERT(asids_found == pmap_tlb_asid_count(ti));
                if (__predict_false(asids_found >= ti->ti_asid_max / 2)) {
@@ -473,12 +470,7 @@
                         */
                        tlb_invalidate_all();
 #endif /* MULTIPROCESSOR && !PMAP_TLB_NEED_SHOOTDOWN */
-                       ti->ti_asid_bitmap[0] = (2 << KERNEL_PID) - 1;
-                       for (size_t word = 1;
-                            word <= asid_bitmap_words;
-                            word++) {
-                               ti->ti_asid_bitmap[word] = 0;
-                       }
+                       TLBINFO_ASID_RESET(ti);
                        ti->ti_asids_free = TLBINFO_ASID_INITIAL_FREE(ti);
 #if !defined(MULTIPROCESSOR) || defined(PMAP_TLB_NEED_SHOOTDOWN)
                } else {
@@ -829,11 +821,11 @@
         * a new one.
         */
        if (__predict_true(TLBINFO_ASID_INUSE_P(ti, ti->ti_asid_hint))) {
-               const size_t nbpw = 8 * sizeof(ti->ti_asid_bitmap[0]);
+               const size_t nbpw = NBBY * sizeof(ti->ti_asid_bitmap._b[0]);
                size_t i;
                u_long bits;
-               for (i = 0; (bits = ~ti->ti_asid_bitmap[i]) == 0; i++) {
-                       KASSERT(i < __arraycount(ti->ti_asid_bitmap) - 1);
+               for (i = 0; (bits = ~ti->ti_asid_bitmap._b[i]) == 0; i++) {
+                       KASSERT(i < __arraycount(ti->ti_asid_bitmap._b) - 1);
                }
                /*
                 * ffs wants to find the first bit set while we want
@@ -850,9 +842,9 @@
        KASSERT(ti->ti_asid_hint <= ti->ti_asid_max);
        KASSERTMSG(PMAP_TLB_FLUSH_ASID_ON_RESET
            || TLBINFO_ASID_INUSE_P(ti, ti->ti_asid_hint - 1),
-           "hint %u bitmap %p", ti->ti_asid_hint, ti->ti_asid_bitmap);
+           "hint %u bitmap %p", ti->ti_asid_hint, &ti->ti_asid_bitmap);
        KASSERTMSG(!TLBINFO_ASID_INUSE_P(ti, ti->ti_asid_hint),
-           "hint %u bitmap %p", ti->ti_asid_hint, ti->ti_asid_bitmap);
+           "hint %u bitmap %p", ti->ti_asid_hint, &ti->ti_asid_bitmap);
 
        /*
         * The hint contains our next ASID so take it and advance the hint.
diff -r 118cdbe5e166 -r 10575f65f1ab sys/uvm/pmap/pmap_tlb.h
--- a/sys/uvm/pmap/pmap_tlb.h   Mon Feb 19 21:40:45 2018 +0000
+++ b/sys/uvm/pmap/pmap_tlb.h   Mon Feb 19 22:01:15 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_tlb.h,v 1.12 2018/02/19 21:20:33 jdolecek Exp $   */
+/*     $NetBSD: pmap_tlb.h,v 1.13 2018/02/19 22:01:15 jdolecek Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,6 +76,7 @@
 
 #include <sys/evcnt.h>
 #include <sys/kcpuset.h>
+#include <sys/bitops.h>
 
 #if !defined(PMAP_TLB_MAX)
 # if defined(MULTIPROCESSOR)
@@ -141,7 +142,10 @@
 #define tlbinfo_index(ti)      ((void)(ti), 0)
 #endif
        struct evcnt ti_evcnt_asid_reinits;
-       u_long ti_asid_bitmap[256 / (sizeof(u_long) * 8)];
+#ifndef PMAP_TLB_BITMAP_LENGTH
+#define        PMAP_TLB_BITMAP_LENGTH 256
+#endif
+       __BITMAP_TYPE(, u_long, PMAP_TLB_BITMAP_LENGTH) ti_asid_bitmap;
 };
 
 #ifdef _KERNEL



Home | Main Index | Thread Index | Old Index