From owner-svn-src-stable@freebsd.org Thu Jun 7 07:42:49 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 50087FD3797; Thu, 7 Jun 2018 07:42:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 23CFB83011; Thu, 7 Jun 2018 07:42:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 04DF31D45E; Thu, 7 Jun 2018 07:42:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w577gm6t061782; Thu, 7 Jun 2018 07:42:48 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w577gmaD061779; Thu, 7 Jun 2018 07:42:48 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201806070742.w577gmaD061779@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 7 Jun 2018 07:42:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r334762 - in stable/11/sys: cddl/compat/opensolaris/kern cddl/compat/opensolaris/sys i386/include X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/11/sys: cddl/compat/opensolaris/kern cddl/compat/opensolaris/sys i386/include X-SVN-Commit-Revision: 334762 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2018 07:42:49 -0000 Author: hselasky Date: Thu Jun 7 07:42:48 2018 New Revision: 334762 URL: https://svnweb.freebsd.org/changeset/base/334762 Log: MFC r334320 and r334328: Implement atomic_add_64() and atomic_subtract_64() for the i386 target. While at it add missing _acq_ and _rel_ variants for 64-bit atomic operations under i386. Reviewed by: kib @ Sponsored by: Mellanox Technologies Modified: stable/11/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c stable/11/sys/cddl/compat/opensolaris/sys/atomic.h stable/11/sys/i386/include/atomic.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c ============================================================================== --- stable/11/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Thu Jun 7 07:38:37 2018 (r334761) +++ stable/11/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c Thu Jun 7 07:42:48 2018 (r334762) @@ -52,7 +52,8 @@ atomic_init(void) } #endif -#if !defined(__LP64__) && !defined(__mips_n32) && !defined(ARM_HAVE_ATOMIC64) +#if !defined(__LP64__) && !defined(__mips_n32) && \ + !defined(ARM_HAVE_ATOMIC64) && !defined(I386_HAVE_ATOMIC64) void atomic_add_64(volatile uint64_t *target, int64_t delta) { Modified: stable/11/sys/cddl/compat/opensolaris/sys/atomic.h ============================================================================== --- stable/11/sys/cddl/compat/opensolaris/sys/atomic.h Thu Jun 7 07:38:37 2018 (r334761) +++ stable/11/sys/cddl/compat/opensolaris/sys/atomic.h Thu Jun 7 07:42:48 2018 (r334762) @@ -36,7 +36,12 @@ atomic_cmpset_ptr((volatile uintptr_t *)(_a), (uintptr_t)(_b), (uintptr_t) (_c)) #define cas32 atomic_cmpset_32 -#if !defined(__LP64__) && !defined(__mips_n32) && !defined(ARM_HAVE_ATOMIC64) +#if defined(__i386__) && (defined(_KERNEL) || defined(KLD_MODULE)) +#define I386_HAVE_ATOMIC64 +#endif + +#if !defined(__LP64__) && !defined(__mips_n32) && \ + !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); #endif @@ -85,7 +90,8 @@ atomic_dec_32_nv(volatile uint32_t *target) return (atomic_fetchadd_32(target, -1) - 1); } -#if defined(__LP64__) || defined(__mips_n32) || defined(ARM_HAVE_ATOMIC64) +#if defined(__LP64__) || defined(__mips_n32) || \ + defined(ARM_HAVE_ATOMIC64) || defined(I386_HAVE_ATOMIC64) static __inline void atomic_dec_64(volatile uint64_t *target) { Modified: stable/11/sys/i386/include/atomic.h ============================================================================== --- stable/11/sys/i386/include/atomic.h Thu Jun 7 07:38:37 2018 (r334761) +++ stable/11/sys/i386/include/atomic.h Thu Jun 7 07:42:48 2018 (r334762) @@ -132,6 +132,8 @@ uint64_t atomic_load_acq_64(volatile uint64_t *); void atomic_store_rel_64(volatile uint64_t *, uint64_t); uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); uint64_t atomic_fetchadd_64(volatile uint64_t *, uint64_t); +void atomic_add_64(volatile uint64_t *, uint64_t); +void atomic_subtract_64(volatile uint64_t *, uint64_t); #else /* !KLD_MODULE && __GNUCLIKE_ASM */ @@ -579,6 +581,30 @@ atomic_fetchadd_64(volatile uint64_t *p, uint64_t v) } } +static __inline void +atomic_add_64(volatile uint64_t *p, uint64_t v) +{ + uint64_t t; + + for (;;) { + t = *p; + if (atomic_cmpset_64(p, t, t + v)) + break; + } +} + +static __inline void +atomic_subtract_64(volatile uint64_t *p, uint64_t v) +{ + uint64_t t; + + for (;;) { + t = *p; + if (atomic_cmpset_64(p, t, t - v)) + break; + } +} + #endif /* _KERNEL */ #endif /* KLD_MODULE || !__GNUCLIKE_ASM */ @@ -802,6 +828,16 @@ u_long atomic_swap_long(volatile u_long *p, u_long v); #define atomic_fetchadd_32 atomic_fetchadd_int #define atomic_testandset_32 atomic_testandset_int #define atomic_testandclear_32 atomic_testandclear_int + +/* Operations on 64-bit quad words. */ +#define atomic_cmpset_acq_64 atomic_cmpset_64 +#define atomic_cmpset_rel_64 atomic_cmpset_64 +#define atomic_fetchadd_acq_64 atomic_fetchadd_64 +#define atomic_fetchadd_rel_64 atomic_fetchadd_64 +#define atomic_add_acq_64 atomic_add_64 +#define atomic_add_rel_64 atomic_add_64 +#define atomic_subtract_acq_64 atomic_subtract_64 +#define atomic_subtract_rel_64 atomic_subtract_64 /* Operations on pointers. */ #define atomic_set_ptr(p, v) \