Source-Changes-HG archive

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

[src/trunk]: src/sys Introduce kcov_silence_enter() and kcov_silence_leave(),...



details:   https://anonhg.NetBSD.org/src/rev/59ac714dfd14
branches:  trunk
changeset: 932764:59ac714dfd14
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri May 15 13:09:02 2020 +0000

description:
Introduce kcov_silence_enter() and kcov_silence_leave(), to allow to
temporarily disable KCOV on the current lwp. Should be used in the rare
but problematic cases where extreme noise is introduced by an
uninteresting subsystem.

Use this capability to silence KCOV during the LOCKDEBUG lookups. This
divides the size of the KCOV output by more than two in my KCOV+vHCI
tests.

diffstat:

 sys/kern/subr_kcov.c      |  28 +++++++++++++++++++++++++++-
 sys/kern/subr_lockdebug.c |  13 +++++++++++--
 sys/sys/kcov.h            |   6 +++++-
 3 files changed, 43 insertions(+), 4 deletions(-)

diffs (140 lines):

diff -r a6b6233cc24e -r 59ac714dfd14 sys/kern/subr_kcov.c
--- a/sys/kern/subr_kcov.c      Fri May 15 12:34:52 2020 +0000
+++ b/sys/kern/subr_kcov.c      Fri May 15 13:09:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kcov.c,v 1.13 2020/05/15 12:34:52 maxv Exp $      */
+/*     $NetBSD: subr_kcov.c,v 1.14 2020/05/15 13:09:02 maxv Exp $      */
 
 /*
  * Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
@@ -108,6 +108,7 @@
        /* Local only */
        kmutex_t lock;
        bool lwpfree;
+       bool silenced;
 
        /* Pointer to the end of the structure, if any */
        struct kcov_desc *remote;
@@ -423,6 +424,26 @@
 
 /* -------------------------------------------------------------------------- */
 
+void
+kcov_silence_enter(void)
+{
+       kcov_t *kd = curlwp->l_kcov;
+
+       if (kd != NULL)
+               kd->silenced = true;
+}
+
+void
+kcov_silence_leave(void)
+{
+       kcov_t *kd = curlwp->l_kcov;
+
+       if (kd != NULL)
+               kd->silenced = false;
+}
+
+/* -------------------------------------------------------------------------- */
+
 static int
 kcov_open(dev_t dev, int flag, int mode, struct lwp *l)
 {
@@ -581,6 +602,11 @@
                return;
        }
 
+       if (__predict_false(kd->silenced)) {
+               /* Silenced. */
+               return;
+       }
+
        if (kd->mode != KCOV_MODE_TRACE_PC) {
                /* PC tracing mode not enabled */
                return;
diff -r a6b6233cc24e -r 59ac714dfd14 sys/kern/subr_lockdebug.c
--- a/sys/kern/subr_lockdebug.c Fri May 15 12:34:52 2020 +0000
+++ b/sys/kern/subr_lockdebug.c Fri May 15 13:09:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_lockdebug.c,v 1.76 2020/04/10 17:16:21 ad Exp $   */
+/*     $NetBSD: subr_lockdebug.c,v 1.77 2020/05/15 13:09:02 maxv Exp $ */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.76 2020/04/10 17:16:21 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.77 2020/05/15 13:09:02 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -52,6 +52,7 @@
 #include <sys/lock.h>
 #include <sys/rbtree.h>
 #include <sys/ksyms.h>
+#include <sys/kcov.h>
 
 #include <machine/lock.h>
 
@@ -209,7 +210,10 @@
 {
        lockdebug_t *ld;
 
+       kcov_silence_enter();
        ld = lockdebug_lookup1(lock);
+       kcov_silence_leave();
+
        if (__predict_false(ld == NULL)) {
                panic("%s,%zu: uninitialized lock (lock=%p, from=%08"
                    PRIxPTR ")", func, line, lock, where);
@@ -675,6 +679,8 @@
        if (__predict_false(panicstr != NULL || ld_panic))
                return;
 
+       kcov_silence_enter();
+
        s = splhigh();
        ci = curcpu();
        __cpu_simple_lock(&ci->ci_data.cpu_ld_lock);
@@ -693,9 +699,12 @@
                __cpu_simple_lock(&ld->ld_spinlock);
                lockdebug_abort1(func, line, ld, s,
                    "allocation contains active lock", !cold);
+               kcov_silence_leave();
                return;
        }
        splx(s);
+
+       kcov_silence_leave();
 }
 #endif /* _KERNEL */
 
diff -r a6b6233cc24e -r 59ac714dfd14 sys/sys/kcov.h
--- a/sys/sys/kcov.h    Fri May 15 12:34:52 2020 +0000
+++ b/sys/sys/kcov.h    Fri May 15 13:09:02 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: kcov.h,v 1.8 2020/05/15 12:34:52 maxv Exp $        */
+/*      $NetBSD: kcov.h,v 1.9 2020/05/15 13:09:02 maxv Exp $        */
 
 /*
  * Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
@@ -66,11 +66,15 @@
 void kcov_remote_register(uint64_t, uint64_t);
 void kcov_remote_enter(uint64_t, uint64_t);
 void kcov_remote_leave(uint64_t, uint64_t);
+void kcov_silence_enter(void);
+void kcov_silence_leave(void);
 void kcov_lwp_free(struct lwp *);
 #else
 #define kcov_remote_register(s, i)     __nothing
 #define kcov_remote_enter(s, i)                __nothing
 #define kcov_remote_leave(s, i)                __nothing
+#define kcov_silence_enter()           __nothing
+#define kcov_silence_leave()           __nothing
 #define kcov_lwp_free(a) __nothing
 #endif
 #endif



Home | Main Index | Thread Index | Old Index