From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMqud-0008Rv-GX for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:02:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMquS-0005Cm-Pz for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:02:15 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:49969) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMquS-0005Ca-9i for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:02:04 -0400 Received: from kw-mxoi1.gw.nic.fujitsu.com (unknown [10.0.237.133]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 7833B3EE14B for ; Thu, 28 Aug 2014 13:02:03 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by kw-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 691C3AC084F for ; Thu, 28 Aug 2014 13:02:02 +0900 (JST) Received: from s00.gw.fujitsu.co.jp (s00.gw.nic.fujitsu.com [133.161.11.15]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id E3054E18001 for ; Thu, 28 Aug 2014 13:02:01 +0900 (JST) From: Gu Zheng Date: Thu, 28 Aug 2014 11:36:41 +0800 Message-Id: <1409197002-9498-10-git-send-email-guz.fnst@cn.fujitsu.com> In-Reply-To: <1409197002-9498-1-git-send-email-guz.fnst@cn.fujitsu.com> References: <1409197002-9498-1-git-send-email-guz.fnst@cn.fujitsu.com> Subject: [Qemu-devel] [RFC V2 09/10] cpu hotplug: implement function cpu_status_write() for vcpu ejection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, imammedo@redhat.com, afaerber@suse.de Cc: chen.fan.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, isimatu.yasuaki@jp.fujitsu.com, Gu Zheng , tangchen@cn.fujitsu.com From: Chen Fan When OS ejected a vcpu (like: echo 1 > /sys/bus/acpi/devices/LNXCPUXX/eject), it would call acpi EJ0 method, the firmware need to write the new cpumap, QEMU would know which vcpu need to be ejected. TODO: -confirm the hotplug result via OST if guest support it. Signed-off-by: Chen Fan Signed-off-by: Gu Zheng --- cpus.c | 7 ++++++ hw/acpi/cpu_hotplug.c | 40 ++++++++++++++++++++++++++++++++++++- hw/i386/acpi-dsdt-cpu-hotplug.dsl | 6 ++++- include/hw/acpi/cpu_hotplug.h | 1 + include/qom/cpu.h | 9 ++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index cce2744..eee693b 100644 --- a/cpus.c +++ b/cpus.c @@ -1182,6 +1182,13 @@ void resume_all_vcpus(void) } } +void cpu_remove(CPUState *cpu) +{ + cpu->stop = true; + cpu->exit = true; + qemu_cpu_kick(cpu); +} + /* For temporary buffers for forming a name */ #define VCPU_THREAD_NAME_SIZE 16 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c index 56cb316..7cbce69 100644 --- a/hw/acpi/cpu_hotplug.c +++ b/hw/acpi/cpu_hotplug.c @@ -20,10 +20,46 @@ static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size) return val; } +static void acpi_eject_vcpu(AcpiCpuHotplug *cpus_status, int64_t cpu_id) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + CPUClass *cc = CPU_GET_CLASS(cpu); + int64_t id = cc->get_arch_id(cpu); + + if (cpu_id == id) { + cpus_status->old_sts[cpu_id / 8] &= ~(1 << (cpu_id % 8)); + cpus_status->sts[cpu_id / 8] &= ~(1 << (cpu_id % 8)); + cpu_remove(cpu); + break; + } + } +} + 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 */ + AcpiCpuHotplug *cpus = opaque; + uint8_t val; + int i; + int64_t cpu_id = -1; + + val = cpus->old_sts[addr] ^ data; + + if (val == 0) { + return; + } + + for (i = 0; i < 8; i++) { + if (val & 1 << i) { + cpu_id = 8 * addr + i; + } + } + + if (cpu_id != -1) { + acpi_eject_vcpu(cpus, cpu_id); + } } static const MemoryRegionOps AcpiCpuHotplug_ops = { @@ -49,6 +85,7 @@ void AcpiCpuHotplug_handle(ACPIGPE *gpe, AcpiCpuHotplug *g, if (type == 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)); } @@ -65,6 +102,7 @@ void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner, g_assert((id / 8) < ACPI_GPE_PROC_LEN); gpe_cpu->sts[id / 8] |= (1 << (id % 8)); + gpe_cpu->old_sts[id / 8] |= (1 << (id % 8)); } memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops, gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN); diff --git a/hw/i386/acpi-dsdt-cpu-hotplug.dsl b/hw/i386/acpi-dsdt-cpu-hotplug.dsl index 34aab5a..9485f12 100644 --- a/hw/i386/acpi-dsdt-cpu-hotplug.dsl +++ b/hw/i386/acpi-dsdt-cpu-hotplug.dsl @@ -50,7 +50,11 @@ Scope(\_SB) { } Method(CPEJ, 2, NotSerialized) { // _EJ0 method - eject callback - Sleep(200) + Store(Zero, Index(CPON, ToInteger(Arg0))) + Store(One, Local0) + ShiftLeft(Local0, Arg0, Local0) + Not(Local0, Local0) + And(PRS, Local0, PRS) } #define CPU_STATUS_LEN ACPI_GPE_PROC_LEN diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h index 4fe0066..3bffc69 100644 --- a/include/hw/acpi/cpu_hotplug.h +++ b/include/hw/acpi/cpu_hotplug.h @@ -28,6 +28,7 @@ typedef struct CPUNotifier { typedef struct AcpiCpuHotplug { MemoryRegion io; uint8_t sts[ACPI_GPE_PROC_LEN]; + uint8_t old_sts[ACPI_GPE_PROC_LEN]; } AcpiCpuHotplug; void AcpiCpuHotplug_handle(ACPIGPE *gpe, AcpiCpuHotplug *g, diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 2fc00ef..9108dc6 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -236,6 +236,7 @@ struct CPUState { bool created; bool stop; bool stopped; + bool exit; volatile sig_atomic_t exit_request; uint32_t interrupt_request; int singlestep_enabled; @@ -600,6 +601,14 @@ void cpu_exit(CPUState *cpu); void cpu_resume(CPUState *cpu); /** + * cpu_remove: + * @cpu: The vCPU to remove. + * + * Requests the CPU @cpu to be removed. + */ +void cpu_remove(CPUState *cpu); + +/** * qemu_init_vcpu: * @cpu: The vCPU to initialize. * -- 1.7.7