[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC qom-cpu v4 09/10] piix4: implement function cpu_status
From: |
Chen Fan |
Subject: |
[Qemu-devel] [RFC qom-cpu v4 09/10] piix4: implement function cpu_status_write() for vcpu ejection |
Date: |
Wed, 9 Oct 2013 17:43:17 +0800 |
When OS eject a vcpu (like: echo 1 > /sys/bus/acpi/devices/LNXCPUXX/eject),
it will call acpi EJ0 method, the firmware will write the new cpumap, QEMU
will know which vcpu need to be ejected.
Signed-off-by: Chen Fan <address@hidden>
---
hw/acpi/piix4.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index dc506bf..fd27001 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -61,6 +61,7 @@ struct pci_status {
typedef struct CPUStatus {
uint8_t sts[PIIX4_PROC_LEN];
+ uint8_t old_sts[PIIX4_PROC_LEN];
} CPUStatus;
typedef struct PIIX4PMState {
@@ -611,6 +612,12 @@ static const MemoryRegionOps piix4_pci_ops = {
},
};
+static void acpi_piix_eject_vcpu(int64_t cpuid)
+{
+ /* TODO: eject a vcpu, release allocated vcpu and exit the vcpu pthread.
*/
+ PIIX4_DPRINTF("vcpu: %" PRIu64 " need to be ejected.\n", cpuid);
+}
+
static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
{
PIIX4PMState *s = opaque;
@@ -623,7 +630,27 @@ static uint64_t cpu_status_read(void *opaque, hwaddr addr,
unsigned int size)
static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
unsigned int size)
{
- /* TODO: implement VCPU removal on guest signal that CPU can be removed */
+ PIIX4PMState *s = opaque;
+ CPUStatus *cpus = &s->gpe_cpu;
+ uint8_t val;
+ int i;
+ int64_t cpuid = 0;
+
+ val = cpus->old_sts[addr] ^ data;
+
+ if (val == 0) {
+ return;
+ }
+
+ for (i = 0; i < 8; i++) {
+ if (val & 1 << i) {
+ cpuid = 8 * addr + i;
+ }
+ }
+
+ if (cpuid != 0) {
+ acpi_piix_eject_vcpu(cpuid);
+ }
}
static const MemoryRegionOps cpu_hotplug_ops = {
@@ -643,13 +670,20 @@ static void piix4_cpu_hotplug_req(PIIX4PMState *s,
CPUState *cpu,
ACPIGPE *gpe = &s->ar.gpe;
CPUClass *k = CPU_GET_CLASS(cpu);
int64_t cpu_id;
+ int i;
assert(s != NULL);
*gpe->sts = *gpe->sts | PIIX4_CPU_HOTPLUG_STATUS;
cpu_id = k->get_arch_id(CPU(cpu));
+
+ for (i = 0; i < PIIX4_PROC_LEN; i++) {
+ g->old_sts[i] = g->sts[i];
+ }
+
if (action == PLUG) {
g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
+ g->old_sts[cpu_id / 8] |= (1 << (cpu_id % 8));
} else {
g->sts[cpu_id / 8] &= ~(1 << (cpu_id % 8));
}
@@ -688,6 +722,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent,
g_assert((id / 8) < PIIX4_PROC_LEN);
s->gpe_cpu.sts[id / 8] |= (1 << (id % 8));
+ s->gpe_cpu.old_sts[id / 8] |= (1 << (id % 8));
}
memory_region_init_io(&s->io_cpu, OBJECT(s), &cpu_hotplug_ops, s,
"acpi-cpu-hotplug", PIIX4_PROC_LEN);
--
1.8.1.4
- [Qemu-devel] [RFC qom-cpu v4 00/10] i386: add cpu hot remove support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 02/10] apic: remove redundant variable 'apic_no' from apic_init_common(), Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 04/10] x86: add x86_cpu_unrealizefn() for cpu apic remove, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 01/10] x86: move apic_state field from CPUX86State to X86CPU, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 03/10] apic: remove local_apics array and using CPU_FOREACH instead, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 05/10] qmp: add 'cpu-del' command support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 07/10] qom cpu: add UNPLUG cpu notifier support, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 08/10] i386: implement pc interface pc_hot_del_cpu(), Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 09/10] piix4: implement function cpu_status_write() for vcpu ejection,
Chen Fan <=
- [Qemu-devel] [RFC qom-cpu v4 10/10] cpus: reclaim allocated vCPU objects, Chen Fan, 2013/10/09
- [Qemu-devel] [RFC qom-cpu v4 06/10] qom cpu: rename variable 'cpu_added_notifier' to 'cpu_hotplug_notifier', Chen Fan, 2013/10/09