diff mbox

[05/12] target-i386: push hot-plugged VCPU state to KVM and unstop it

Message ID 1363876125-8264-6-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov March 21, 2013, 2:28 p.m. UTC
* synchronize CPU state to KVM
 * resume CPU, it makes CPU be able to handle interrupts in TCG mode
   and/or with user-space APIC.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 cpus.c                |   11 ++++++++---
 include/sysemu/cpus.h |    3 +++
 stubs/Makefile.objs   |    1 +
 stubs/resume_vcpu.c   |    6 ++++++
 target-i386/cpu.c     |    5 +++++
 5 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 stubs/resume_vcpu.c

Comments

Paolo Bonzini March 27, 2013, 11:01 a.m. UTC | #1
Il 21/03/2013 15:28, Igor Mammedov ha scritto:
>  * synchronize CPU state to KVM
>  * resume CPU, it makes CPU be able to handle interrupts in TCG mode
>    and/or with user-space APIC.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  cpus.c                |   11 ++++++++---
>  include/sysemu/cpus.h |    3 +++
>  stubs/Makefile.objs   |    1 +
>  stubs/resume_vcpu.c   |    6 ++++++
>  target-i386/cpu.c     |    5 +++++
>  5 files changed, 23 insertions(+), 3 deletions(-)
>  create mode 100644 stubs/resume_vcpu.c
> 
> diff --git a/cpus.c b/cpus.c
> index e919dd7..ae479bf 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -973,6 +973,13 @@ void pause_all_vcpus(void)
>      }
>  }
>  
> +void resume_vcpu(CPUState *cpu)
> +{
> +    cpu->stop = false;
> +    cpu->stopped = false;
> +    qemu_cpu_kick(cpu);
> +}
> +
>  void resume_all_vcpus(void)
>  {
>      CPUArchState *penv = first_cpu;
> @@ -980,9 +987,7 @@ void resume_all_vcpus(void)
>      qemu_clock_enable(vm_clock, true);
>      while (penv) {
>          CPUState *pcpu = ENV_GET_CPU(penv);
> -        pcpu->stop = false;
> -        pcpu->stopped = false;
> -        qemu_cpu_kick(pcpu);
> +        resume_vcpu(pcpu);
>          penv = penv->next_cpu;
>      }
>  }
> diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
> index 6502488..9437df5 100644
> --- a/include/sysemu/cpus.h
> +++ b/include/sysemu/cpus.h
> @@ -1,11 +1,14 @@
>  #ifndef QEMU_CPUS_H
>  #define QEMU_CPUS_H
>  
> +#include "qom/cpu.h"
> +
>  /* cpus.c */
>  void qemu_init_cpu_loop(void);
>  void resume_all_vcpus(void);
>  void pause_all_vcpus(void);
>  void cpu_stop_current(void);
> +void resume_vcpu(CPUState *cpu);
>  
>  void cpu_synchronize_all_states(void);
>  void cpu_synchronize_all_post_reset(void);
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 9c55b34..28fb4f8 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -23,3 +23,4 @@ stub-obj-y += sysbus.o
>  stub-obj-y += vm-stop.o
>  stub-obj-y += vmstate.o
>  stub-obj-$(CONFIG_WIN32) += fd-register.o
> +stub-obj-y += resume_vcpu.o
> diff --git a/stubs/resume_vcpu.c b/stubs/resume_vcpu.c
> new file mode 100644
> index 0000000..383b71a
> --- /dev/null
> +++ b/stubs/resume_vcpu.c
> @@ -0,0 +1,6 @@
> +#include "qemu-common.h"
> +#include "sysemu/cpus.h"
> +
> +void resume_vcpu(CPUState *cpu)
> +{
> +}
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index d03ff73..631bcd8 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2260,6 +2260,11 @@ out:
>          error_propagate(errp, local_err);
>          return;
>      }
> +
> +    if (dev->hotplugged) {
> +        cpu_synchronize_post_init(env);
> +        resume_vcpu(CPU(cpu));
> +    }

