git: 7dbd5b49ca82 - stable/12 - emulated atomic64: disable interrupts as the lock mechanism on !SMP
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 06 Oct 2021 18:53:18 UTC
The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7dbd5b49ca8261481968f6ea0ff84d9b1a58ca3d commit 7dbd5b49ca8261481968f6ea0ff84d9b1a58ca3d Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2020-01-03 18:29:20 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2021-10-06 18:29:33 +0000 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) --- sys/kern/subr_atomic64.c | 14 ++++++++++++-- 1 file 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 */