[RFC PATCH 03/19] accel: Keep reference to AccelOpsClass in AccelClass

Philippe Mathieu-Daudé posted 19 patches 5 months, 1 week ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Peter Maydell <peter.maydell@linaro.org>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>
There is a newer version of this series
[RFC PATCH 03/19] accel: Keep reference to AccelOpsClass in AccelClass
Posted by Philippe Mathieu-Daudé 5 months, 1 week ago
Allow dereferencing AccelOpsClass outside of accel/accel-system.c.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/accel.h       | 2 ++
 include/system/accel-ops.h | 3 ++-
 accel/accel-system.c       | 3 ++-
 accel/tcg/tcg-accel-ops.c  | 4 +++-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index fbd3d897fef..23c62cbeb07 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -37,6 +37,8 @@ typedef struct AccelClass {
     /*< public >*/
 
     const char *name;
+    AccelOpsClass *ops;
+
     int (*init_machine)(MachineState *ms);
     bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
     void (*cpu_common_unrealize)(CPUState *cpu);
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index 4c99d25aeff..44b37592d02 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -10,6 +10,7 @@
 #ifndef ACCEL_OPS_H
 #define ACCEL_OPS_H
 
+#include "qemu/accel.h"
 #include "exec/vaddr.h"
 #include "qom/object.h"
 
@@ -31,7 +32,7 @@ struct AccelOpsClass {
     /*< public >*/
 
     /* initialization function called when accel is chosen */
-    void (*ops_init)(AccelOpsClass *ops);
+    void (*ops_init)(AccelClass *ac);
 
     bool (*cpus_are_resettable)(void);
     void (*cpu_reset_hold)(CPUState *cpu);
diff --git a/accel/accel-system.c b/accel/accel-system.c
index a0f562ae9ff..64bc991b1ce 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -85,8 +85,9 @@ void accel_init_ops_interfaces(AccelClass *ac)
      * non-NULL create_vcpu_thread operation.
      */
     ops = ACCEL_OPS_CLASS(oc);
+    ac->ops = ops;
     if (ops->ops_init) {
-        ops->ops_init(ops);
+        ops->ops_init(ac);
     }
     cpus_register_accel(ops);
 }
diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
index b24d6a75625..da2e22a7dff 100644
--- a/accel/tcg/tcg-accel-ops.c
+++ b/accel/tcg/tcg-accel-ops.c
@@ -198,8 +198,10 @@ static inline void tcg_remove_all_breakpoints(CPUState *cpu)
     cpu_watchpoint_remove_all(cpu, BP_GDB);
 }
 
-static void tcg_accel_ops_init(AccelOpsClass *ops)
+static void tcg_accel_ops_init(AccelClass *ac)
 {
+    AccelOpsClass *ops = ac->ops;
+
     if (qemu_tcg_mttcg_enabled()) {
         ops->create_vcpu_thread = mttcg_start_vcpu_thread;
         ops->kick_vcpu_thread = mttcg_kick_vcpu_thread;
-- 
2.49.0


Re: [RFC PATCH 03/19] accel: Keep reference to AccelOpsClass in AccelClass
Posted by Alex Bennée 5 months, 1 week ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Allow dereferencing AccelOpsClass outside of accel/accel-system.c.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  include/qemu/accel.h       | 2 ++
>  include/system/accel-ops.h | 3 ++-
>  accel/accel-system.c       | 3 ++-
>  accel/tcg/tcg-accel-ops.c  | 4 +++-
>  4 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/include/qemu/accel.h b/include/qemu/accel.h
> index fbd3d897fef..23c62cbeb07 100644
> --- a/include/qemu/accel.h
> +++ b/include/qemu/accel.h
> @@ -37,6 +37,8 @@ typedef struct AccelClass {
>      /*< public >*/
>  
>      const char *name;

A comment wouldn't go a amiss here:

 "Cached by accel_init_ops_interfaces when created"?
 
> +    AccelOpsClass *ops;
> +
>      int (*init_machine)(MachineState *ms);
>      bool (*cpu_common_realize)(CPUState *cpu, Error **errp);
>      void (*cpu_common_unrealize)(CPUState *cpu);
> diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
> index 4c99d25aeff..44b37592d02 100644
> --- a/include/system/accel-ops.h
> +++ b/include/system/accel-ops.h
> @@ -10,6 +10,7 @@
>  #ifndef ACCEL_OPS_H
>  #define ACCEL_OPS_H
>  
> +#include "qemu/accel.h"
>  #include "exec/vaddr.h"
>  #include "qom/object.h"
>  
> @@ -31,7 +32,7 @@ struct AccelOpsClass {
>      /*< public >*/
>  
>      /* initialization function called when accel is chosen */
> -    void (*ops_init)(AccelOpsClass *ops);
> +    void (*ops_init)(AccelClass *ac);
>  
>      bool (*cpus_are_resettable)(void);
>      void (*cpu_reset_hold)(CPUState *cpu);
> diff --git a/accel/accel-system.c b/accel/accel-system.c
> index a0f562ae9ff..64bc991b1ce 100644
> --- a/accel/accel-system.c
> +++ b/accel/accel-system.c
> @@ -85,8 +85,9 @@ void accel_init_ops_interfaces(AccelClass *ac)
>       * non-NULL create_vcpu_thread operation.
>       */
>      ops = ACCEL_OPS_CLASS(oc);
> +    ac->ops = ops;
>      if (ops->ops_init) {
> -        ops->ops_init(ops);
> +        ops->ops_init(ac);
>      }
>      cpus_register_accel(ops);
>  }
> diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c
> index b24d6a75625..da2e22a7dff 100644
> --- a/accel/tcg/tcg-accel-ops.c
> +++ b/accel/tcg/tcg-accel-ops.c
> @@ -198,8 +198,10 @@ static inline void tcg_remove_all_breakpoints(CPUState *cpu)
>      cpu_watchpoint_remove_all(cpu, BP_GDB);
>  }
>  
> -static void tcg_accel_ops_init(AccelOpsClass *ops)
> +static void tcg_accel_ops_init(AccelClass *ac)
>  {
> +    AccelOpsClass *ops = ac->ops;
> +
>      if (qemu_tcg_mttcg_enabled()) {
>          ops->create_vcpu_thread = mttcg_start_vcpu_thread;
>          ops->kick_vcpu_thread = mttcg_kick_vcpu_thread;

otherwise:

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

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [RFC PATCH 03/19] accel: Keep reference to AccelOpsClass in AccelClass
Posted by Richard Henderson 5 months, 1 week ago
On 6/6/25 17:44, Philippe Mathieu-Daudé wrote:
> Allow dereferencing AccelOpsClass outside of accel/accel-system.c.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   include/qemu/accel.h       | 2 ++
>   include/system/accel-ops.h | 3 ++-
>   accel/accel-system.c       | 3 ++-
>   accel/tcg/tcg-accel-ops.c  | 4 +++-
>   4 files changed, 9 insertions(+), 3 deletions(-)

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

r~