[PATCH for-8.0 2/7] hw/mips: Use QEMU_IOTHREAD_LOCK_GUARD in cpu_mips_irq_request

Richard Henderson posted 7 patches 3 years, 2 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, David Gibson <david@gibson.dropbear.id.au>, Greg Kurz <groug@kaod.org>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>
There is a newer version of this series
[PATCH for-8.0 2/7] hw/mips: Use QEMU_IOTHREAD_LOCK_GUARD in cpu_mips_irq_request
Posted by Richard Henderson 3 years, 2 months ago
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 hw/mips/mips_int.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/hw/mips/mips_int.c b/hw/mips/mips_int.c
index 2db5e10fe0..73437cd90f 100644
--- a/hw/mips/mips_int.c
+++ b/hw/mips/mips_int.c
@@ -32,17 +32,12 @@ static void cpu_mips_irq_request(void *opaque, int irq, int level)
     MIPSCPU *cpu = opaque;
     CPUMIPSState *env = &cpu->env;
     CPUState *cs = CPU(cpu);
-    bool locked = false;
 
     if (irq < 0 || irq > 7) {
         return;
     }
 
-    /* Make sure locking works even if BQL is already held by the caller */
-    if (!qemu_mutex_iothread_locked()) {
-        locked = true;
-        qemu_mutex_lock_iothread();
-    }
+    QEMU_IOTHREAD_LOCK_GUARD();
 
     if (level) {
         env->CP0_Cause |= 1 << (irq + CP0Ca_IP);
@@ -59,10 +54,6 @@ static void cpu_mips_irq_request(void *opaque, int irq, int level)
     } else {
         cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
     }
-
-    if (locked) {
-        qemu_mutex_unlock_iothread();
-    }
 }
 
 void cpu_mips_irq_init_cpu(MIPSCPU *cpu)
-- 
2.34.1


Re: [PATCH for-8.0 2/7] hw/mips: Use QEMU_IOTHREAD_LOCK_GUARD in cpu_mips_irq_request
Posted by Philippe Mathieu-Daudé 3 years, 2 months ago
On 18/11/22 10:18, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>   hw/mips/mips_int.c | 11 +----------
>   1 file changed, 1 insertion(+), 10 deletions(-)
> 
> diff --git a/hw/mips/mips_int.c b/hw/mips/mips_int.c
> index 2db5e10fe0..73437cd90f 100644
> --- a/hw/mips/mips_int.c
> +++ b/hw/mips/mips_int.c
> @@ -32,17 +32,12 @@ static void cpu_mips_irq_request(void *opaque, int irq, int level)
>       MIPSCPU *cpu = opaque;
>       CPUMIPSState *env = &cpu->env;
>       CPUState *cs = CPU(cpu);
> -    bool locked = false;
>   
>       if (irq < 0 || irq > 7) {
>           return;
>       }
>   
> -    /* Make sure locking works even if BQL is already held by the caller */
> -    if (!qemu_mutex_iothread_locked()) {
> -        locked = true;
> -        qemu_mutex_lock_iothread();
> -    }
> +    QEMU_IOTHREAD_LOCK_GUARD();
>   
>       if (level) {
>           env->CP0_Cause |= 1 << (irq + CP0Ca_IP);
> @@ -59,10 +54,6 @@ static void cpu_mips_irq_request(void *opaque, int irq, int level)
>       } else {
>           cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
>       }
> -
> -    if (locked) {
> -        qemu_mutex_unlock_iothread();
> -    }
>   }

I'd rather have a macro similar to WITH_RCU_READ_LOCK_GUARD()
so the locked context is obvious:

   WITH_QEMU_IOTHREAD_LOCK_GUARD() {
       ...
   }

Anyhow:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>