Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Dec 2018 11:09:01 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Hans Petter Selasky <hselasky@freebsd.org>
Cc:        "freebsd-mips@freebsd.org" <freebsd-mips@freebsd.org>
Subject:   Re: svn commit: r341787 - in head/sys: arm/include mips/include powerpc/include
Message-ID:  <CANCZdfqiFrH6WZ8zqfxg_Dmk_pUGbewTVNh%2Bs5rV9wP=80ZuVQ@mail.gmail.com>
In-Reply-To: <201812101338.wBADcE5A026483@repo.freebsd.org>
References:  <201812101338.wBADcE5A026483@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
[[ redirected to mips mailing list ]]

This doesn't quite do all platforms, see below, but 32-bit mips is omitted.

On Mon, Dec 10, 2018 at 6:38 AM Hans Petter Selasky <hselasky@freebsd.org>
wrote:

> Author: hselasky
> Date: Mon Dec 10 13:38:13 2018
> New Revision: 341787
> URL: https://svnweb.freebsd.org/changeset/base/341787
>
> Log:
>   Implement atomic_swap_xxx() for all platforms.
>
> +#if defined(__mips_n64) || defined(__mips_n32)
> +static __inline uint64_t
> +atomic_swap_64(volatile uint64_t *ptr, const uint64_t value)
>

32-bit MIPS still lacks this. It will need to be implemented in assembler.
Since we don't support SMP on mips-32 (or could easily move to not
supporting it if we have kernels that purport to support it), it would be
implemented as save status0; clear interrupts; do the swap; restore
status0. If we actually do have SMP 32-mips, then it's much harder.

Warner


> +{
> +       uint64_t retval;
> +
> +       retval = *ptr;
> +
> +       while (!atomic_fcmpset_64(ptr, &retval, value))
> +               ;
> +       return (retval);
> +}
> +#endif
> +
> +static __inline unsigned long
> +atomic_swap_long(volatile unsigned long *ptr, const unsigned long value)
> +{
> +       unsigned long retval;
> +
> +       retval = *ptr;
> +
> +       while (!atomic_fcmpset_32((volatile uint32_t *)ptr,
> +           (uint32_t *)&retval, value))
> +               ;
> +       return (retval);
> +}
> +
> +static __inline uintptr_t
> +atomic_swap_ptr(volatile uintptr_t *ptr, const uintptr_t value)
> +{
> +       uintptr_t retval;
> +
> +       retval = *ptr;
> +
> +       while (!atomic_fcmpset_32((volatile uint32_t *)ptr,
> +           (uint32_t *)&retval, value))
> +               ;
> +       return (retval);
> +}
> +
>  #endif /* ! _MACHINE_ATOMIC_H_ */
>
> Modified: head/sys/powerpc/include/atomic.h
>
> ==============================================================================
> --- head/sys/powerpc/include/atomic.h   Mon Dec 10 09:45:57 2018
> (r341786)
> +++ head/sys/powerpc/include/atomic.h   Mon Dec 10 13:38:13 2018
> (r341787)
> @@ -852,6 +852,9 @@ atomic_swap_64(volatile u_long *p, u_long v)
>  #define        atomic_fetchadd_64      atomic_fetchadd_long
>  #define        atomic_swap_long        atomic_swap_64
>  #define        atomic_swap_ptr         atomic_swap_64
> +#else
> +#define        atomic_swap_long(p,v)   atomic_swap_32((volatile u_int
> *)(p), v)
> +#define        atomic_swap_ptr(p,v)    atomic_swap_32((volatile u_int
> *)(p), v)
>  #endif
>
>  #undef __ATOMIC_REL
>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfqiFrH6WZ8zqfxg_Dmk_pUGbewTVNh%2Bs5rV9wP=80ZuVQ>