svn commit: r356325 - head/sys/kern

Kyle Evans kevans at FreeBSD.org
Fri Jan 3 18:29:21 UTC 2020


Author: kevans
Date: Fri Jan  3 18:29:20 2020
New Revision: 356325
URL: https://svnweb.freebsd.org/changeset/base/356325

Log:
  emulated atomic64: disable interrupts as the lock mechanism on !SMP
  
  Reviewed by:	jhibbits, bdragon
  Differential Revision:	https://reviews.freebsd.org/D23015

Modified:
  head/sys/kern/subr_atomic64.c

Modified: head/sys/kern/subr_atomic64.c
==============================================================================
--- head/sys/kern/subr_atomic64.c	Fri Jan  3 18:21:00 2020	(r356324)
+++ head/sys/kern/subr_atomic64.c	Fri Jan  3 18:29:20 2020	(r356325)
@@ -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
 	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 */


More information about the svn-src-head mailing list