Module Name: src Committed By: maxv Date: Fri May 15 13:09:02 UTC 2020
Modified Files: src/sys/kern: subr_kcov.c subr_lockdebug.c src/sys/sys: kcov.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_kcov.c cvs rdiff -u -r1.76 -r1.77 src/sys/kern/subr_lockdebug.c cvs rdiff -u -r1.8 -r1.9 src/sys/sys/kcov.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_kcov.c diff -u src/sys/kern/subr_kcov.c:1.13 src/sys/kern/subr_kcov.c:1.14 --- src/sys/kern/subr_kcov.c:1.13 Fri May 15 12:34:52 2020 +++ src/sys/kern/subr_kcov.c Fri May 15 13:09:02 2020 @@ -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 @@ typedef struct kcov_desc { /* 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 @@ kcov_disable(kcov_t *kd) /* -------------------------------------------------------------------------- */ +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 @@ __sanitizer_cov_trace_pc(void) return; } + if (__predict_false(kd->silenced)) { + /* Silenced. */ + return; + } + if (kd->mode != KCOV_MODE_TRACE_PC) { /* PC tracing mode not enabled */ return; Index: src/sys/kern/subr_lockdebug.c diff -u src/sys/kern/subr_lockdebug.c:1.76 src/sys/kern/subr_lockdebug.c:1.77 --- src/sys/kern/subr_lockdebug.c:1.76 Fri Apr 10 17:16:21 2020 +++ src/sys/kern/subr_lockdebug.c Fri May 15 13:09:02 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: subr_lockdeb #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_lookup(const char *func, size_ { 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 @@ lockdebug_mem_check(const char *func, si 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 @@ lockdebug_mem_check(const char *func, si __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 */ Index: src/sys/sys/kcov.h diff -u src/sys/sys/kcov.h:1.8 src/sys/sys/kcov.h:1.9 --- src/sys/sys/kcov.h:1.8 Fri May 15 12:34:52 2020 +++ src/sys/sys/kcov.h Fri May 15 13:09:02 2020 @@ -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 @@ typedef volatile uint64_t kcov_int_t; 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