Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Add a new sanity check to psref
details: https://anonhg.NetBSD.org/src/rev/8420101b73ab
branches: trunk
changeset: 348813:8420101b73ab
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Nov 09 09:00:46 2016 +0000
description:
Add a new sanity check to psref
It checks if a target being acquired is already acquired with
the same psref. It is usable but not lightweight, so enabled
only if DEBUG.
diffstat:
sys/kern/subr_psref.c | 31 +++++++++++++++++++++++++++++--
1 files changed, 29 insertions(+), 2 deletions(-)
diffs (59 lines):
diff -r 634b4c884480 -r 8420101b73ab sys/kern/subr_psref.c
--- a/sys/kern/subr_psref.c Wed Nov 09 08:18:56 2016 +0000
+++ b/sys/kern/subr_psref.c Wed Nov 09 09:00:46 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_psref.c,v 1.5 2016/10/28 07:27:52 ozaki-r Exp $ */
+/* $NetBSD: subr_psref.c,v 1.6 2016/11/09 09:00:46 ozaki-r Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.5 2016/10/28 07:27:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.6 2016/11/09 09:00:46 ozaki-r Exp $");
#include <sys/types.h>
#include <sys/condvar.h>
@@ -195,6 +195,28 @@
target->prt_draining = false;
}
+#ifdef DEBUG
+static void
+psref_check_duplication(struct psref_cpu *pcpu, struct psref *psref,
+ const struct psref_target *target)
+{
+ bool found = false;
+ struct psref *_psref;
+
+ LIST_FOREACH(_psref, &pcpu->pcpu_head, psref_entry) {
+ if (_psref == psref &&
+ _psref->psref_target == target) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ panic("trying to acquire a target twice with the same psref: "
+ "psref=%p target=%p", psref, target);
+ }
+}
+#endif /* DEBUG */
+
/*
* psref_acquire(psref, target, class)
*
@@ -231,6 +253,11 @@
s = splraiseipl(class->prc_iplcookie);
pcpu = percpu_getref(class->prc_percpu);
+#ifdef DEBUG
+ /* Sanity-check if the target is already acquired with the same psref. */
+ psref_check_duplication(pcpu, psref, target);
+#endif
+
/* Record our reference. */
LIST_INSERT_HEAD(&pcpu->pcpu_head, psref, psref_entry);
psref->psref_target = target;
Home |
Main Index |
Thread Index |
Old Index