I think the resume_vcpu should not be here, but in the superclass.

Paolo

>  }
>  
>  /* Enables contiguous-apic-ID mode, for compatibility */
>
Igor Mammedov March 27, 2013, 12:12 p.m. UTC | #2
On Wed, 27 Mar 2013 12:01:20 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 21/03/2013 15:28, Igor Mammedov ha scritto:
> >  * synchronize CPU state to KVM
> >  * resume CPU, it makes CPU be able to handle interrupts in TCG mode
> >    and/or with user-space APIC.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  cpus.c                |   11 ++++++++---
> >  include/sysemu/cpus.h |    3 +++
> >  stubs/Makefile.objs   |    1 +
> >  stubs/resume_vcpu.c   |    6 ++++++
> >  target-i386/cpu.c     |    5 +++++
> >  5 files changed, 23 insertions(+), 3 deletions(-)
> >  create mode 100644 stubs/resume_vcpu.c
> > 
> > diff --git a/cpus.c b/cpus.c
> > index e919dd7..ae479bf 100644
> > --- a/cpus.c
> > +++ b/cpus.c
> > @@ -973,6 +973,13 @@ void pause_all_vcpus(void)
> >      }
> >  }
> >  
> > +void resume_vcpu(CPUState *cpu)
> > +{
> > +    cpu->stop = false;
> > +    cpu->stopped = false;
> > +    qemu_cpu_kick(cpu);
> > +}
> > +
> >  void resume_all_vcpus(void)
> >  {
> >      CPUArchState *penv = first_cpu;
> > @@ -980,9 +987,7 @@ void resume_all_vcpus(void)
> >      qemu_clock_enable(vm_clock, true);
> >      while (penv) {
> >          CPUState *pcpu = ENV_GET_CPU(penv);
> > -        pcpu->stop = false;
> > -        pcpu->stopped = false;
> > -        qemu_cpu_kick(pcpu);
> > +        resume_vcpu(pcpu);
> >          penv = penv->next_cpu;
> >      }
> >  }
> > diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
> > index 6502488..9437df5 100644
> > --- a/include/sysemu/cpus.h
> > +++ b/include/sysemu/cpus.h
> > @@ -1,11 +1,14 @@
> >  #ifndef QEMU_CPUS_H
> >  #define QEMU_CPUS_H
> >  
> > +#include "qom/cpu.h"
> > +
> >  /* cpus.c */
> >  void qemu_init_cpu_loop(void);
> >  void resume_all_vcpus(void);
> >  void pause_all_vcpus(void);
> >  void cpu_stop_current(void);
> > +void resume_vcpu(CPUState *cpu);
> >  
> >  void cpu_synchronize_all_states(void);
> >  void cpu_synchronize_all_post_reset(void);
> > diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> > index 9c55b34..28fb4f8 100644
> > --- a/stubs/Makefile.objs
> > +++ b/stubs/Makefile.objs
> > @@ -23,3 +23,4 @@ stub-obj-y += sysbus.o
> >  stub-obj-y += vm-stop.o
> >  stub-obj-y += vmstate.o
> >  stub-obj-$(CONFIG_WIN32) += fd-register.o
> > +stub-obj-y += resume_vcpu.o
> > diff --git a/stubs/resume_vcpu.c b/stubs/resume_vcpu.c
> > new file mode 100644
> > index 0000000..383b71a
> > --- /dev/null
> > +++ b/stubs/resume_vcpu.c
> > @@ -0,0 +1,6 @@
> > +#include "qemu-common.h"
> > +#include "sysemu/cpus.h"
> > +
> > +void resume_vcpu(CPUState *cpu)
> > +{
> > +}
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index d03ff73..631bcd8 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -2260,6 +2260,11 @@ out:
> >          error_propagate(errp, local_err);
> >          return;
> >      }
> > +
> > +    if (dev->hotplugged) {
> > +        cpu_synchronize_post_init(env);
> > +        resume_vcpu(CPU(cpu));
> > +    }
> 
> I think the resume_vcpu should not be here, but in the superclass.

