diff mbox series

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

Message ID 20240124074201.8239-2-philmd@linaro.org
State New
Headers show
Series hw/accel: Use RCU_READ macros | expand

Commit Message

Philippe Mathieu-Daudé Jan. 24, 2024, 7:41 a.m. UTC
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(-)

Comments

Manos Pitsidianakis Jan. 24, 2024, 9:34 a.m. UTC | #1
On Wed, 24 Jan 2024 09:41, Philippe Mathieu-Daudé <philmd@linaro.org> 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;
> }
>-- 
>2.41.0
>

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Richard Henderson Jan. 24, 2024, 9:14 p.m. UTC | #2
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~
Richard Henderson Jan. 28, 2024, 1:07 a.m. UTC | #3
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~
diff mbox series

Patch

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;
 }