[Qemu-devel] [PATCH v6 61/73] cpu: call .cpu_has_work with the CPU lock held

Emilio G. Cota posted 73 patches 6 years, 9 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v6 61/73] cpu: call .cpu_has_work with the CPU lock held
Posted by Emilio G. Cota 6 years, 9 months ago
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 include/qom/cpu.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 4a87c1fef7..96a5d0cb94 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -85,7 +85,8 @@ struct TranslationBlock;
  * @parse_features: Callback to parse command line arguments.
  * @reset: Callback to reset the #CPUState to its initial state.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @has_work: Callback for checking if there is work to do.
+ * @has_work: Callback for checking if there is work to do. Called with the
+ * CPU lock held.
  * @do_interrupt: Callback for interrupt handling.
  * @do_unassigned_access: Callback for unassigned access handling.
  * (this is deprecated: new targets should use do_transaction_failed instead)
@@ -795,9 +796,16 @@ const char *parse_cpu_model(const char *cpu_model);
 static inline bool cpu_has_work(CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
+    bool ret;
 
     g_assert(cc->has_work);
-    return cc->has_work(cpu);
+    if (cpu_mutex_locked(cpu)) {
+        return cc->has_work(cpu);
+    }
+    cpu_mutex_lock(cpu);
+    ret = cc->has_work(cpu);
+    cpu_mutex_unlock(cpu);
+    return ret;
 }
 
 /**
-- 
2.17.1


Re: [Qemu-devel] [PATCH v6 61/73] cpu: call .cpu_has_work with the CPU lock held
Posted by Alex Bennée 6 years, 9 months ago
Emilio G. Cota <cota@braap.org> writes:

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Emilio G. Cota <cota@braap.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  include/qom/cpu.h | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 4a87c1fef7..96a5d0cb94 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -85,7 +85,8 @@ struct TranslationBlock;
>   * @parse_features: Callback to parse command line arguments.
>   * @reset: Callback to reset the #CPUState to its initial state.
>   * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
> - * @has_work: Callback for checking if there is work to do.
> + * @has_work: Callback for checking if there is work to do. Called with the
> + * CPU lock held.
>   * @do_interrupt: Callback for interrupt handling.
>   * @do_unassigned_access: Callback for unassigned access handling.
>   * (this is deprecated: new targets should use do_transaction_failed instead)
> @@ -795,9 +796,16 @@ const char *parse_cpu_model(const char *cpu_model);
>  static inline bool cpu_has_work(CPUState *cpu)
>  {
>      CPUClass *cc = CPU_GET_CLASS(cpu);
> +    bool ret;
>
>      g_assert(cc->has_work);
> -    return cc->has_work(cpu);
> +    if (cpu_mutex_locked(cpu)) {
> +        return cc->has_work(cpu);
> +    }
> +    cpu_mutex_lock(cpu);
> +    ret = cc->has_work(cpu);
> +    cpu_mutex_unlock(cpu);
> +    return ret;
>  }
>
>  /**


--
Alex Bennée