[PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro

Philippe Mathieu-Daudé posted 6 patches 10 months, 1 week ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Greg Kurz <groug@kaod.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Fam Zheng <fam@euphon.net>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>
[PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
Posted by Philippe Mathieu-Daudé 10 months, 1 week ago
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba
"docs/style: call out the use of GUARD macros").

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/cpu-exec.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 67eda9865e..6b3f66930e 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -1070,21 +1070,21 @@ int cpu_exec(CPUState *cpu)
         return EXCP_HALTED;
     }
 
-    rcu_read_lock();
-    cpu_exec_enter(cpu);
+    WITH_RCU_READ_LOCK_GUARD() {
+        cpu_exec_enter(cpu);
 
-    /*
-     * Calculate difference between guest clock and host clock.
-     * This delay includes the delay of the last cycle, so
-     * what we have to do is sleep until it is 0. As for the
-     * advance/delay we gain here, we try to fix it next time.
-     */
-    init_delay_params(&sc, cpu);
+        /*
+         * Calculate difference between guest clock and host clock.
+         * This delay includes the delay of the last cycle, so
+         * what we have to do is sleep until it is 0. As for the
+         * advance/delay we gain here, we try to fix it next time.
+         */
+        init_delay_params(&sc, cpu);
 
-    ret = cpu_exec_setjmp(cpu, &sc);
+        ret = cpu_exec_setjmp(cpu, &sc);
 
-    cpu_exec_exit(cpu);
-    rcu_read_unlock();
+        cpu_exec_exit(cpu);
+    };
 
     return ret;
 }
-- 
2.41.0


Re: [PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
Posted by Richard Henderson 10 months ago
On 1/24/24 17:41, Philippe Mathieu-Daudé wrote:
> Replace the manual rcu_read_(un)lock calls by the
> WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba
> "docs/style: call out the use of GUARD macros").
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   accel/tcg/cpu-exec.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 67eda9865e..6b3f66930e 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -1070,21 +1070,21 @@ int cpu_exec(CPUState *cpu)
>           return EXCP_HALTED;
>       }
>   
> -    rcu_read_lock();
> -    cpu_exec_enter(cpu);
> +    WITH_RCU_READ_LOCK_GUARD() {
> +        cpu_exec_enter(cpu);
>   
> -    /*
> -     * Calculate difference between guest clock and host clock.
> -     * This delay includes the delay of the last cycle, so
> -     * what we have to do is sleep until it is 0. As for the
> -     * advance/delay we gain here, we try to fix it next time.
> -     */
> -    init_delay_params(&sc, cpu);
> +        /*
> +         * Calculate difference between guest clock and host clock.
> +         * This delay includes the delay of the last cycle, so
> +         * what we have to do is sleep until it is 0. As for the
> +         * advance/delay we gain here, we try to fix it next time.
> +         */
> +        init_delay_params(&sc, cpu);
>   
> -    ret = cpu_exec_setjmp(cpu, &sc);
> +        ret = cpu_exec_setjmp(cpu, &sc);
>   
> -    cpu_exec_exit(cpu);
> -    rcu_read_unlock();
> +        cpu_exec_exit(cpu);
> +    };
>   
>       return ret;
>   }

I've tweaked this to use RCU_READ_LOCK_GUARD instead -- there's little point
in excluding the return from the block, and thus avoid the re-indent -- and queued this 
one patch to tcg-next.


r~


Re: [PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
Posted by Richard Henderson 10 months ago
On 1/24/24 17:41, Philippe Mathieu-Daudé wrote:
> Replace the manual rcu_read_(un)lock calls by the
> WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba
> "docs/style: call out the use of GUARD macros").
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   accel/tcg/cpu-exec.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

> +    };

Stray ;


r~