[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/28] spapr_cpu_core: Implement DeviceClass::reset
From: |
David Gibson |
Subject: |
[PULL 23/28] spapr_cpu_core: Implement DeviceClass::reset |
Date: |
Thu, 24 Oct 2019 19:18:08 +1100 |
From: Greg Kurz <address@hidden>
Since vCPUs aren't plugged into a bus, we manually register a reset
handler for each vCPU. We also call this handler at realize time
to ensure hot plugged vCPUs are reset before being exposed to the
guest. This results in vCPUs being reset twice at machine reset.
It doesn't break anything but it is slightly suboptimal and above
all confusing.
The hotplug path in device_set_realized() already knows how to reset
a hotplugged device if the device reset handler is present. Implement
one for sPAPR CPU cores that resets all vCPUs under a core.
While here rename spapr_cpu_reset() to spapr_reset_vcpu() for
consistency with spapr_realize_vcpu() and spapr_unrealize_vcpu().
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
[clg: add documentation on the reset helper usage ]
Signed-off-by: Cédric Le Goater <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: David Gibson <address@hidden>
---
hw/ppc/spapr_cpu_core.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 2b21285d20..2e34832d0e 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -25,9 +25,8 @@
#include "sysemu/hw_accel.h"
#include "qemu/error-report.h"
-static void spapr_cpu_reset(void *opaque)
+static void spapr_reset_vcpu(PowerPCCPU *cpu)
{
- PowerPCCPU *cpu = opaque;
CPUState *cs = CPU(cpu);
CPUPPCState *env = &cpu->env;
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
@@ -193,7 +192,6 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu,
SpaprCpuCore *sc)
if (!sc->pre_3_0_migration) {
vmstate_unregister(NULL, &vmstate_spapr_cpu_state, cpu->machine_data);
}
- qemu_unregister_reset(spapr_cpu_reset, cpu);
if (spapr_cpu_state(cpu)->icp) {
object_unparent(OBJECT(spapr_cpu_state(cpu)->icp));
}
@@ -204,12 +202,36 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu,
SpaprCpuCore *sc)
object_unparent(OBJECT(cpu));
}
+/*
+ * Called when CPUs are hot-plugged.
+ */
+static void spapr_cpu_core_reset(DeviceState *dev)
+{
+ CPUCore *cc = CPU_CORE(dev);
+ SpaprCpuCore *sc = SPAPR_CPU_CORE(dev);
+ int i;
+
+ for (i = 0; i < cc->nr_threads; i++) {
+ spapr_reset_vcpu(sc->threads[i]);
+ }
+}
+
+/*
+ * Called by the machine reset.
+ */
+static void spapr_cpu_core_reset_handler(void *opaque)
+{
+ spapr_cpu_core_reset(opaque);
+}
+
static void spapr_cpu_core_unrealize(DeviceState *dev, Error **errp)
{
SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
CPUCore *cc = CPU_CORE(dev);
int i;
+ qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
+
for (i = 0; i < cc->nr_threads; i++) {
spapr_unrealize_vcpu(sc->threads[i], sc);
}
@@ -238,12 +260,6 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu,
SpaprMachineState *spapr,
goto error_intc_create;
}
- /*
- * FIXME: Hot-plugged CPUs are not reset. Do it at realize.
- */
- qemu_register_reset(spapr_cpu_reset, cpu);
- spapr_cpu_reset(cpu);
-
if (!sc->pre_3_0_migration) {
vmstate_register(NULL, cs->cpu_index, &vmstate_spapr_cpu_state,
cpu->machine_data);
@@ -338,6 +354,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error
**errp)
goto err_unrealize;
}
}
+
+ qemu_register_reset(spapr_cpu_core_reset_handler, sc);
return;
err_unrealize:
@@ -366,6 +384,7 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void
*data)
dc->realize = spapr_cpu_core_realize;
dc->unrealize = spapr_cpu_core_unrealize;
+ dc->reset = spapr_cpu_core_reset;
dc->props = spapr_cpu_core_properties;
scc->cpu_type = data;
}
--
2.21.0
- [PULL 05/28] ppc/pnv: Use address_space_stq_be() when triggering an interrupt from PSI, (continued)
- [PULL 05/28] ppc/pnv: Use address_space_stq_be() when triggering an interrupt from PSI, David Gibson, 2019/10/24
- [PULL 02/28] xics: Make some device types not user creatable, David Gibson, 2019/10/24
- [PULL 01/28] xive: Make some device types not user creatable, David Gibson, 2019/10/24
- [PULL 07/28] spapr, xics, xive: Introduce SpaprInterruptController QOM interface, David Gibson, 2019/10/24
- [PULL 03/28] target/ppc: Fix for optimized vsl/vsr instructions, David Gibson, 2019/10/24
- [PULL 11/28] spapr, xics, xive: Move set_irq from SpaprIrq to SpaprInterruptController, David Gibson, 2019/10/24
- [PULL 04/28] ppc/pnv: Improve trigger data definition, David Gibson, 2019/10/24
- [PULL 21/28] spapr: Don't request to unplug the same core twice, David Gibson, 2019/10/24
- [PULL 10/28] spapr: Formalize notion of active interrupt controller, David Gibson, 2019/10/24
- [PULL 08/28] spapr, xics, xive: Move cpu_intc_create from SpaprIrq to SpaprInterruptController, David Gibson, 2019/10/24
- [PULL 23/28] spapr_cpu_core: Implement DeviceClass::reset,
David Gibson <=
- [PULL 09/28] spapr, xics, xive: Move irq claim and free from SpaprIrq to SpaprInterruptController, David Gibson, 2019/10/24
- [PULL 18/28] spapr: Remove SpaprIrq::nr_msis, David Gibson, 2019/10/24
- [PULL 27/28] ppc/pnv: Fix naming of routines realizing the CPUs, David Gibson, 2019/10/24
- [PULL 28/28] spapr/xive: Set the OS CAM line at reset, David Gibson, 2019/10/24
- [PULL 13/28] spapr, xics, xive: Move dt_populate from SpaprIrq to SpaprInterruptController, David Gibson, 2019/10/24
- [PULL 12/28] spapr, xics, xive: Move print_info from SpaprIrq to SpaprInterruptController, David Gibson, 2019/10/24
- [PULL 17/28] spapr, xics, xive: Move SpaprIrq::post_load hook to backends, David Gibson, 2019/10/24
- [PULL 06/28] spapr: Set VSMT to smp_threads by default, David Gibson, 2019/10/24
- [PULL 22/28] spapr: move CPU reset after presenter creation, David Gibson, 2019/10/24
- [PULL 15/28] spapr: Remove SpaprIrq::init_kvm hook, David Gibson, 2019/10/24