diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2019-05-14 03:27:44 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2019-05-14 03:27:44 +0000 |
commit | 2525608439527c7ae74b03c2cc4b9089cb9f2726 (patch) | |
tree | 1adffbf0e5ae0a4876b21e8adedff3df14672224 /sys | |
parent | 9a5a6297d05660d316866af15246f2366b96dbfe (diff) |
Add lock order checking for smr_barrier(9). This is similar to the
checking done in taskq_barrier(9) and timeout_barrier(9).
OK mpi@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_smr.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/kern/kern_smr.c b/sys/kern/kern_smr.c index 0913aee8683..eadf828cfd6 100644 --- a/sys/kern/kern_smr.c +++ b/sys/kern/kern_smr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_smr.c,v 1.1 2019/02/26 14:24:21 visa Exp $ */ +/* $OpenBSD: kern_smr.c,v 1.2 2019/05/14 03:27:43 visa Exp $ */ /* * Copyright (c) 2019 Visa Hankala @@ -25,6 +25,7 @@ #include <sys/proc.h> #include <sys/smr.h> #include <sys/time.h> +#include <sys/witness.h> #include <machine/cpu.h> @@ -45,6 +46,18 @@ struct timeout smr_wakeup_tmo; unsigned int smr_expedite; unsigned int smr_ndeferred; +#ifdef WITNESS +static const char smr_lock_name[] = "smr"; +struct lock_object smr_lock_obj = { + .lo_name = smr_lock_name, + .lo_flags = LO_WITNESS | LO_INITIALIZED | LO_SLEEPABLE | + (LO_CLASS_RWLOCK << LO_CLASSSHIFT) +}; +struct lock_type smr_lock_type = { + .lt_name = smr_lock_name +}; +#endif + static inline int smr_cpu_is_idle(struct cpu_info *ci) { @@ -55,6 +68,7 @@ void smr_startup(void) { SIMPLEQ_INIT(&smr_deferred); + WITNESS_INIT(&smr_lock_obj, &smr_lock_type); kthread_create_deferred(smr_create_thread, NULL); } @@ -102,11 +116,16 @@ smr_thread(void *arg) smr_grace_wait(); + WITNESS_CHECKORDER(&smr_lock_obj, LOP_NEWORDER, NULL); + WITNESS_LOCK(&smr_lock_obj, 0); + while ((smr = SIMPLEQ_FIRST(&deferred)) != NULL) { SIMPLEQ_REMOVE_HEAD(&deferred, smr_list); smr->smr_func(smr->smr_arg); } + WITNESS_UNLOCK(&smr_lock_obj, 0); + getmicrouptime(&end); timersub(&end, &start, &elapsed); if (elapsed.tv_sec >= 5 && @@ -289,6 +308,8 @@ smr_barrier_impl(int expedite) assertwaitok(); SMR_ASSERT_NONCRITICAL(); + WITNESS_CHECKORDER(&smr_lock_obj, LOP_NEWORDER, NULL); + smr_init(&smr); smr_call_impl(&smr, smr_barrier_func, &c, expedite); cond_wait(&c, "smrbar"); |