diff mbox

[v3,3/3] exec: call cpu_exec_exit() from a CPU unrealize common function

Message ID 1476485569-6744-4-git-send-email-lvivier@redhat.com
State New
Headers show

Commit Message

Laurent Vivier Oct. 14, 2016, 10:52 p.m. UTC
As cpu_exec_exit() mirrors the cpu_exec_realizefn(),
rename it as cpu_exec_unrealizefn().

Create and register a cpu_common_unrealizefn() function for
the CPU device class and call cpu_exec_unrealizefn() from
this function.

Remove cpu_exec_exit() from cpu_common_finalize()
(which mirrors init, not realize), and as x86_cpu_unrealizefn()
overwrites the device class unrealize function, add a call to
cpu_exec_unrealizefn() (as in ppc_cpu_unrealizefn()).

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 exec.c                      | 2 +-
 include/qom/cpu.h           | 2 +-
 qom/cpu.c                   | 8 +++++++-
 target-i386/cpu.c           | 2 ++
 target-ppc/translate_init.c | 2 +-
 5 files changed, 12 insertions(+), 4 deletions(-)

Comments

David Gibson Oct. 17, 2016, 3:43 a.m. UTC | #1
On Sat, Oct 15, 2016 at 12:52:49AM +0200, Laurent Vivier wrote:
> As cpu_exec_exit() mirrors the cpu_exec_realizefn(),
> rename it as cpu_exec_unrealizefn().
> 
> Create and register a cpu_common_unrealizefn() function for
> the CPU device class and call cpu_exec_unrealizefn() from
> this function.
> 
> Remove cpu_exec_exit() from cpu_common_finalize()
> (which mirrors init, not realize), and as x86_cpu_unrealizefn()
> overwrites the device class unrealize function, add a call to
> cpu_exec_unrealizefn() (as in ppc_cpu_unrealizefn()).
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  exec.c                      | 2 +-
>  include/qom/cpu.h           | 2 +-
>  qom/cpu.c                   | 8 +++++++-
>  target-i386/cpu.c           | 2 ++
>  target-ppc/translate_init.c | 2 +-
>  5 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 203eb52..3cd25db 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -596,7 +596,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
>  }
>  #endif
>  
> -void cpu_exec_exit(CPUState *cpu)
> +void cpu_exec_unrealizefn(CPUState *cpu)
>  {
>      CPUClass *cc = CPU_GET_CLASS(cpu);
>  
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 5520c6c..633c3fc 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -948,7 +948,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
>      GCC_FMT_ATTR(2, 3);
>  void cpu_exec_initfn(CPUState *cpu);
>  void cpu_exec_realizefn(CPUState *cpu, Error **errp);
> -void cpu_exec_exit(CPUState *cpu);
> +void cpu_exec_unrealizefn(CPUState *cpu);
>  
>  #ifdef CONFIG_SOFTMMU
>  extern const struct VMStateDescription vmstate_cpu_common;
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 85f1132..03d9190 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -345,6 +345,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
>      trace_init_vcpu(cpu);
>  }
>  
> +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
> +{
> +    CPUState *cpu = CPU(dev);
> +    cpu_exec_unrealizefn(cpu);
> +}
> +
>  static void cpu_common_initfn(Object *obj)
>  {
>      CPUState *cpu = CPU(obj);
> @@ -369,7 +375,6 @@ static void cpu_common_initfn(Object *obj)
>  static void cpu_common_finalize(Object *obj)
>  {
>      CPUState *cpu = CPU(obj);
> -    cpu_exec_exit(cpu);
>      g_free(cpu->trace_dstate);
>  }
>  
> @@ -403,6 +408,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
>      k->cpu_exec_exit = cpu_common_noop;
>      k->cpu_exec_interrupt = cpu_common_exec_interrupt;
>      dc->realize = cpu_common_realizefn;
> +    dc->unrealize = cpu_common_unrealizefn;
>      /*
>       * Reason: CPUs still need special care by board code: wiring up
>       * IRQs, adding reset handlers, halting non-first CPUs, ...
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3476d46..399a3e4 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -3253,6 +3253,8 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
>          object_unparent(OBJECT(cpu->apic_state));
>          cpu->apic_state = NULL;
>      }
> +
> +    cpu_exec_unrealizefn(CPU(dev));
>  }
>  
>  typedef struct BitProperty {
> diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
> index 40dae70..2de6a06 100644
> --- a/target-ppc/translate_init.c
> +++ b/target-ppc/translate_init.c
> @@ -9910,7 +9910,7 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
>      opc_handler_t **table, **table_2;
>      int i, j, k;
>  
> -    cpu_exec_exit(CPU(dev));
> +    cpu_exec_unrealizefn(CPU(dev));
>  
>      for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
>          if (env->opcodes[i] == &invalid_handler) {
Igor Mammedov Oct. 17, 2016, 11:30 a.m. UTC | #2
On Sat, 15 Oct 2016 00:52:49 +0200
Laurent Vivier <lvivier@redhat.com> wrote:

> As cpu_exec_exit() mirrors the cpu_exec_realizefn(),
> rename it as cpu_exec_unrealizefn().
> 
> Create and register a cpu_common_unrealizefn() function for
> the CPU device class and call cpu_exec_unrealizefn() from
> this function.
> 
> Remove cpu_exec_exit() from cpu_common_finalize()
> (which mirrors init, not realize), and as x86_cpu_unrealizefn()
> overwrites the device class unrealize function, add a call to
> cpu_exec_unrealizefn() (as in ppc_cpu_unrealizefn()).
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  exec.c                      | 2 +-
>  include/qom/cpu.h           | 2 +-
>  qom/cpu.c                   | 8 +++++++-
>  target-i386/cpu.c           | 2 ++
>  target-ppc/translate_init.c | 2 +-
>  5 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 203eb52..3cd25db 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -596,7 +596,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
>  }
>  #endif
>  
> -void cpu_exec_exit(CPUState *cpu)
> +void cpu_exec_unrealizefn(CPUState *cpu)
>  {
>      CPUClass *cc = CPU_GET_CLASS(cpu);
>  
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 5520c6c..633c3fc 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -948,7 +948,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
>      GCC_FMT_ATTR(2, 3);
>  void cpu_exec_initfn(CPUState *cpu);
>  void cpu_exec_realizefn(CPUState *cpu, Error **errp);
> -void cpu_exec_exit(CPUState *cpu);
> +void cpu_exec_unrealizefn(CPUState *cpu);
>  
>  #ifdef CONFIG_SOFTMMU
>  extern const struct VMStateDescription vmstate_cpu_common;
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 85f1132..03d9190 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -345,6 +345,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
>      trace_init_vcpu(cpu);
>  }
>  
> +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
> +{
> +    CPUState *cpu = CPU(dev);
> +    cpu_exec_unrealizefn(cpu);
> +}
> +
>  static void cpu_common_initfn(Object *obj)
>  {
>      CPUState *cpu = CPU(obj);
> @@ -369,7 +375,6 @@ static void cpu_common_initfn(Object *obj)
>  static void cpu_common_finalize(Object *obj)
>  {
>      CPUState *cpu = CPU(obj);
> -    cpu_exec_exit(cpu);
>      g_free(cpu->trace_dstate);
>  }
>  
> @@ -403,6 +408,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
>      k->cpu_exec_exit = cpu_common_noop;
>      k->cpu_exec_interrupt = cpu_common_exec_interrupt;
>      dc->realize = cpu_common_realizefn;
> +    dc->unrealize = cpu_common_unrealizefn;
>      /*
>       * Reason: CPUs still need special care by board code: wiring up
>       * IRQs, adding reset handlers, halting non-first CPUs, ...
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3476d46..399a3e4 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -3253,6 +3253,8 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
>          object_unparent(OBJECT(cpu->apic_state));
>          cpu->apic_state = NULL;
>      }
> +
> +    cpu_exec_unrealizefn(CPU(dev));
perhaps it should mirror the same pattern as realize override

i.e.
child class is it has it's own unrealize()
should have parent_unrealize field where it save original
unrealize pointer before override.

grep for parent_realize to see used pattern.

>  }
>  
>  typedef struct BitProperty {
> diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
> index 40dae70..2de6a06 100644
> --- a/target-ppc/translate_init.c
> +++ b/target-ppc/translate_init.c
> @@ -9910,7 +9910,7 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
>      opc_handler_t **table, **table_2;
>      int i, j, k;
>  
> -    cpu_exec_exit(CPU(dev));
> +    cpu_exec_unrealizefn(CPU(dev));
>  
>      for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
>          if (env->opcodes[i] == &invalid_handler) {
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 203eb52..3cd25db 100644
--- a/exec.c
+++ b/exec.c
@@ -596,7 +596,7 @@  AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 }
 #endif
 
-void cpu_exec_exit(CPUState *cpu)
+void cpu_exec_unrealizefn(CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
 
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 5520c6c..633c3fc 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -948,7 +948,7 @@  void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 void cpu_exec_initfn(CPUState *cpu);
 void cpu_exec_realizefn(CPUState *cpu, Error **errp);
-void cpu_exec_exit(CPUState *cpu);
+void cpu_exec_unrealizefn(CPUState *cpu);
 
 #ifdef CONFIG_SOFTMMU
 extern const struct VMStateDescription vmstate_cpu_common;
diff --git a/qom/cpu.c b/qom/cpu.c
index 85f1132..03d9190 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -345,6 +345,12 @@  static void cpu_common_realizefn(DeviceState *dev, Error **errp)
     trace_init_vcpu(cpu);
 }
 
+static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
+{
+    CPUState *cpu = CPU(dev);
+    cpu_exec_unrealizefn(cpu);
+}
+
 static void cpu_common_initfn(Object *obj)
 {
     CPUState *cpu = CPU(obj);
@@ -369,7 +375,6 @@  static void cpu_common_initfn(Object *obj)
 static void cpu_common_finalize(Object *obj)
 {
     CPUState *cpu = CPU(obj);
-    cpu_exec_exit(cpu);
     g_free(cpu->trace_dstate);
 }
 
@@ -403,6 +408,7 @@  static void cpu_class_init(ObjectClass *klass, void *data)
     k->cpu_exec_exit = cpu_common_noop;
     k->cpu_exec_interrupt = cpu_common_exec_interrupt;
     dc->realize = cpu_common_realizefn;
+    dc->unrealize = cpu_common_unrealizefn;
     /*
      * Reason: CPUs still need special care by board code: wiring up
      * IRQs, adding reset handlers, halting non-first CPUs, ...
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 3476d46..399a3e4 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3253,6 +3253,8 @@  static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
         object_unparent(OBJECT(cpu->apic_state));
         cpu->apic_state = NULL;
     }
+
+    cpu_exec_unrealizefn(CPU(dev));
 }
 
 typedef struct BitProperty {
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 40dae70..2de6a06 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -9910,7 +9910,7 @@  static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
     opc_handler_t **table, **table_2;
     int i, j, k;
 
-    cpu_exec_exit(CPU(dev));
+    cpu_exec_unrealizefn(CPU(dev));
 
     for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
         if (env->opcodes[i] == &invalid_handler) {