From owner-svn-src-all@freebsd.org Wed Oct 2 17:07:59 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B4157134409; Wed, 2 Oct 2019 17:07:59 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46k2dW4LqFz3DXW; Wed, 2 Oct 2019 17:07:59 +0000 (UTC) (envelope-from kevans@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 7A00E2E9EB; Wed, 2 Oct 2019 17:07:59 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x92H7x72079752; Wed, 2 Oct 2019 17:07:59 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x92H7xsk079751; Wed, 2 Oct 2019 17:07:59 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201910021707.x92H7xsk079751@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 2 Oct 2019 17:07:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353016 - head/sys/mips/include X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/mips/include X-SVN-Commit-Revision: 353016 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Oct 2019 17:07:59 -0000 Author: kevans Date: Wed Oct 2 17:07:59 2019 New Revision: 353016 URL: https://svnweb.freebsd.org/changeset/base/353016 Log: mips: use generic sub-word atomic *cmpset Most of this diff is refactoring to reduce duplication between the different acq_ and rel_ variants. Differential Revision: https://reviews.freebsd.org/D21822 Modified: head/sys/mips/include/atomic.h Modified: head/sys/mips/include/atomic.h ============================================================================== --- head/sys/mips/include/atomic.h Wed Oct 2 17:06:28 2019 (r353015) +++ head/sys/mips/include/atomic.h Wed Oct 2 17:07:59 2019 (r353016) @@ -81,6 +81,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) { @@ -376,23 +381,6 @@ atomic_cmpset_32(__volatile uint32_t *p, uint32_t cmpv * 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) { int ret; @@ -422,24 +410,59 @@ atomic_fcmpset_32(__volatile uint32_t *p, uint32_t *cm 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. */ @@ -487,29 +510,7 @@ atomic_cmpset_64(__volatile uint64_t *p, uint64_t cmpv 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) { int ret; @@ -532,23 +533,14 @@ atomic_fcmpset_64(__volatile uint64_t *p, uint64_t *cm return ret; } -static __inline int -atomic_fcmpset_acq_64(__volatile uint64_t *p, uint64_t *cmpval, uint64_t newval) -{ - int retval; +/* + * 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); - 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 add the value of v to the integer pointed to by p and return * the previous value of *p. @@ -611,6 +603,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 @@ -625,6 +623,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 @@ -827,5 +831,7 @@ atomic_swap_long(volatile unsigned long *ptr, const un } #endif #define atomic_swap_ptr(ptr, value) atomic_swap_long((unsigned long *)(ptr), value) + +#include #endif /* ! _MACHINE_ATOMIC_H_ */