Source-Changes-HG archive

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

[src-draft/trunk]: src/sys/uvm diag code from chuq silvers



details:   https://anonhg.NetBSD.org/src-all/rev/313d895910ab
branches:  trunk
changeset: 949251:313d895910ab
user:      Joerg Sonnenberger <joerg%bec.de@localhost>
date:      Sat Aug 01 22:32:53 2020 +0200

description:
diag code from chuq silvers

diffstat:

 sys/uvm/uvm_amap.c |  49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/uvm/uvm_amap.h |  33 ++++++++++++++++++++++++++++++---
 2 files changed, 78 insertions(+), 4 deletions(-)

diffs (110 lines):

diff -r fc79596b5aec -r 313d895910ab sys/uvm/uvm_amap.c
--- a/sys/uvm/uvm_amap.c        Sat Aug 01 22:32:04 2020 +0200
+++ b/sys/uvm/uvm_amap.c        Sat Aug 01 22:32:53 2020 +0200
@@ -63,6 +63,53 @@
  * local functions
  */
 
+void
+amap_check(const struct vm_amap *amap, const char *which, const char *lockun)
+{
+       int i, c, slot, ptr;
+
+       c = 0;
+       for (i = 0; i < amap->am_maxslot; i++) {
+               if (amap->am_anon[i]) {
+                       c++;
+               }
+       }
+       if (c != amap->am_nused) {
+               printf("bad amap c %d\n", c);
+               goto bad;
+       }
+
+       for (i = 0; i < c; i++) {
+               slot = amap->am_slots[i];
+               if (amap->am_anon[slot] == NULL) {
+                       printf("no anon for idx %d slot %d\n", i, slot);
+                       goto bad;
+               }
+               ptr = amap->am_bckptr[slot];
+               if (ptr != i) {
+                       printf("wrong amap bckptr idx %d bckptr %d\n", i, ptr);
+                       goto bad;
+               }
+       }
+       return;
+
+bad:
+       printf("bad amap %p which %s %s\n", amap, which, lockun);
+       printf("ref %d flags 0x%x\n", amap->am_ref, amap->am_flags);
+       printf("maxslot %d nslot %d nused %d\n",
+              amap->am_maxslot, amap->am_nslot, amap->am_nused);
+       for (i = 0; i < amap->am_maxslot; i++) {
+               printf("am_anon[%d] %p\n", i, amap->am_anon[i]);
+       }
+       for (i = 0; i < amap->am_maxslot; i++) {
+               printf("am_bckptr[%d] %d\n", i, amap->am_bckptr[i]);
+       }
+       for (i = 0; i < amap->am_maxslot; i++) {
+               printf("am_slots[%d] %d\n", i, amap->am_slots[i]);
+       }
+       panic("amap_check failed");
+}
+
 static int
 amap_roundup_slots(int slots)
 {
@@ -797,7 +844,7 @@
         */
 
        amap->am_nused = 0;
-       amap_unlock(amap);
+       amap_unlock1(amap);
        amap_free(amap);
        UVMHIST_LOG(maphist,"<- done!", 0,0,0,0);
 }
diff -r fc79596b5aec -r 313d895910ab sys/uvm/uvm_amap.h
--- a/sys/uvm/uvm_amap.h        Sat Aug 01 22:32:04 2020 +0200
+++ b/sys/uvm/uvm_amap.h        Sat Aug 01 22:32:53 2020 +0200
@@ -251,10 +251,37 @@
  */
 
 #define amap_flags(AMAP)       ((AMAP)->am_flags)
-#define amap_lock(AMAP, OP)    rw_enter((AMAP)->am_lock, (OP))
-#define amap_lock_try(AMAP, OP)        rw_tryenter((AMAP)->am_lock, (OP))
+#define amap_lock1(AMAP, OP)   rw_enter((AMAP)->am_lock, (OP))
+#define amap_lock_try1(AMAP, OP)       rw_tryenter((AMAP)->am_lock, (OP))
 #define amap_refs(AMAP)                ((AMAP)->am_ref)
-#define amap_unlock(AMAP)      rw_exit((AMAP)->am_lock)
+#define amap_unlock1(AMAP)     rw_exit((AMAP)->am_lock)
+
+void amap_check(const struct vm_amap *, const char *, const char *);
+
+#define amap_lock(amap, op) \
+do { \
+       amap_lock1(amap, op); \
+       amap_check(amap, __func__, "lock"); \
+} while (0)
+
+#define amap_lock_try(amap, op) \
+       amap_lock_try_inline(amap, op, __func__)
+
+static inline bool
+amap_lock_try_inline(struct vm_amap *amap, int op, const char *which)
+{
+       bool rv = amap_lock_try1(amap, op);
+       if (rv) {
+               amap_check(amap, which, "trylock");
+       }
+       return rv;
+}
+
+#define amap_unlock(amap) \
+do { \
+       amap_check(amap, __func__, "unlock"); \
+       amap_unlock1(amap); \
+} while (0)
 
 /*
  * if we enable PPREF, then we have a couple of extra functions that



Home | Main Index | Thread Index | Old Index