diff mbox series

[3/5] accel: Declare AccelClass::[un]realize_cpu() handlers

Message ID 20230915190009.68404-4-philmd@linaro.org (mailing list archive)
State New, archived
Headers show
Series accel: Restrict tcg_exec_[un]realizefn() to TCG | expand

Commit Message

Philippe Mathieu-Daudé Sept. 15, 2023, 7 p.m. UTC
Currently accel_cpu_realize() only performs target-specific
realization. Introduce the [un]realize_cpu fields in the
base AccelClass to be able to perform target-agnostic
[un]realization of vCPUs.

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

Comments

Claudio Fontana Oct. 3, 2023, 8:55 a.m. UTC | #1
On 9/15/23 21:00, Philippe Mathieu-Daudé wrote:
> Currently accel_cpu_realize() only performs target-specific
> realization. Introduce the [un]realize_cpu fields in the
> base AccelClass to be able to perform target-agnostic
> [un]realization of vCPUs.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Just thinking, for the benefit of the reader trying to understand the code later on,
maybe putting in a "target_" in there somewhere in the function name?
like "realize_cpu_target", vs "realize_cpu_generic" ?

Ciao,

C

> ---
>  include/qemu/accel.h |  2 ++
>  accel/accel-common.c | 21 +++++++++++++++++++--
>  2 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/include/qemu/accel.h b/include/qemu/accel.h
> index 23254c6c9c..7bd9907d2a 100644
> --- a/include/qemu/accel.h
> +++ b/include/qemu/accel.h
> @@ -43,6 +43,8 @@ typedef struct AccelClass {
>      bool (*has_memory)(MachineState *ms, AddressSpace *as,
>                         hwaddr start_addr, hwaddr size);
>  #endif
> +    bool (*realize_cpu)(CPUState *cpu, Error **errp);
> +    void (*unrealize_cpu)(CPUState *cpu);
>  
>      /* gdbstub related hooks */
>      int (*gdbstub_supported_sstep_flags)(void);
> diff --git a/accel/accel-common.c b/accel/accel-common.c
> index cc3a45e663..6d427f2b9d 100644
> --- a/accel/accel-common.c
> +++ b/accel/accel-common.c
> @@ -122,15 +122,32 @@ void accel_cpu_instance_init(CPUState *cpu)
>  bool accel_cpu_realize(CPUState *cpu, Error **errp)
>  {
>      CPUClass *cc = CPU_GET_CLASS(cpu);
> +    AccelState *accel = current_accel();
> +    AccelClass *acc = ACCEL_GET_CLASS(accel);
>  
> -    if (cc->accel_cpu && cc->accel_cpu->cpu_realizefn) {
> -        return cc->accel_cpu->cpu_realizefn(cpu, errp);
> +    /* target specific realization */
> +    if (cc->accel_cpu && cc->accel_cpu->cpu_realizefn
> +        && !cc->accel_cpu->cpu_realizefn(cpu, errp)) {
> +        return false;
>      }
> +
> +    /* generic realization */
> +    if (acc->realize_cpu && !acc->realize_cpu(cpu, errp)) {
> +        return false;
> +    }
> +
>      return true;
>  }
>  
>  void accel_cpu_unrealize(CPUState *cpu)
>  {
> +    AccelState *accel = current_accel();
> +    AccelClass *acc = ACCEL_GET_CLASS(accel);
> +
> +    /* generic unrealization */
> +    if (acc->unrealize_cpu) {
> +        acc->unrealize_cpu(cpu);
> +    }
>  }
>  
>  int accel_supported_gdbstub_sstep_flags(void)
Philippe Mathieu-Daudé Oct. 3, 2023, 9:44 a.m. UTC | #2
On 3/10/23 10:55, Claudio Fontana wrote:
> On 9/15/23 21:00, Philippe Mathieu-Daudé wrote:
>> Currently accel_cpu_realize() only performs target-specific
>> realization. Introduce the [un]realize_cpu fields in the
>> base AccelClass to be able to perform target-agnostic
>> [un]realization of vCPUs.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Just thinking, for the benefit of the reader trying to understand the code later on,
> maybe putting in a "target_" in there somewhere in the function name?
> like "realize_cpu_target", vs "realize_cpu_generic" ?

Good idea, I like it, thanks!
diff mbox series

Patch

diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index 23254c6c9c..7bd9907d2a 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -43,6 +43,8 @@  typedef struct AccelClass {
     bool (*has_memory)(MachineState *ms, AddressSpace *as,
                        hwaddr start_addr, hwaddr size);
 #endif
+    bool (*realize_cpu)(CPUState *cpu, Error **errp);
+    void (*unrealize_cpu)(CPUState *cpu);
 
     /* gdbstub related hooks */
     int (*gdbstub_supported_sstep_flags)(void);
diff --git a/accel/accel-common.c b/accel/accel-common.c
index cc3a45e663..6d427f2b9d 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -122,15 +122,32 @@  void accel_cpu_instance_init(CPUState *cpu)
 bool accel_cpu_realize(CPUState *cpu, Error **errp)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
 
-    if (cc->accel_cpu && cc->accel_cpu->cpu_realizefn) {
-        return cc->accel_cpu->cpu_realizefn(cpu, errp);
+    /* target specific realization */
+    if (cc->accel_cpu && cc->accel_cpu->cpu_realizefn
+        && !cc->accel_cpu->cpu_realizefn(cpu, errp)) {
+        return false;
     }
+
+    /* generic realization */
+    if (acc->realize_cpu && !acc->realize_cpu(cpu, errp)) {
+        return false;
+    }
+
     return true;
 }
 
 void accel_cpu_unrealize(CPUState *cpu)
 {
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    /* generic unrealization */
+    if (acc->unrealize_cpu) {
+        acc->unrealize_cpu(cpu);
+    }
 }
 
 int accel_supported_gdbstub_sstep_flags(void)