Date: Mon, 7 Oct 2019 07:54:34 +0000 (UTC) From: Andriy Gapon <avg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353167 - in head/sys/cddl/compat/opensolaris: kern sys Message-ID: <201910070754.x977sYLd028098@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: avg Date: Mon Oct 7 07:54:34 2019 New Revision: 353167 URL: https://svnweb.freebsd.org/changeset/base/353167 Log: ZFS: add emulation of atomic_swap_64 and atomic_load_64 Some 32-bit platforms do not provide 64-bit atomic operations that ZFS requires, either in userland or at all. We emulate those operations for those platforms using a mutex. That is not entirely correct and it's very efficient. Besides, the loads are plain loads, so torn values are possible. Nevertheless, the emulation seems to work for some definition of work. This change adds atomic_swap_64, which is already used in ZFS code, and atomic_load_64 that can be used to prevent torn reads. MFC after: 1 week Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c head/sys/cddl/compat/opensolaris/sys/atomic.h Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c ============================================================================== --- head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Mon Oct 7 07:42:26 2019 (r353166) +++ head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Mon Oct 7 07:54:34 2019 (r353167) @@ -71,6 +71,29 @@ atomic_dec_64(volatile uint64_t *target) *target -= 1; mtx_unlock(&atomic_mtx); } + +uint64_t +atomic_swap_64(volatile uint64_t *a, uint64_t value) +{ + uint64_t ret; + + mtx_lock(&atomic_mtx); + ret = *a; + *a = value; + mtx_unlock(&atomic_mtx); + return (ret); +} + +uint64_t +atomic_load_64(volatile uint64_t *a) +{ + uint64_t ret; + + mtx_lock(&atomic_mtx); + ret = *a; + mtx_unlock(&atomic_mtx); + return (ret); +} #endif uint64_t Modified: head/sys/cddl/compat/opensolaris/sys/atomic.h ============================================================================== --- head/sys/cddl/compat/opensolaris/sys/atomic.h Mon Oct 7 07:42:26 2019 (r353166) +++ head/sys/cddl/compat/opensolaris/sys/atomic.h Mon Oct 7 07:54:34 2019 (r353167) @@ -44,6 +44,8 @@ !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) extern void atomic_add_64(volatile uint64_t *target, int64_t delta); extern void atomic_dec_64(volatile uint64_t *target); +extern uint64_t atomic_swap_64(volatile uint64_t *a, uint64_t value); +extern uint64_t atomic_load_64(volatile uint64_t *a); #endif #ifndef __sparc64__ extern uint32_t atomic_cas_32(volatile uint32_t *target, uint32_t cmp,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910070754.x977sYLd028098>