qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v8 22/35] RISC-V: Use atomic_cmpxchg to update P


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH v8 22/35] RISC-V: Use atomic_cmpxchg to update PLIC bitmaps
Date: Thu, 26 Apr 2018 14:14:37 -1000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 04/25/2018 01:45 PM, Michael Clark wrote:
> +    uint32_t old, new;
> +    do {
> +        old = atomic_read(&plic->pending[word]);
> +        new = (old & ~(1 << (irq & 31))) | (-!!pending & (1 << (irq & 31)));
> +    } while (atomic_cmpxchg(&plic->pending[word], old, new) != old);

I prefer

  uint32_t old, new, cmp = atomic_read(...);
  do {
    old = cmp;
    new = ...;
    cmp = atomic_cmpxchg(...);
  } while (old != cmp);

to avoid an extra load, should we loop.

That said, what you have is not wrong.  So,
Reviewed-by: Richard Henderson <address@hidden>


r~



reply via email to

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