[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 05/11] qemu-thread: add simple test-and-set s

From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH v3 05/11] qemu-thread: add simple test-and-set spinlock
Date: Wed, 20 Apr 2016 08:18:56 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1

On 04/19/2016 04:07 PM, Emilio G. Cota wrote:
From: Guillaume Delbergue <address@hidden>

Signed-off-by: Guillaume Delbergue <address@hidden>
[Rewritten. - Paolo]
Signed-off-by: Paolo Bonzini <address@hidden>
[Emilio's additions: call cpu_relax() while spinning; optimize for
  uncontended locks by acquiring the lock with xchg+test instead of
Signed-off-by: Emilio G. Cota <address@hidden>

It probably doesn't matter for any real hosts, but do note that there are compiler primitives for test-and-set that (can be) simpler for a cpu to implement than xchg. This likely affects only ancient hosts like sparcv7,
or tiny hosts like SH.

We don't have to change anything here, but it does seem more natural to use a test-and-set primitive.

+static inline int qemu_spin_trylock(QemuSpin *spin)
+    if (atomic_read(&spin->value) || atomic_xchg(&spin->value, true)) {
+        return -EBUSY;

I think there's no point in the extra read here.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]