Then I should move following parts to superclass:

    if (dev->hotplugged) {
        cpu_synchronize_post_init(env);
        resume_vcpu(CPU(cpu));
    }

because in case of KVM we should make sure that CPU in sane state before
allowing CPU to become run-able.

> Paolo
> 
> >  }
> >  
> >  /* Enables contiguous-apic-ID mode, for compatibility */
> > 
> 
>
Andreas Färber March 27, 2013, 12:17 p.m. UTC | #3
Am 27.03.2013 13:12, schrieb Igor Mammedov:
> On Wed, 27 Mar 2013 12:01:20 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> Il 21/03/2013 15:28, Igor Mammedov ha scritto:
>>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>>> index d03ff73..631bcd8 100644
>>> --- a/target-i386/cpu.c
>>> +++ b/target-i386/cpu.c
>>> @@ -2260,6 +2260,11 @@ out:
>>>          error_propagate(errp, local_err);
>>>          return;
>>>      }
>>> +
>>> +    if (dev->hotplugged) {
>>> +        cpu_synchronize_post_init(env);
>>> +        resume_vcpu(CPU(cpu));
>>> +    }
>>
>> I think the resume_vcpu should not be here, but in the superclass.
> 
> Then I should move following parts to superclass:
> 
>     if (dev->hotplugged) {
>         cpu_synchronize_post_init(env);
>         resume_vcpu(CPU(cpu));
>     }
> 
> because in case of KVM we should make sure that CPU in sane state before
> allowing CPU to become run-able.

That's not possible until we change cpu_synchronize_post_init() argument
to CPUState, which is somewhere down my TODO list. Currently I have
mostly flushed my refactorings out, so if you wanted to dive into that,
that would be appreciated. :)

Andreas
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index e919dd7..ae479bf 100644
--- a/cpus.c
+++ b/cpus.c
@@ -973,6 +973,13 @@  void pause_all_vcpus(void)
     }
 }
 
+void resume_vcpu(CPUState *cpu)
+{
+    cpu->stop = false;
+    cpu->stopped = false;
+    qemu_cpu_kick(cpu);
+}
+
 void resume_all_vcpus(void)
 {
     CPUArchState *penv = first_cpu;
@@ -980,9 +987,7 @@  void resume_all_vcpus(void)
     qemu_clock_enable(vm_clock, true);
     while (penv) {
         CPUState *pcpu = ENV_GET_CPU(penv);
-        pcpu->stop = false;
-        pcpu->stopped = false;
-        qemu_cpu_kick(pcpu);
+        resume_vcpu(pcpu);
         penv = penv->next_cpu;
     }
 }
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index 6502488..9437df5 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -1,11 +1,14 @@ 
 #ifndef QEMU_CPUS_H
 #define QEMU_CPUS_H
 
+#include "qom/cpu.h"
+
 /* cpus.c */
 void qemu_init_cpu_loop(void);
 void resume_all_vcpus(void);
 void pause_all_vcpus(void);
 void cpu_stop_current(void);
+void resume_vcpu(CPUState *cpu);
 
 void cpu_synchronize_all_states(void);
 void cpu_synchronize_all_post_reset(void);
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 9c55b34..28fb4f8 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -23,3 +23,4 @@  stub-obj-y += sysbus.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
+stub-obj-y += resume_vcpu.o
diff --git a/stubs/resume_vcpu.c b/stubs/resume_vcpu.c
new file mode 100644
index 0000000..383b71a
--- /dev/null
+++ b/stubs/resume_vcpu.c
@@ -0,0 +1,6 @@ 
+#include "qemu-common.h"
+#include "sysemu/cpus.h"
+
+void resume_vcpu(CPUState *cpu)
+{
+}
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d03ff73..631bcd8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2260,6 +2260,11 @@  out:
         error_propagate(errp, local_err);
         return;
     }
+
+    if (dev->hotplugged) {
+        cpu_synchronize_post_init(env);
+        resume_vcpu(CPU(cpu));
+    }
 }
 
 /* Enables contiguous-apic-ID mode, for compatibility */