Subject: Re: splassert
To: Frank van der Linden <fvdl@wasabisystems.com>
From: None <itojun@iijlab.net>
List: tech-kern
Date: 06/20/2002 22:15:58
>Yes, it assumes ordering. And so does the diff you posted, it compares
>wantedipl to cpl. Which is ok on OpenBSD, since they compare the
>level. However, we compare masks, and the masks are in reverse IPL
>order. So this code won't work correctly.

	yes.  i was wrong (noticed after writing the previous email).  
	the following should be correct.

>Please don't commit this, we can revisit this shortly, I am redoing
>some of the i386 interrupt code for the i386mp merge.

	i see.

itojun


Index: i386/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.472
diff -u -r1.472 machdep.c
--- i386/machdep.c	2002/05/31 17:46:51	1.472
+++ i386/machdep.c	2002/06/20 13:14:38
@@ -3310,3 +3310,14 @@
 
 	for (;;);
 }
+
+#ifdef DIAGNOSTIC
+void
+splassert_check(wantipl, func)
+	int wantipl;
+	const char *func;
+{
+	if (cpl & ~imask[wantipl])
+		splassert_fail(wantipl, cpl, func);
+}
+#endif
Index: include/intr.h
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/include/intr.h,v
retrieving revision 1.25
diff -u -r1.25 intr.h
--- include/intr.h	2002/05/12 23:16:52	1.25
+++ include/intr.h	2002/06/20 13:14:40
@@ -79,6 +79,24 @@
 static __inline void spllower __P((int));
 static __inline void softintr __P((int));
 
+/* SPL asserts */
+#ifdef DIAGNOSTIC
+/*
+ * Although this function is implemented in MI code, it must be in this MD
+ * header because we don't want this header to include MI includes.
+ */
+void splassert_fail(int, int, const char *);
+extern int splassert_ctl;
+void splassert_check(int, const char *);
+#define splassert(__wantipl) do {			\
+	if (__predict_false(splassert_ctl > 0)) {	\
+		splassert_check(__wantipl, __func__);	\
+	}						\
+} while (0)
+#else
+#define splassert(wantipl) do { /* nada */ } while (0)
+#endif
+
 /*
  * compiler barrier: prevent reordering of instructions.
  * XXX something similar will move to <sys/cdefs.h>