From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Emilio G. Cota" <cota@braap.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
MTTCG Devel <mttcg@listserver.greensocs.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Richard Henderson <rth@twiddle.net>,
Peter Maydell <peter.maydell@linaro.org>,
Sergey Fedorov <serge.fdrv@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2 06/13] qemu-thread: add simple test-and-set spinlock
Date: Fri, 08 Apr 2016 14:02:11 +0100 [thread overview]
Message-ID: <87bn5kb6ek.fsf@linaro.org> (raw)
In-Reply-To: <1460050358-25025-7-git-send-email-cota@braap.org>
Emilio G. Cota <cota@braap.org> writes:
> From: Guillaume Delbergue <guillaume.delbergue@greensocs.com>
>
> Signed-off-by: Guillaume Delbergue <guillaume.delbergue@greensocs.com>
> [Rewritten. - Paolo]
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/qemu/thread.h | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/include/qemu/thread.h b/include/qemu/thread.h
> index bdae6df..1aa843b 100644
> --- a/include/qemu/thread.h
> +++ b/include/qemu/thread.h
> @@ -1,6 +1,8 @@
> #ifndef __QEMU_THREAD_H
> #define __QEMU_THREAD_H 1
>
> +#include <errno.h>
> +#include "qemu/atomic.h"
>
> typedef struct QemuMutex QemuMutex;
> typedef struct QemuCond QemuCond;
> @@ -60,4 +62,33 @@ struct Notifier;
> void qemu_thread_atexit_add(struct Notifier *notifier);
> void qemu_thread_atexit_remove(struct Notifier *notifier);
>
> +typedef struct QemuSpin {
> + int value;
If we are throwing true and false around as the only two values can we
use bool here and be consistent when setting/clearing.
> +} QemuSpin;
> +
> +static inline void qemu_spin_init(QemuSpin *spin)
> +{
> + spin->value = 0;
> +}
> +
> +static inline void qemu_spin_lock(QemuSpin *spin)
> +{
> + do {
> + while (atomic_read(&spin->value));
> + } while (atomic_xchg(&spin->value, true));
> +}
> +
> +static inline int qemu_spin_trylock(QemuSpin *spin)
> +{
> + if (atomic_read(&spin->value) || atomic_xchg(&spin->value, true)) {
> + return -EBUSY;
> + }
> + return 0;
> +}
> +
> +static inline void qemu_spin_unlock(QemuSpin *spin)
> +{
> + atomic_mb_set(&spin->value, 0);
> +}
> +
> #endif
--
Alex Bennée
next prev parent reply other threads:[~2016-04-08 13:02 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 17:32 [Qemu-devel] [PATCH v2 00/10] tb hash improvements Emilio G. Cota
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 02/13] compiler.h: add QEMU_ALIGNED() to enforce struct alignment Emilio G. Cota
2016-04-08 18:26 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 03/13] seqlock: remove optional mutex Emilio G. Cota
2016-04-08 18:26 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 04/13] seqlock: rename write_lock/unlock to write_begin/end Emilio G. Cota
2016-04-08 18:27 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 05/13] include/processor.h: define cpu_relax() Emilio G. Cota
2016-04-08 18:33 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 06/13] qemu-thread: add simple test-and-set spinlock Emilio G. Cota
2016-04-08 13:02 ` Alex Bennée [this message]
2016-04-08 18:38 ` Richard Henderson
2016-04-08 21:24 ` Alex Bennée
2016-04-08 21:26 ` Paolo Bonzini
2016-04-08 21:31 ` Richard Henderson
2016-04-08 21:35 ` Sergey Fedorov
2016-04-08 18:35 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 07/13] qemu-thread: call cpu_relax() while spinning Emilio G. Cota
2016-04-08 18:39 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 08/13] qemu-thread: optimize spin_lock for uncontended locks Emilio G. Cota
2016-04-08 18:40 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 09/13] exec: add tb_hash_func5, derived from xxhash Emilio G. Cota
2016-04-08 18:45 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 10/13] tb hash: hash phys_pc, pc, and flags with xxhash Emilio G. Cota
2016-04-08 18:48 ` Richard Henderson
2016-04-07 17:32 ` [Qemu-devel] [PATCH v2 12/13] qht: add test program Emilio G. Cota
2016-04-08 12:41 ` [Qemu-devel] [PATCH v2 00/10] tb hash improvements Alex Bennée
[not found] ` <1460050358-25025-2-git-send-email-cota@braap.org>
2016-04-08 18:25 ` [Qemu-devel] [PATCH v2 01/13] translate-all: add missing fold of tb_ctx into tcg_ctx Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bn5kb6ek.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=cota@braap.org \
--cc=crosthwaite.peter@gmail.com \
--cc=mttcg@listserver.greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=serge.fdrv@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).