aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-01-03 18:29:20 +0000
committerKristof Provost <kp@FreeBSD.org>2021-10-06 18:29:33 +0000
commit7dbd5b49ca8261481968f6ea0ff84d9b1a58ca3d (patch)
tree6bc05b37dd0c0ff5409059552ab580c8010b7a57
parent92a6b17e8ba00d1d55936b53868f81c69d70f446 (diff)
downloadsrc-7dbd5b49ca8261481968f6ea0ff84d9b1a58ca3d.tar.gz
src-7dbd5b49ca8261481968f6ea0ff84d9b1a58ca3d.zip
emulated atomic64: disable interrupts as the lock mechanism on !SMP
Reviewed by: jhibbits, bdragon Differential Revision: https://reviews.freebsd.org/D23015 (cherry picked from commit 3a22f09cbff13aed11206af6c839c4e1a5a08bff)
-rw-r--r--sys/kern/subr_atomic64.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys/kern/subr_atomic64.c b/sys/kern/subr_atomic64.c
index 266b4ee20a10..5dffb161e8f2 100644
--- a/sys/kern/subr_atomic64.c
+++ b/sys/kern/subr_atomic64.c
@@ -55,9 +55,12 @@ enum {
};
#ifdef _KERNEL
+#ifdef SMP
+
#define A64_POOL_SIZE MAXCPU
/* Estimated size of a cacheline */
#define CACHE_ALIGN CACHE_LINE_SIZE
+static struct mtx a64_mtx_pool[A64_POOL_SIZE];
#define GET_MUTEX(p) \
(&a64_mtx_pool[(pmap_kextract((vm_offset_t)p) / CACHE_ALIGN) % (A64_POOL_SIZE)])
@@ -68,6 +71,13 @@ enum {
#define UNLOCK_A64() if (smp_started) mtx_unlock(_amtx)
+#else /* !SMP */
+
+#define LOCK_A64() { register_t s = intr_disable()
+#define UNLOCK_A64() intr_restore(s); }
+
+#endif /* SMP */
+
#define ATOMIC64_EMU_UN(op, rt, block, ret) \
rt \
atomic_##op##_64(volatile u_int64_t *p) { \
@@ -86,8 +96,6 @@ enum {
UNLOCK_A64(); \
ret; } struct hack
-static struct mtx a64_mtx_pool[A64_POOL_SIZE];
-
ATOMIC64_EMU_BIN(add, void, (*p = *p + v), return);
ATOMIC64_EMU_BIN(clear, void, *p &= ~v, return);
ATOMIC64_EMU_BIN(fetchadd, u_int64_t, (*p = *p + v, v = *p - v), return (v));
@@ -126,6 +134,7 @@ int atomic_fcmpset_64(volatile u_int64_t *p, u_int64_t *old, u_int64_t new)
return (tmp == tmp_old);
}
+#ifdef SMP
static void
atomic64_mtxinit(void *x __unused)
{
@@ -136,5 +145,6 @@ atomic64_mtxinit(void *x __unused)
}
SYSINIT(atomic64_mtxinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, atomic64_mtxinit, NULL);
+#endif /* SMP */
#endif /* _KERNEL */