Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Spinkle __predict_false to LOCKDEBUG functions



details:   https://anonhg.NetBSD.org/src/rev/5d7039b4dc3c
branches:  trunk
changeset: 359665:5d7039b4dc3c
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Feb 20 03:34:52 2018 +0000

description:
Spinkle __predict_false to LOCKDEBUG functions

Panics and lockdebug failures are unlikely to occur normally.

diffstat:

 sys/kern/subr_lockdebug.c |  64 ++++++++++++++++++++++++----------------------
 1 files changed, 34 insertions(+), 30 deletions(-)

diffs (255 lines):

diff -r f8a337ab3109 -r 5d7039b4dc3c sys/kern/subr_lockdebug.c
--- a/sys/kern/subr_lockdebug.c Tue Feb 20 02:52:41 2018 +0000
+++ b/sys/kern/subr_lockdebug.c Tue Feb 20 03:34:52 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_lockdebug.c,v 1.59 2018/02/14 03:56:26 ozaki-r Exp $      */
+/*     $NetBSD: subr_lockdebug.c,v 1.60 2018/02/20 03:34:52 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.59 2018/02/14 03:56:26 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.60 2018/02/20 03:34:52 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -196,7 +196,7 @@
        lockdebug_t *ld;
 
        ld = lockdebug_lookup1(lock);
-       if (ld == NULL) {
+       if (__predict_false(ld == NULL)) {
                panic("%s,%zu: uninitialized lock (lock=%p, from=%08"
                    PRIxPTR ")", func, line, lock, where);
        }
@@ -246,14 +246,14 @@
        lockdebug_t *ld;
        int s;
 
-       if (lo == NULL || panicstr != NULL || ld_panic)
+       if (__predict_false(lo == NULL || panicstr != NULL || ld_panic))
                return false;
-       if (ld_freeptr == 0)
+       if (__predict_false(ld_freeptr == 0))
                lockdebug_init();
 
        s = splhigh();
        __cpu_simple_lock(&ld_mod_lk);
-       if ((ld = lockdebug_lookup1(lock)) != NULL) {
+       if (__predict_false((ld = lockdebug_lookup1(lock)) != NULL)) {
                __cpu_simple_unlock(&ld_mod_lk);
                lockdebug_abort1(func, line, ld, s, "already initialized",
                    true);
@@ -281,7 +281,7 @@
        } else if (ci->ci_lkdebug_recurse == 1 && ld_nfree < LD_SLOP) {
                s = lockdebug_more(s);
        }
-       if ((ld = TAILQ_FIRST(&ld_free)) == NULL) {
+       if (__predict_false((ld = TAILQ_FIRST(&ld_free)) == NULL)) {
                __cpu_simple_unlock(&ld_mod_lk);
                splx(s);
                return false;
@@ -290,7 +290,7 @@
        ld_nfree--;
        ci->ci_lkdebug_recurse--;
 
-       if (ld->ld_lock != NULL) {
+       if (__predict_false(ld->ld_lock != NULL)) {
                panic("%s,%zu: corrupt table ld %p", func, line, ld);
        }
 
@@ -322,20 +322,21 @@
        lockdebug_t *ld;
        int s;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
        __cpu_simple_lock(&ld_mod_lk);
        ld = lockdebug_lookup(func, line, lock,
            (uintptr_t) __builtin_return_address(0));
-       if (ld == NULL) {
+       if (__predict_false(ld == NULL)) {
                __cpu_simple_unlock(&ld_mod_lk);
                panic("%s,%zu: destroying uninitialized object %p"
                    "(ld_lock=%p)", func, line, lock, ld->ld_lock);
                return;
        }
-       if ((ld->ld_flags & LD_LOCKED) != 0 || ld->ld_shares != 0) {
+       if (__predict_false((ld->ld_flags & LD_LOCKED) != 0 ||
+           ld->ld_shares != 0)) {
                __cpu_simple_unlock(&ld_mod_lk);
                lockdebug_abort1(func, line, ld, s, "is locked or in use",
                    true);
@@ -430,7 +431,7 @@
        (void)shared;
        recurse = false;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
@@ -446,7 +447,7 @@
                        recurse = true;
        }
        if (cpu_intr_p()) {
-               if ((ld->ld_flags & LD_SLEEPER) != 0) {
+               if (__predict_false((ld->ld_flags & LD_SLEEPER) != 0)) {
                        lockdebug_abort1(func, line, ld, s,
                            "acquiring sleep lock from interrupt context",
                            true);
@@ -457,7 +458,7 @@
                ld->ld_shwant++;
        else if (shared == 0)
                ld->ld_exwant++;
-       if (recurse) {
+       if (__predict_false(recurse)) {
                lockdebug_abort1(func, line, ld, s, "locking against myself",
                    true);
                return;
@@ -479,7 +480,7 @@
        lockdebug_t *ld;
        int s;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
@@ -493,7 +494,7 @@
                        /* nothing */
                } else if (ld->ld_shares++ == 0) {
                        ld->ld_locked = (uintptr_t)cvlock;
-               } else if (cvlock != (void *)ld->ld_locked) {
+               } else if (__predict_false(cvlock != (void *)ld->ld_locked)) {
                        lockdebug_abort1(func, line, ld, s,
                            "multiple locks used with condition variable",
                            true);
@@ -505,7 +506,7 @@
                ld->ld_shares++;
                ld->ld_shwant--;
        } else {
-               if ((ld->ld_flags & LD_LOCKED) != 0) {
+               if (__predict_false((ld->ld_flags & LD_LOCKED) != 0)) {
                        lockdebug_abort1(func, line, ld, s, "already locked",
                            true);
                        return;
@@ -539,7 +540,7 @@
        lockdebug_t *ld;
        int s;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
@@ -554,12 +555,12 @@
                        ld->ld_shares--;
                }
        } else if (shared) {
-               if (l->l_shlocks == 0) {
+               if (__predict_false(l->l_shlocks == 0)) {
                        lockdebug_abort1(func, line, ld, s,
                            "no shared locks held by LWP", true);
                        return;
                }
-               if (ld->ld_shares == 0) {
+               if (__predict_false(ld->ld_shares == 0)) {
                        lockdebug_abort1(func, line, ld, s,
                            "no shared holds on this lock", true);
                        return;
@@ -573,20 +574,21 @@
                if (ld->ld_cpu == (uint16_t)cpu_index(curcpu()))
                        ld->ld_cpu = (uint16_t)-1;
        } else {
-               if ((ld->ld_flags & LD_LOCKED) == 0) {
+               if (__predict_false((ld->ld_flags & LD_LOCKED) == 0)) {
                        lockdebug_abort1(func, line, ld, s, "not locked", true);
                        return;
                }
 
                if ((ld->ld_flags & LD_SLEEPER) != 0) {
-                       if (ld->ld_lwp != curlwp) {
+                       if (__predict_false(ld->ld_lwp != curlwp)) {
                                lockdebug_abort1(func, line, ld, s,
                                    "not held by current LWP", true);
                                return;
                        }
                        TAILQ_REMOVE(&l->l_ld_locks, ld, ld_chain);
                } else {
-                       if (ld->ld_cpu != (uint16_t)cpu_index(curcpu())) {
+                       uint16_t idx = (uint16_t)cpu_index(curcpu());
+                       if (__predict_false(ld->ld_cpu != idx)) {
                                lockdebug_abort1(func, line, ld, s,
                                    "not held by current CPU", true);
                                return;
@@ -614,7 +616,7 @@
        lockdebug_t *ld;
        int s;
 
-       if (panicstr != NULL || ld_panic || lock == (void *)&lbolt)
+       if (__predict_false(panicstr != NULL || ld_panic || lock == (void *)&lbolt))
                return;
 
        s = splhigh();
@@ -627,7 +629,8 @@
         * If it has any waiters, ensure that they are using the
         * same interlock.
         */
-       if (ld->ld_shares != 0 && !mutex_owned((kmutex_t *)ld->ld_locked)) {
+       if (__predict_false(ld->ld_shares != 0 &&
+           !mutex_owned((kmutex_t *)ld->ld_locked))) {
                lockdebug_abort1(func, line, ld, s, "interlocking mutex not "
                    "held during wakeup", true);
                return;
@@ -650,7 +653,7 @@
        lockdebug_t *ld;
        int s;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
@@ -669,7 +672,8 @@
                splx(s);
                return;
        }
-       if ((ld = TAILQ_FIRST(&l->l_ld_locks)) != NULL) {
+       ld = TAILQ_FIRST(&l->l_ld_locks);
+       if (__predict_false(ld != NULL)) {
                __cpu_simple_lock(&ld->ld_spinlock);
                lockdebug_abort1(func, line, ld, s, "sleep lock held", true);
                return;
@@ -700,7 +704,7 @@
        struct cpu_info *ci;
        int s;
 
-       if (panicstr != NULL || ld_panic)
+       if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
        s = splhigh();
@@ -710,14 +714,14 @@
        if (ld != NULL) {
                const uintptr_t lock = (uintptr_t)ld->ld_lock;
 
-               if ((uintptr_t)base > lock)
+               if (__predict_false((uintptr_t)base > lock))
                        panic("%s,%zu: corrupt tree ld=%p, base=%p, sz=%zu",
                            func, line, ld, base, sz);
                if (lock >= (uintptr_t)base + sz)
                        ld = NULL;
        }
        __cpu_simple_unlock(&ci->ci_data.cpu_ld_lock);
-       if (ld != NULL) {
+       if (__predict_false(ld != NULL)) {
                __cpu_simple_lock(&ld->ld_spinlock);
                lockdebug_abort1(func, line, ld, s,
                    "allocation contains active lock", !cold);



Home | Main Index | Thread Index | Old Index