diff mbox

[RFC,v0] spapr: Disable CPU unplug in TCG mode

Message ID 20160930032237.GA3812@in.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bharata B Rao Sept. 30, 2016, 3:22 a.m. UTC
On Wed, Sep 21, 2016 at 03:31:00PM +1000, David Gibson wrote:
> On Wed, Sep 21, 2016 at 10:18:00AM +0530, Bharata B Rao wrote:
> > CPU unplug doesn't work in TCG mode currently and causes frequent system
> > freeze. In addition to other potential problems, the main problem arises
> > of out the requirement to support synchronous removal of a CPU thread.
> > The CPU thread that performs the cleanup of the unplugged CPU, kicks and
> > waits for the unplugged CPU thread to finish. This wait never finishes in
> > TCG mode when the waiting thread and the unplugged CPU thread are one and
> > the same.
> > 
> > So wait till proper MTTCG support is available before enabling
> > CPU unplug in TCG mode.
> 
> MTTCG seems like a very big hammer to fix this with.  Surely we could
> come up with a simpler interlock that would work for TCG in the
> meantime.

The following hack fixes the issue mostly. I still see some occasional
hangs which points to other potential problems.


This is however on Alex's MTTCG tree, I need to figure out which are
the fixes that are relavent from Alex's tree to get CPU unplug working
in TCG mode.

Regards,
Bharata.
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index 8ad1eb4..7dc7d09 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1526,8 +1526,13 @@  void cpu_remove(CPUState *cpu)
 void cpu_remove_sync(CPUState *cpu)
 {
     cpu_remove(cpu);
-    while (cpu->created) {
-        qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
+    if (!kvm_enabled()) {
+        qemu_tcg_destroy_vcpu(cpu);
+        cpu->created = false;
+    } else {
+        while (cpu->created) {
+            qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
+        }
     }
 }
 
@@ -1573,6 +1578,9 @@  static void qemu_tcg_init_vcpu(CPUState *cpu)
         /* For non-MTTCG cases we share the thread */
         cpu->thread = single_tcg_cpu_thread;
         cpu->halt_cond = single_tcg_halt_cond;
+        cpu->thread_id = first_cpu->thread_id;
+        cpu->created = true;
+        cpu->can_do_io = 1;
     }
 }
 
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index dc058e5..9558fc9 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -244,6 +244,7 @@  static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,
     CPUPPCState *env = &cpu->env;
 
     cs->halted = 1;
+    cs->stop = true;
     qemu_cpu_kick(cs);
     /*
      * While stopping a CPU, the guest calls H_CPPR which