[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool
From: |
Richard Henderson |
Subject: |
Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool |
Date: |
Fri, 15 Apr 2016 09:22:49 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 |
On 04/15/2016 07:23 AM, Alex Bennée wrote:
> +#define atomic_bool_cmpxchg(ptr, old, new) \
> + ({ \
> + typeof(*ptr) _old = (old), _new = (new); \
> + bool r; \
> + r = __atomic_compare_exchange(ptr, &_old, &_new, false, \
> + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
> + r; \
> + })
How are you thinking this will be used? If a loop like
do {
old = atomic_read (ptr);
new = f(old);
} while (!atomic_bool_cmpxchg(ptr, old, new));
then it's usually helpful to use a weak compare_exchange (s/false/true/ above).
This will produce one loop for ll/sc architectures instead of two.
r~
- [Qemu-devel] [RFC v1 00/12] Enable MTTCG for 32 bit arm on x86, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 02/12] tcg/i386: Make direct jump patching thread-safe, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 01/12] include: move CPU-related definitions out of qemu-common.h, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 00/12] Enable MTTCG for 32 bit arm on x86, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 03/12] qemu-thread: add simple test-and-set spinlock, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 04/12] atomic: introduce atomic_dec_fetch., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool, Alex Bennée, 2016/04/15
- Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool,
Richard Henderson <=
- [Qemu-devel] [RFC v1 07/12] cpus: introduce async_safe_run_on_cpu., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 11/12] arm: atomically check the exclusive value in a STREX, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 10/12] arm: use tlb_flush_page_all for tlbimva[a], Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 06/12] cpus: pass CPUState to run_on_cpu helpers, Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 08/12] cputlb: introduce tlb_flush_* async work., Alex Bennée, 2016/04/15
- [Qemu-devel] [RFC v1 12/12] cpus: default MTTCG to on for 32 bit ARM on x86, Alex Bennée, 2016/04/15