[RFC PATCH v3 05/12] C-SKY: Atomic and Locking Routines
Mao Han
han_mao@c-sky.com
Tue Jul 3 07:57:00 GMT 2018
On Fri, Jun 29, 2018 at 04:36:19PM +0000, Joseph Myers wrote:
> On Fri, 29 Jun 2018, Mao Han wrote:
>
> > +#define USE_ATOMIC_COMPILER_BUILTINS 0
>
> Does this mean the compiler expands the atomic built-in function calls to
> out-of-line calls to libgcc or libatomic, but you wish to use inline
> expansions in glibc? (That's the main case when
> USE_ATOMIC_COMPILER_BUILTINS 0 is appropriate. If there are suitable
> atomic instructions, typically the compiler would expand the calls inline
> and USE_ATOMIC_COMPILER_BUILTINS 1 is most appropriate rather than using
> inline asm for atomics.)
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
Thanks a lot for the feedfack.
The macro seems someting to reduce architecture-specific code
needed to support C11-like atomics? If compiler can expands the
atomic built-in to the correct call, either libgcc or libatomic(inline)
, it is suggested to define USE_ATOMIC_COMPILER_BUILTINS to 1?
I don't know what will the difference between out-of-line call and
inline call affect on the linux system. effciency?
I'm also not sure about the macro ATOMIC_EXCHANGE_USES_CAS.
We don't have any exchange instruction.
We've only got CAS loop implement with linux helper on ck807/ck810 in libgcc,
and one implement with load-store Exclusive on ck860.
According to comment in pthread_spin_trylock.c ATOMIC_EXCHANGE_USES_CAS
should define to 1 if exchange is not supported? I did not found any
difference while running testsuits.
Is it better to have the atomic-machine.h like this below?
#define __HAVE_64B_ATOMICS 0
#define USE_ATOMIC_COMPILER_BUILTINS 1
#define ATOMIC_EXCHANGE_USES_CAS 1
#define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
(abort (), 0)
#define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
(abort (), 0)
#define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
({ \
typeof (*mem) __oldval = (oldval); \
!__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
model, __ATOMIC_RELAXED); \
})
#define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
(abort (), 0)
#define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
(abort (), (__typeof (*mem)) 0)
#define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
(abort (), (__typeof (*mem)) 0)
#define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
({ \
typeof (*mem) __oldval = (oldval); \
__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
model, __ATOMIC_RELAXED); \
__oldval; \
})
#define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
(abort (), (__typeof (*mem)) 0)
#define atomic_compare_and_exchange_bool_acq(mem, new, old) \
__atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
mem, new, old, __ATOMIC_ACQUIRE)
#define atomic_compare_and_exchange_val_acq(mem, new, old) \
__atomic_val_bysize (__arch_compare_and_exchange_val, int, \
mem, new, old, __ATOMIC_ACQUIRE)
More information about the Libc-alpha
mailing list