Skip to contentSkip to conversation

spapr: add "stop-self" RTAS call required to support hot CPU unplug

PATCH Superseded Alexey Kardashevskiy 3 participants 4 messages Aug 28, 2013 – Aug 29, 2013

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spapr: add "stop-self" RTAS call required to support hot CPU unplug

PAPR+ requires two RTAS calls to be supported by the hypervisor in order to allow hotplugging VCPUs from the guest. The "start-cpu" RTAS call was already there but "stop-self" was not.

This adds the "stop-self" RTAS call.

---
Changes:
v2:
* exit_request flag change replaced with more correct cpu_exit() call
* fixed commit message, "spapr: support CPU hotplug"

---
 hw/ppc/spapr_rtas.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_rtas.c +12 -0
index 394ce05..b906294 100644
@@ -202,6 +202,17 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
     rtas_st(rets, 0, -3);
 }
 
+static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+                           uint32_t token, uint32_t nargs,
+                           target_ulong args,
+                           uint32_t nret, target_ulong rets)
+{
+    CPUState *cs = CPU(cpu);
+
+    cs->halted = 1;
+    cpu_exit(cs);
+}
+
 static struct rtas_call {
     const char *name;
     spapr_rtas_fn fn;
@@ -322,6 +333,7 @@ static void core_rtas_register_types(void)
     spapr_rtas_register("query-cpu-stopped-state",
                         rtas_query_cpu_stopped_state);
     spapr_rtas_register("start-cpu", rtas_start_cpu);
+    spapr_rtas_register("stop-self", rtas_stop_self);
 }
 
 type_init(core_rtas_register_types)
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 22 lines · Alexey Kardashevskiy

PAPR+ requires two RTAS calls to be supported by the hypervisor in order to allow hotplugging VCPUs from the guest. The "start-cpu" RTAS call was already there but "stop-self" was not.

This adds the "stop-self" RTAS call.

---
Changes:
v2:
* exit_request flag change replaced with more correct cpu_exit() call
* fixed commit message, "spapr: support CPU hotplug"

---
 hw/ppc/spapr_rtas.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_rtas.c +0 -0
index 394ce05..b906294 100644
@@ -202,6 +202,17 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
     rtas_st(rets, 0, -3);

hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, · line 212

Quoted 10 lines
hw/ppc/spapr_rtas.c +8 -0
 }
 
+static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+                           uint32_t token, uint32_t nargs,
+                           target_ulong args,
+                           uint32_t nret, target_ulong rets)
+{
+    CPUState *cs = CPU(cpu);
+
+    cs->halted = 1;

Uh.. I think you still need the msr = 0, or an interrupt could wake the cpu up again.

Quoted 14 lines
hw/ppc/spapr_rtas.c +4 -0
+    cpu_exit(cs);
+}
+
 static struct rtas_call {
     const char *name;
     spapr_rtas_fn fn;
@@ -322,6 +333,7 @@ static void core_rtas_register_types(void)
     spapr_rtas_register("query-cpu-stopped-state",
                         rtas_query_cpu_stopped_state);
     spapr_rtas_register("start-cpu", rtas_start_cpu);
+    spapr_rtas_register("stop-self", rtas_stop_self);
 }
 
 type_init(core_rtas_register_types)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 25 lines · David Gibson
Quoted 24 lines · Alexey Kardashevskiy

PAPR+ requires two RTAS calls to be supported by the hypervisor in order to allow hotplugging VCPUs from the guest. The "start-cpu" RTAS call was already there but "stop-self" was not.

This adds the "stop-self" RTAS call.

---
Changes:
v2:
* exit_request flag change replaced with more correct cpu_exit() call
* fixed commit message, "spapr: support CPU hotplug"

---
 hw/ppc/spapr_rtas.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_rtas.c +0 -0
index 394ce05..b906294 100644
@@ -202,6 +202,17 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
     rtas_st(rets, 0, -3);
 }
 
Quoted 11 lines

hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, · line 212

Quoted 8 lines
hw/ppc/spapr_rtas.c +8 -0
+static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+                           uint32_t token, uint32_t nargs,
+                           target_ulong args,
+                           uint32_t nret, target_ulong rets)
+{
+    CPUState *cs = CPU(cpu);
+
+    cs->halted = 1;

Uh.. I think you still need the msr = 0, or an interrupt could wake the cpu up again.

Tried with KVM and TCG - nothing wakes up the stopped CPU :-/ After a CPU stopped, the guest calls H_CPPR and disables interrupts on the specific CPU (or "server") on the XICS level. And decrementer interrupt does not wake up the CPU.

What is strange is that with TCG (but not with KVM) I see a warning from the guest at WARN_ON(get_preferred_offline_state(cpu) != CPU_STATE_OFFLINE); (pseries_mach_cpu_die() function) but only when I stop a CPU (any!) first time in the guest.

Specifically, I can do "echo 0 > ...cpuX/online" and "echo 1 > ...cpuX/online" many times during the same boot but only the first stop at all generates a warning (the state is 2 which is CPU_STATE_ONLINE).

Quoted 15 lines
Quoted 14 lines
hw/ppc/spapr_rtas.c +4 -0
+    cpu_exit(cs);
+}
+
 static struct rtas_call {
     const char *name;
     spapr_rtas_fn fn;
@@ -322,6 +333,7 @@ static void core_rtas_register_types(void)
     spapr_rtas_register("query-cpu-stopped-state",
                         rtas_query_cpu_stopped_state);
     spapr_rtas_register("start-cpu", rtas_start_cpu);
+    spapr_rtas_register("stop-self", rtas_stop_self);
 }
 
 type_init(core_rtas_register_types)
Signature · 1 line
Alexey
#3 lore raw
Quoted 39 lines · Alexey Kardashevskiy
Quoted 25 lines · David Gibson
Quoted 24 lines · Alexey Kardashevskiy

PAPR+ requires two RTAS calls to be supported by the hypervisor in order to allow hotplugging VCPUs from the guest. The "start-cpu" RTAS call was already there but "stop-self" was not.

This adds the "stop-self" RTAS call.

---
Changes:
v2:
* exit_request flag change replaced with more correct cpu_exit() call
* fixed commit message, "spapr: support CPU hotplug"
---
hw/ppc/spapr_rtas.c | 12 ++++++++++++

1 file changed, 12 insertions(+)
hw/ppc/spapr_rtas.c +0 -0
index 394ce05..b906294 100644
@@ -202,6 +202,17 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr,
    rtas_st(rets, 0, -3);
 }
 
Quoted 11 lines

hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, · line 212

Quoted 8 lines
hw/ppc/spapr_rtas.c +8 -0
+static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+                           uint32_t token, uint32_t nargs,
+                           target_ulong args,
+                           uint32_t nret, target_ulong rets)
+{
+    CPUState *cs = CPU(cpu);
+
+    cs->halted = 1;

Uh.. I think you still need the msr = 0, or an interrupt could wake the cpu up again.

Quoted 4 lines

Tried with KVM and TCG - nothing wakes up the stopped CPU :-/ After a CPU stopped, the guest calls H_CPPR and disables interrupts on the specific CPU (or "server") on the XICS level. And decrementer interrupt does not wake up the CPU.

Why not? With TCG it should :).

Alex