From patchwork Tue Sep 10 09:43:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 273807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C0E6B2C00EB for ; Tue, 10 Sep 2013 19:46:40 +1000 (EST) Received: from localhost ([::1]:56685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWs-0000Pu-TO for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 05:46:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWO-0000Ji-Ir for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJKWJ-0006n1-Az for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:08 -0400 Received: from [222.73.24.84] (port=59875 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWI-0006lh-WD for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:03 -0400 X-IronPort-AV: E=Sophos;i="4.90,877,1371052800"; d="scan'208";a="8473935" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Sep 2013 17:42:40 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r8A9jm6p024417; Tue, 10 Sep 2013 17:45:48 +0800 Received: from G08FNSTD131468.fnst.cn.fujitsu.com ([10.167.226.78]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013091017432887-1376623 ; Tue, 10 Sep 2013 17:43:28 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 17:43:47 +0800 Message-Id: X-Mailer: git-send-email 1.8.1.4 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:28, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:31, Serialize complete at 2013/09/10 17:43:31 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC qom-cpu v2 7/8] piix4: implement function cpu_status_write() for vcpu ejection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 2ddc9a8..0e9b5bd 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 { @@ -610,6 +611,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; @@ -622,7 +629,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 = { @@ -642,13 +669,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)); } @@ -687,6 +721,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);