aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/kpilite.h
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2018-07-03 01:55:09 +0000
committerMatt Macy <mmacy@FreeBSD.org>2018-07-03 01:55:09 +0000
commit6443773dab50613cf44754f6f0a5f587fa11b1d4 (patch)
tree8f51571b4f19809c6f6fe29121a3f8a409d425f3 /sys/sys/kpilite.h
parent28acc09dc08bd9b0da13089dd9abedd497f9732e (diff)
downloadsrc-6443773dab50613cf44754f6f0a5f587fa11b1d4.tar.gz
src-6443773dab50613cf44754f6f0a5f587fa11b1d4.zip
make critical_{enter, exit} inline
Avoid pulling in all of the <sys/proc.h> dependencies by automatically generating a stripped down thread_lite exporting only the fields of interest. The field declarations are type checked against the original and the offsets of the generated result is automatically checked. kib has expressed disagreement and would have preferred to simply use genassym style offsets (which loses type check enforcement). jhb has expressed dislike of it due to header pollution and a duplicate structure. He would have preferred to just have defined thread in _thread.h. Nonetheless, he admits that this is the only viable solution at the moment. The impetus for this came from mjg's D15331: "Inline critical_enter/exit for amd64" Reviewed by: jeff Differential Revision: https://reviews.freebsd.org/D16078
Notes
Notes: svn path=/head/; revision=335879
Diffstat (limited to 'sys/sys/kpilite.h')
-rw-r--r--sys/sys/kpilite.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/sys/kpilite.h b/sys/sys/kpilite.h
new file mode 100644
index 000000000000..53817550a8f2
--- /dev/null
+++ b/sys/sys/kpilite.h
@@ -0,0 +1,55 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018, Matthew Macy <mmacy@freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_KPILITE_H_
+#define _SYS_KPILITE_H_
+#if !defined(GENOFFSET) && !defined(KLD_MODULE) && defined(_KERNEL)
+#include "offset.inc"
+
+static __inline void
+sched_pin_lite(struct thread_lite *td)
+{
+
+ KASSERT((struct thread *)td == curthread, ("sched_pin called on non curthread"));
+ td->td_pinned++;
+ __compiler_membar();
+}
+
+static __inline void
+sched_unpin_lite(struct thread_lite *td)
+{
+
+ KASSERT((struct thread *)td == curthread, ("sched_unpin called on non curthread"));
+ KASSERT(td->td_pinned > 0, ("sched_unpin called on non pinned thread"));
+ __compiler_membar();
+ td->td_pinned--;
+ __compiler_membar();
+}
+#endif
+#endif