From nobody Thu Oct 07 03:28:10 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 34EC112DDDC8; Thu, 7 Oct 2021 03:28:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPxbt6ZC5z4qhx; Thu, 7 Oct 2021 03:28:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 94DEE45AC; Thu, 7 Oct 2021 03:28:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1973SAB4060755; Thu, 7 Oct 2021 03:28:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1973SAc9060754; Thu, 7 Oct 2021 03:28:10 GMT (envelope-from git) Date: Thu, 7 Oct 2021 03:28:10 GMT Message-Id: <202110070328.1973SAc9060754@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: fb7485efe6e3 - stable/12 - mips: use generic sub-word atomic *cmpset List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: fb7485efe6e3bdd171861e4e51425ae46823840d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=fb7485efe6e3bdd171861e4e51425ae46823840d commit fb7485efe6e3bdd171861e4e51425ae46823840d Author: Kyle Evans AuthorDate: 2019-10-02 17:07:59 +0000 Commit: Kyle Evans CommitDate: 2021-10-07 03:27:26 +0000 mips: use generic sub-word atomic *cmpset Most of this diff is refactoring to reduce duplication between the different acq_ and rel_ variants. (cherry picked from commit 281ec62c977aba21b4aa60ed0f532d6a20b669e0) --- sys/mips/include/atomic.h | 142 ++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 68 deletions(-) diff --git a/sys/mips/include/atomic.h b/sys/mips/include/atomic.h index 506c686169e4..ad8abf3498f1 100644 --- a/sys/mips/include/atomic.h +++ b/sys/mips/include/atomic.h @@ -85,6 +85,11 @@ void atomic_clear_16(__volatile uint16_t *, uint16_t); void atomic_add_16(__volatile uint16_t *, uint16_t); void atomic_subtract_16(__volatile uint16_t *, uint16_t); +static __inline int atomic_cmpset_8(__volatile uint8_t *, uint8_t, uint8_t); +static __inline int atomic_fcmpset_8(__volatile uint8_t *, uint8_t *, uint8_t); +static __inline int atomic_cmpset_16(__volatile uint16_t *, uint16_t, uint16_t); +static __inline int atomic_fcmpset_16(__volatile uint16_t *, uint16_t *, uint16_t); + static __inline void atomic_set_32(__volatile uint32_t *p, uint32_t v) { @@ -389,23 +394,6 @@ atomic_cmpset_32(__volatile uint32_t *p, uint32_t cmpval, uint32_t newval) * two values are equal, update the value of *p with newval. Returns * zero if the compare failed, nonzero otherwise. */ -static __inline int -atomic_cmpset_acq_32(__volatile uint32_t *p, uint32_t cmpval, uint32_t newval) -{ - int retval; - - retval = atomic_cmpset_32(p, cmpval, newval); - mips_sync(); - return (retval); -} - -static __inline int -atomic_cmpset_rel_32(__volatile uint32_t *p, uint32_t cmpval, uint32_t newval) -{ - mips_sync(); - return (atomic_cmpset_32(p, cmpval, newval)); -} - static __inline int atomic_fcmpset_32(__volatile uint32_t *p, uint32_t *cmpval, uint32_t newval) { @@ -436,23 +424,58 @@ atomic_fcmpset_32(__volatile uint32_t *p, uint32_t *cmpval, uint32_t newval) return ret; } -static __inline int -atomic_fcmpset_acq_32(__volatile uint32_t *p, uint32_t *cmpval, uint32_t newval) -{ - int retval; - - retval = atomic_fcmpset_32(p, cmpval, newval); - mips_sync(); - return (retval); +#define ATOMIC_CMPSET_ACQ_REL(WIDTH) \ +static __inline int \ +atomic_cmpset_acq_##WIDTH(__volatile uint##WIDTH##_t *p, \ + uint##WIDTH##_t cmpval, uint##WIDTH##_t newval) \ +{ \ + int retval; \ + \ + retval = atomic_cmpset_##WIDTH(p, cmpval, newval); \ + mips_sync(); \ + return (retval); \ +} \ + \ +static __inline int \ +atomic_cmpset_rel_##WIDTH(__volatile uint##WIDTH##_t *p, \ + uint##WIDTH##_t cmpval, uint##WIDTH##_t newval) \ +{ \ + mips_sync(); \ + return (atomic_cmpset_##WIDTH(p, cmpval, newval)); \ } -static __inline int -atomic_fcmpset_rel_32(__volatile uint32_t *p, uint32_t *cmpval, uint32_t newval) -{ - mips_sync(); - return (atomic_fcmpset_32(p, cmpval, newval)); +#define ATOMIC_FCMPSET_ACQ_REL(WIDTH) \ +static __inline int \ +atomic_fcmpset_acq_##WIDTH(__volatile uint##WIDTH##_t *p, \ + uint##WIDTH##_t *cmpval, uint##WIDTH##_t newval) \ +{ \ + int retval; \ + \ + retval = atomic_fcmpset_##WIDTH(p, cmpval, newval); \ + mips_sync(); \ + return (retval); \ +} \ + \ +static __inline int \ +atomic_fcmpset_rel_##WIDTH(__volatile uint##WIDTH##_t *p, \ + uint##WIDTH##_t *cmpval, uint##WIDTH##_t newval) \ +{ \ + mips_sync(); \ + return (atomic_fcmpset_##WIDTH(p, cmpval, newval)); \ } +/* + * Atomically compare the value stored at *p with cmpval and if the + * two values are equal, update the value of *p with newval. Returns + * zero if the compare failed, nonzero otherwise. + */ +ATOMIC_CMPSET_ACQ_REL(8); +ATOMIC_CMPSET_ACQ_REL(16); +ATOMIC_CMPSET_ACQ_REL(32); +ATOMIC_FCMPSET_ACQ_REL(8); +ATOMIC_FCMPSET_ACQ_REL(16); +ATOMIC_FCMPSET_ACQ_REL(32); + /* * Atomically add the value of v to the integer pointed to by p and return * the previous value of *p. @@ -501,28 +524,6 @@ atomic_cmpset_64(__volatile uint64_t *p, uint64_t cmpval, uint64_t newval) return ret; } -/* - * Atomically compare the value stored at *p with cmpval and if the - * two values are equal, update the value of *p with newval. Returns - * zero if the compare failed, nonzero otherwise. - */ -static __inline int -atomic_cmpset_acq_64(__volatile uint64_t *p, uint64_t cmpval, uint64_t newval) -{ - int retval; - - retval = atomic_cmpset_64(p, cmpval, newval); - mips_sync(); - return (retval); -} - -static __inline int -atomic_cmpset_rel_64(__volatile uint64_t *p, uint64_t cmpval, uint64_t newval) -{ - mips_sync(); - return (atomic_cmpset_64(p, cmpval, newval)); -} - static __inline int atomic_fcmpset_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) { @@ -546,22 +547,13 @@ atomic_fcmpset_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) return ret; } -static __inline int -atomic_fcmpset_acq_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) -{ - int retval; - - retval = atomic_fcmpset_64(p, cmpval, newval); - mips_sync(); - return (retval); -} - -static __inline int -atomic_fcmpset_rel_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) -{ - mips_sync(); - return (atomic_fcmpset_64(p, cmpval, newval)); -} +/* + * Atomically compare the value stored at *p with cmpval and if the + * two values are equal, update the value of *p with newval. Returns + * zero if the compare failed, nonzero otherwise. + */ +ATOMIC_CMPSET_ACQ_REL(64); +ATOMIC_FCMPSET_ACQ_REL(64); /* * Atomically add the value of v to the integer pointed to by p and return @@ -625,6 +617,12 @@ atomic_thread_fence_seq_cst(void) #define atomic_subtract_char atomic_subtract_8 #define atomic_subtract_acq_char atomic_subtract_acq_8 #define atomic_subtract_rel_char atomic_subtract_rel_8 +#define atomic_cmpset_char atomic_cmpset_8 +#define atomic_cmpset_acq_char atomic_cmpset_acq_8 +#define atomic_cmpset_rel_char atomic_cmpset_rel_8 +#define atomic_fcmpset_char atomic_fcmpset_8 +#define atomic_fcmpset_acq_char atomic_fcmpset_acq_8 +#define atomic_fcmpset_rel_char atomic_fcmpset_rel_8 /* Operations on shorts. */ #define atomic_set_short atomic_set_16 @@ -639,6 +637,12 @@ atomic_thread_fence_seq_cst(void) #define atomic_subtract_short atomic_subtract_16 #define atomic_subtract_acq_short atomic_subtract_acq_16 #define atomic_subtract_rel_short atomic_subtract_rel_16 +#define atomic_cmpset_short atomic_cmpset_16 +#define atomic_cmpset_acq_short atomic_cmpset_acq_16 +#define atomic_cmpset_rel_short atomic_cmpset_rel_16 +#define atomic_fcmpset_short atomic_fcmpset_16 +#define atomic_fcmpset_acq_short atomic_fcmpset_acq_16 +#define atomic_fcmpset_rel_short atomic_fcmpset_rel_16 /* Operations on ints. */ #define atomic_set_int atomic_set_32 @@ -842,4 +846,6 @@ atomic_swap_long(volatile unsigned long *ptr, const unsigned long value) #endif #define atomic_swap_ptr(ptr, value) atomic_swap_long((unsigned long *)(ptr), value) +#include + #endif /* ! _MACHINE_ATOMIC_H_ */