[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 01/10] exec: Introduce tcg_exclusive_{lock, unlock
From: |
Pranith Kumar |
Subject: |
Re: [Qemu-devel] [RFC 01/10] exec: Introduce tcg_exclusive_{lock, unlock}() |
Date: |
Tue, 31 May 2016 11:03:20 -0400 |
Hi Alvise,
On Thu, May 26, 2016 at 12:35 PM, Alvise Rigo
<address@hidden> wrote:
> Add tcg_exclusive_{lock,unlock}() functions that will be used for making
> the emulation of LL and SC instructions thread safe.
>
> Signed-off-by: Alvise Rigo <address@hidden>
<snip>
> +__thread bool cpu_have_exclusive_lock;
> +QemuSpin cpu_exclusive_lock;
> +inline void tcg_exclusive_lock(void)
> +{
> + if (!cpu_have_exclusive_lock) {
> + qemu_spin_lock(&cpu_exclusive_lock);
> + cpu_have_exclusive_lock = true;
> + }
> +}
> +
> +inline void tcg_exclusive_unlock(void)
> +{
> + if (cpu_have_exclusive_lock) {
> + cpu_have_exclusive_lock = false;
> + qemu_spin_unlock(&cpu_exclusive_lock);
> + }
> +}
I think the unlock() here should have an assert if
cpu_have_exclusive_lock is false. From what I can see, a thread should
either take the exclusive lock or wait spinning for it in lock(). So
unlock() should always see cpu_have_exclusive_lock as true. It is a
good place to find locking bugs.
--
Pranith
- [Qemu-devel] [RFC 00/10] MTTCG: Slow-path for atomic insns, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 01/10] exec: Introduce tcg_exclusive_{lock, unlock}(), Alvise Rigo, 2016/05/26
- Re: [Qemu-devel] [RFC 01/10] exec: Introduce tcg_exclusive_{lock, unlock}(),
Pranith Kumar <=
- [Qemu-devel] [RFC 04/10] cputlb: Introduce tlb_flush_other(), Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 03/10] cpus: Introduce async_wait_run_on_cpu(), Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 02/10] softmmu_llsc_template.h: Move to multi-threading, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 05/10] target-arm: End TB after ldrex instruction, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 06/10] cputlb: Add tlb_tables_flush_bitmap(), Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 09/10] cputlb: Query tlb_flush_page_all, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 07/10] cputlb: Query tlb_flush_by_mmuidx, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 08/10] cputlb: Query tlb_flush_page_by_mmuidx, Alvise Rigo, 2016/05/26
- [Qemu-devel] [RFC 10/10] cpus: Do not sleep if some work item is pending, Alvise Rigo, 2016/05/26