summaryrefslogtreecommitdiffstats
path: root/sys/amd64
diff options
context:
space:
mode:
authoralc <alc@FreeBSD.org>1999-08-18 04:08:31 +0000
committeralc <alc@FreeBSD.org>1999-08-18 04:08:31 +0000
commit999b998faadf98cd252ae30361406a176da029bd (patch)
tree84d98ec8a5702a071d3e1d0cf2972575f512b794 /sys/amd64
parentc3587e5dcb4c284938b70a3896c2d0f07b9cd626 (diff)
downloadFreeBSD-src-999b998faadf98cd252ae30361406a176da029bd.zip
FreeBSD-src-999b998faadf98cd252ae30361406a176da029bd.tar.gz
Create callable (non-inline) versions of the atomic_OP_TYPE functions
that are linked into the kernel. The KLD compilation options are changed to call these functions, rather than in-lining the atomic operations. This approach makes atomic operations from KLDs significantly faster on UP systems (though somewhat slower on SMP systems). PR: i386/13111 Submitted by: peter.jeremy@alcatel.com.au
Diffstat (limited to 'sys/amd64')
-rw-r--r--sys/amd64/amd64/atomic.c47
-rw-r--r--sys/amd64/include/atomic.h17
2 files changed, 61 insertions, 3 deletions
diff --git a/sys/amd64/amd64/atomic.c b/sys/amd64/amd64/atomic.c
new file mode 100644
index 0000000..2c0443e
--- /dev/null
+++ b/sys/amd64/amd64/atomic.c
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 1999 Peter Jeremy
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * $Id $
+ */
+
+/* This file creates publically callable functions to perform various
+ * simple arithmetic on memory which is atomic in the presence of
+ * interrupts and multiple processors.
+ */
+#include <sys/types.h>
+
+/* Firstly make atomic.h generate prototypes as it will for kernel modules */
+#define KLD_MODULE
+#include <machine/atomic.h>
+#undef _MACHINE_ATOMIC_H_ /* forget we included it */
+#undef KLD_MODULE
+#undef ATOMIC_ASM
+
+/* Make atomic.h generate public functions */
+#define static
+#undef __inline
+#define __inline
+
+#include <machine/atomic.h>
diff --git a/sys/amd64/include/atomic.h b/sys/amd64/include/atomic.h
index d4e371b..e9f9403 100644
--- a/sys/amd64/include/atomic.h
+++ b/sys/amd64/include/atomic.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: atomic.h,v 1.3 1999/07/13 06:35:25 alc Exp $
+ * $Id: atomic.h,v 1.4 1999/07/23 23:45:19 alc Exp $
*/
#ifndef _MACHINE_ATOMIC_H_
#define _MACHINE_ATOMIC_H_
@@ -54,9 +54,19 @@
*/
/*
- * Make kernel modules portable between UP and SMP.
+ * The above functions are expanded inline in the statically-linked
+ * kernel. Lock prefixes are generated if an SMP kernel is being
+ * built.
+ *
+ * Kernel modules call real functions which are built into the kernel.
+ * This allows kernel modules to be portable between UP and SMP systems.
*/
-#if defined(SMP) || defined(KLD_MODULE)
+#if defined(KLD_MODULE)
+#define ATOMIC_ASM(NAME, TYPE, OP, V) \
+ extern void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v);
+
+#else /* !KLD_MODULE */
+#if defined(SMP)
#define MPLOCKED "lock ; "
#else
#define MPLOCKED
@@ -74,6 +84,7 @@ atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
: "=m" (*p) \
: "0" (*p), "ir" (V)); \
}
+#endif /* KLD_MODULE */
ATOMIC_ASM(set, char, "orb %2,%0", v)
ATOMIC_ASM(clear, char, "andb %2,%0", ~v)
OpenPOWER on IntegriCloud