Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2018 15:10:34 +0200
From:      Hans Petter Selasky <hps@selasky.org>
To:        Cy Schubert <Cy.Schubert@cschubert.com>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r334320 - in head/sys: cddl/compat/opensolaris/kern cddl/compat/opensolaris/sys i386/include
Message-ID:  <168f4cd3-07d2-15cb-9cf4-a2d02f6dc260@selasky.org>
In-Reply-To: <201805291302.w4TD2bR5059884@slippy.cwsent.com>
References:  <201805291302.w4TD2bR5059884@slippy.cwsent.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 05/29/18 15:02, Cy Schubert wrote:
> In message <201805291159.w4TBx3e5085835@repo.freebsd.org>, Hans Petter
> Selasky
> writes:
>> Author: hselasky
>> Date: Tue May 29 11:59:02 2018
>> New Revision: 334320
>> URL: https://svnweb.freebsd.org/changeset/base/334320
>>
>> Log:
>>    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 @
>>    MFC after:	1 week
>>    Sponsored by:	Mellanox Technologies
>>
>> Modified:
>>    head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c
>>    head/sys/cddl/compat/opensolaris/sys/atomic.h
>>    head/sys/i386/include/atomic.h
>>
>> Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c
>> =============================================================================
>> =
>> --- head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c	Tue May
>>   29 10:29:43 2018	(r334319)
>> +++ head/sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c	Tue May
>>   29 11:59:02 2018	(r334320)
>> @@ -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__)
>>   void
>>   atomic_add_64(volatile uint64_t *target, int64_t delta)
>>   {
>>
>> Modified: head/sys/cddl/compat/opensolaris/sys/atomic.h
>> =============================================================================
>> =
>> --- head/sys/cddl/compat/opensolaris/sys/atomic.h	Tue May 29 10:29:43 201
>> 8	(r334319)
>> +++ head/sys/cddl/compat/opensolaris/sys/atomic.h	Tue May 29 11:59:02 201
>> 8	(r334320)
>> @@ -36,7 +36,8 @@
>>   	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(__LP64__) && !defined(__mips_n32) && \
>> +    !defined(ARM_HAVE_ATOMIC64) && !defined(__i386__)
>>   extern void atomic_add_64(volatile uint64_t *target, int64_t delta);
>>   extern void atomic_dec_64(volatile uint64_t *target);
>>   #endif
>> @@ -85,7 +86,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__)
>>   static __inline void
>>   atomic_dec_64(volatile uint64_t *target)
>>   {
>>
>> Modified: head/sys/i386/include/atomic.h
>> =============================================================================
>> =
>> --- head/sys/i386/include/atomic.h	Tue May 29 10:29:43 2018	(r33431
>> 9)
>> +++ head/sys/i386/include/atomic.h	Tue May 29 11:59:02 2018	(r33432
>> 0)
>> @@ -134,6 +134,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 */
>>   
>> @@ -581,6 +583,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 */
>> @@ -804,6 +830,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) \
>>
> 
> Hi Hans,
> 
> This broke in lib32 on an amd64 system.
> 
> --- cddl/lib/libnvpair__L ---
> In file included from /opt/src/svn-current/sys/cddl/contrib/opensolaris/
> common/nvpair/opensolaris_fnvpair.c:29:
> In file included from /opt/src/svn-current/cddl/contrib/opensolaris/lib/
> libzpool/common/sys/zfs_context.h:74:
> /opt/src/svn-current/sys/cddl/compat/opensolaris/sys/atomic.h:94:2:
> error: implicit declaration of function 'atomic_subtract_64' is invalid
> in C99 [-Werror,-Wimplicit-function-declaration]
>          atomic_subtract_64(target, 1);
>          ^

I only tested buildkernel i386 LINT + GENERIC with this change. I will 
have a look ASAP.

--HPS




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?168f4cd3-07d2-15cb-9cf4-a2d02f6dc260>