svn commit: r357882 - in head/sys: kern sys

Jeff Roberson jeff at FreeBSD.org
Thu Feb 13 20:50:22 UTC 2020


Author: jeff
Date: Thu Feb 13 20:50:21 2020
New Revision: 357882
URL: https://svnweb.freebsd.org/changeset/base/357882

Log:
  Add more precise SMR entry asserts.

Modified:
  head/sys/kern/subr_smr.c
  head/sys/sys/smr.h

Modified: head/sys/kern/subr_smr.c
==============================================================================
--- head/sys/kern/subr_smr.c	Thu Feb 13 20:49:45 2020	(r357881)
+++ head/sys/kern/subr_smr.c	Thu Feb 13 20:50:21 2020	(r357882)
@@ -193,8 +193,7 @@ smr_advance(smr_t smr)
 	/*
 	 * It is illegal to enter while in an smr section.
 	 */
-	KASSERT(curthread->td_critnest == 0,
-	    ("smr_advance: Not allowed in a critical section."));
+	SMR_ASSERT_NOT_ENTERED(smr);
 
 	/*
 	 * Modifications not done in a smr section need to be visible
@@ -237,6 +236,8 @@ smr_advance_deferred(smr_t smr, int limit)
 	smr_seq_t goal;
 	smr_t csmr;
 
+	SMR_ASSERT_NOT_ENTERED(smr);
+
 	critical_enter();
 	csmr = zpcpu_get(smr);
 	if (++csmr->c_deferred >= limit) {
@@ -275,8 +276,8 @@ smr_poll(smr_t smr, smr_seq_t goal, bool wait)
 	/*
 	 * It is illegal to enter while in an smr section.
 	 */
-	KASSERT(!wait || curthread->td_critnest == 0,
-	    ("smr_poll: Blocking not allowed in a critical section."));
+	KASSERT(!wait || !SMR_ENTERED(smr),
+	    ("smr_poll: Blocking not allowed in a SMR section."));
 
 	/*
 	 * Use a critical section so that we can avoid ABA races

Modified: head/sys/sys/smr.h
==============================================================================
--- head/sys/sys/smr.h	Thu Feb 13 20:49:45 2020	(r357881)
+++ head/sys/sys/smr.h	Thu Feb 13 20:50:21 2020	(r357882)
@@ -68,6 +68,15 @@ struct smr {
 	int		c_deferred;	/* Deferred advance counter. */
 };
 
+#define	SMR_ENTERED(smr)						\
+    (curthread->td_critnest != 0 && zpcpu_get((smr))->c_seq != SMR_SEQ_INVALID)
+
+#define	SMR_ASSERT_ENTERED(smr)						\
+    KASSERT(SMR_ENTERED(smr), ("Not in smr section"))
+
+#define	SMR_ASSERT_NOT_ENTERED(smr)					\
+    KASSERT(!SMR_ENTERED(smr), ("In smr section."));
+
 /*
  * Return the current write sequence number.
  */


More information about the svn-src-head mailing list