Page MenuHomeFreeBSD

D1799.id3687.diff
No OneTemporary

D1799.id3687.diff

Index: share/man/man4/witness.4
===================================================================
--- share/man/man4/witness.4
+++ share/man/man4/witness.4
@@ -36,6 +36,7 @@
.Cd options WITNESS_KDB
.Cd options WITNESS_NO_VNODE
.Cd options WITNESS_SKIPSPIN
+.Cd options WITNESS_USE_SYSLOG
.Sh DESCRIPTION
The
.Nm
@@ -112,6 +113,23 @@
set via the read-only sysctl
.Va debug.witness.skipspin .
.Pp
+The
+.Dv WITNESS_USE_SYSLOG
+kernel option tells
+.Xr witness 4
+to use
+.Xr log 9
+instead of
+.Xr printf 9
+when printing out lock order reversals and lock order warnings.
+The
+.Xr log 9
+priority can be adjusted via
+.Va debug.witness.log_priority
+using either the sysctl or
+.Xr loader 8
+interface.
+.Pp
The sysctl
.Va debug.witness.watch
specifies the level of witness involvement in the system.
Index: sys/conf/options
===================================================================
--- sys/conf/options
+++ sys/conf/options
@@ -682,6 +682,7 @@
WITNESS_NO_VNODE opt_witness.h
WITNESS_SKIPSPIN opt_witness.h
WITNESS_COUNT opt_witness.h
+WITNESS_USE_SYSLOG opt_witness.h
OPENSOLARIS_WITNESS opt_global.h
# options for ACPI support
Index: sys/dev/cxgb/cxgb_osdep.h
===================================================================
--- sys/dev/cxgb/cxgb_osdep.h
+++ sys/dev/cxgb/cxgb_osdep.h
@@ -39,6 +39,8 @@
#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/kdb.h>
+
#include <dev/mii/mii.h>
#ifndef _CXGB_OSDEP_H_
@@ -128,10 +130,8 @@
#define smp_mb() mb()
#define L1_CACHE_BYTES 128
-extern void kdb_backtrace(void);
-
#define WARN_ON(condition) do { \
- if (__predict_false((condition)!=0)) { \
+ if (__predict_false((condition)!=0)) { \
log(LOG_WARNING, "BUG: warning at %s:%d/%s()\n", __FILE__, __LINE__, __FUNCTION__); \
kdb_backtrace(); \
} \
Index: sys/kern/subr_witness.c
===================================================================
--- sys/kern/subr_witness.c
+++ sys/kern/subr_witness.c
@@ -106,6 +106,9 @@
#include <sys/sched.h>
#include <sys/stack.h>
#include <sys/sysctl.h>
+#ifdef WITNESS_USE_SYSLOG
+#include <sys/syslog.h>
+#endif
#include <sys/systm.h>
#ifdef DDB
@@ -420,6 +423,38 @@
SYSCTL_INT(_debug_witness, OID_AUTO, witness_count, CTLFLAG_RDTUN,
&witness_count, 0, "");
+#ifdef WITNESS_USE_SYSLOG
+static int witness_log_priority_level = LOG_DEBUG;
+
+static int
+sysctl_debug_witness_log_priority(SYSCTL_HANDLER_ARGS)
+{
+ int error, value;
+
+ value = witness_log_priority_level;
+ error = sysctl_handle_int(oidp, &value, 0, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+ if (value < LOG_EMERG || value > LOG_DEBUG)
+ return (EINVAL);
+
+ witness_log_priority_level = value;
+
+ return (0);
+}
+
+SYSCTL_PROC(_debug_witness, OID_AUTO, log_priority,
+ CTLTYPE_INT | CTLFLAG_RWTUN,
+ NULL, 0, sysctl_debug_witness_log_priority, "I",
+ "log priority applied to witness messages");
+
+#define WITNESS_LOG(fmt, ...) \
+ log(witness_log_priority_level, fmt, ##__VA_ARGS__)
+#else
+#define WITNESS_LOG(fmt, ...) \
+ printf(fmt, ##__VA_ARGS__)
+#endif
+
/*
* Call this to print out the relations between locks.
*/
@@ -789,6 +824,12 @@
w = w1;
}
}
+
+#ifdef WITNESS_USE_SYSLOG
+ witness_log_priority_level =
+ max(LOG_EMERG, min(witness_log_priority_level, LOG_DEBUG));
+#endif
+
witness_spin_warn = 1;
/* Iterate through all locks and add them to witness. */
@@ -1110,19 +1151,19 @@
if (lock1 != NULL) {
if ((lock1->li_flags & LI_EXCLUSIVE) != 0 &&
(flags & LOP_EXCLUSIVE) == 0) {
- printf("shared lock of (%s) %s @ %s:%d\n",
+ WITNESS_LOG("shared lock of (%s) %s @ %s:%d\n",
class->lc_name, lock->lo_name,
fixup_filename(file), line);
- printf("while exclusively locked from %s:%d\n",
+ WITNESS_LOG("while exclusively locked from %s:%d\n",
fixup_filename(lock1->li_file), lock1->li_line);
kassert_panic("excl->share");
}
if ((lock1->li_flags & LI_EXCLUSIVE) == 0 &&
(flags & LOP_EXCLUSIVE) != 0) {
- printf("exclusive lock of (%s) %s @ %s:%d\n",
+ WITNESS_LOG("exclusive lock of (%s) %s @ %s:%d\n",
class->lc_name, lock->lo_name,
fixup_filename(file), line);
- printf("while share locked from %s:%d\n",
+ WITNESS_LOG("while share locked from %s:%d\n",
fixup_filename(lock1->li_file), lock1->li_line);
kassert_panic("share->excl");
}
@@ -1186,12 +1227,12 @@
w_rmatrix[i][i] |= WITNESS_REVERSAL;
w->w_reversed = 1;
mtx_unlock_spin(&w_mtx);
- printf(
+ WITNESS_LOG(
"acquiring duplicate lock of same type: \"%s\"\n",
w->w_name);
- printf(" 1st %s @ %s:%d\n", plock->li_lock->lo_name,
+ WITNESS_LOG(" 1st %s @ %s:%d\n", plock->li_lock->lo_name,
fixup_filename(plock->li_file), plock->li_line);
- printf(" 2nd %s @ %s:%d\n", lock->lo_name,
+ WITNESS_LOG(" 2nd %s @ %s:%d\n", lock->lo_name,
fixup_filename(file), line);
witness_debugger(1);
} else
@@ -1315,14 +1356,14 @@
*/
if (((lock->lo_flags & LO_SLEEPABLE) != 0 &&
(lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0))
- printf(
+ WITNESS_LOG(
"lock order reversal: (sleepable after non-sleepable)\n");
else if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0
&& lock == &Giant.lock_object)
- printf(
+ WITNESS_LOG(
"lock order reversal: (Giant after non-sleepable)\n");
else
- printf("lock order reversal:\n");
+ WITNESS_LOG("lock order reversal:\n");
/*
* Try to locate an earlier lock with
@@ -1341,24 +1382,24 @@
i--;
} while (i >= 0);
if (i < 0) {
- printf(" 1st %p %s (%s) @ %s:%d\n",
+ WITNESS_LOG(" 1st %p %s (%s) @ %s:%d\n",
lock1->li_lock, lock1->li_lock->lo_name,
w1->w_name, fixup_filename(lock1->li_file),
lock1->li_line);
- printf(" 2nd %p %s (%s) @ %s:%d\n", lock,
+ WITNESS_LOG(" 2nd %p %s (%s) @ %s:%d\n", lock,
lock->lo_name, w->w_name,
fixup_filename(file), line);
} else {
- printf(" 1st %p %s (%s) @ %s:%d\n",
+ WITNESS_LOG(" 1st %p %s (%s) @ %s:%d\n",
lock2->li_lock, lock2->li_lock->lo_name,
lock2->li_lock->lo_witness->w_name,
fixup_filename(lock2->li_file),
lock2->li_line);
- printf(" 2nd %p %s (%s) @ %s:%d\n",
+ WITNESS_LOG(" 2nd %p %s (%s) @ %s:%d\n",
lock1->li_lock, lock1->li_lock->lo_name,
w1->w_name, fixup_filename(lock1->li_file),
lock1->li_line);
- printf(" 3rd %p %s (%s) @ %s:%d\n", lock,
+ WITNESS_LOG(" 3rd %p %s (%s) @ %s:%d\n", lock,
lock->lo_name, w->w_name,
fixup_filename(file), line);
}
@@ -1580,17 +1621,17 @@
/* First, check for shared/exclusive mismatches. */
if ((instance->li_flags & LI_EXCLUSIVE) != 0 && witness_watch > 0 &&
(flags & LOP_EXCLUSIVE) == 0) {
- printf("shared unlock of (%s) %s @ %s:%d\n", class->lc_name,
+ WITNESS_LOG("shared unlock of (%s) %s @ %s:%d\n", class->lc_name,
lock->lo_name, fixup_filename(file), line);
- printf("while exclusively locked from %s:%d\n",
+ WITNESS_LOG("while exclusively locked from %s:%d\n",
fixup_filename(instance->li_file), instance->li_line);
kassert_panic("excl->ushare");
}
if ((instance->li_flags & LI_EXCLUSIVE) == 0 && witness_watch > 0 &&
(flags & LOP_EXCLUSIVE) != 0) {
- printf("exclusive unlock of (%s) %s @ %s:%d\n", class->lc_name,
+ WITNESS_LOG("exclusive unlock of (%s) %s @ %s:%d\n", class->lc_name,
lock->lo_name, fixup_filename(file), line);
- printf("while share locked from %s:%d\n",
+ WITNESS_LOG("while share locked from %s:%d\n",
fixup_filename(instance->li_file),
instance->li_line);
kassert_panic("share->uexcl");
@@ -1605,7 +1646,7 @@
}
/* The lock is now being dropped, check for NORELEASE flag */
if ((instance->li_flags & LI_NORELEASE) != 0 && witness_watch > 0) {
- printf("forbidden unlock of (%s) %s @ %s:%d\n", class->lc_name,
+ WITNESS_LOG("forbidden unlock of (%s) %s @ %s:%d\n", class->lc_name,
lock->lo_name, fixup_filename(file), line);
kassert_panic("lock marked norelease");
}
@@ -1656,7 +1697,7 @@
for (n = 0; lle != NULL; lle = lle->ll_next)
for (i = lle->ll_count - 1; i >= 0; i--) {
if (n == 0)
- printf("Thread %p exiting with the following locks held:\n",
+ WITNESS_LOG("Thread %p exiting with the following locks held:\n",
td);
n++;
witness_list_lock(&lle->ll_children[i], printf);

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 19, 2:18 PM (8 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31776269
Default Alt Text
D1799.id3687.diff (8 KB)

Event Timeline