[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH] Use atomic cmpxchg to atomically check the
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [RFC PATCH] Use atomic cmpxchg to atomically check the exclusive value in a STREX |
Date: |
Tue, 09 Jun 2015 16:35:54 +0100 |
Mark Burton <address@hidden> writes:
>> On 9 Jun 2015, at 15:55, Alex Bennée <address@hidden> wrote:
>>
>>
>> Alex Bennée <address@hidden> writes:
>>
>>> address@hidden writes:
>>>
>>>> From: KONRAD Frederic <address@hidden>
>>>>
>>>> This mechanism replaces the existing load/store exclusive mechanism which
>>>> seems
>>>> to be broken for multithread.
>>>> It follows the intention of the existing mechanism and stores the target
>>>> address
>>>> and data values during a load operation and checks that they remain
>>>> unchanged
>>>> before a store.
>>>>
>>>> In common with the older approach, this provides weaker semantics than
>>>> required
>>>> in that it could be that a different processor writes the same value as a
>>>> non-exclusive write, however in practise this seems to be irrelevant.
>>>
>> <snip>
>>>>
>>>> +/* Protect cpu_exclusive_* variable .*/
>>>> +__thread bool cpu_have_exclusive_lock;
>>>> +QemuMutex cpu_exclusive_lock;
>>>> +
>>>> +inline void arm_exclusive_lock(void)
>>>> +{
>>>> + if (!cpu_have_exclusive_lock) {
>>>> + qemu_mutex_lock(&cpu_exclusive_lock);
>>>> + cpu_have_exclusive_lock = true;
>>>> + }
>>>> +}
>>>> +
>>>> +inline void arm_exclusive_unlock(void)
>>>> +{
>>>> + if (cpu_have_exclusive_lock) {
>>>> + cpu_have_exclusive_lock = false;
>>>> + qemu_mutex_unlock(&cpu_exclusive_lock);
>>>> + }
>>>> +}
>>>
>>> I don't quite follow. If these locks are mean to be protecting access to
>>> variables then how do they do that? The lock won't block if another
>>> thread is currently messing with the protected values.
>>
>> Having re-read after coffee I'm still wondering why we need the
>> per-thread bool? All the lock/unlock pairs are for critical sections so
>> don't we just want to serialise on the qemu_mutex_lock(), what do the
>> flags add apart from allowing you to next locks that shouldn't happen?
>>
>>
>
> you mean the “cpu_have_exclusive_lock” bools?
Yeah - surely just calling mutex_lock will serialise all the users
accessing the ldst variables?
>
> Cheers
> Mark.
>
>> --
>> Alex Bennée
>
>
> +44 (0)20 7100 3485 x 210
> +33 (0)5 33 52 01 77x 210
>
> +33 (0)603762104
> mark.burton
--
Alex Bennée
Re: [Qemu-devel] [RFC PATCH] Use atomic cmpxchg to atomically check the exclusive value in a STREX, Alex Bennée, 2015/06/09