From patchwork Tue Sep 10 09:43:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 273811 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 D03E92C0109 for ; Tue, 10 Sep 2013 19:48:52 +1000 (EST) Received: from localhost ([::1]:56703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKZ1-0004ev-1J for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 05:48:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWO-0000Jg-0x for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJKWJ-0006mv-AK for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:07 -0400 Received: from [222.73.24.84] (port=64787 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWI-0006ii-Ux 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="8473934" 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 r8A9jlrT024413; 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 2013091017432885-1376622 ; Tue, 10 Sep 2013 17:43:28 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 17:43:46 +0800 Message-Id: <974bab7bbd33238e4a80d870735bd80e5e3eb646.1378796990.git.chen.fan.fnst@cn.fujitsu.com> 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 6/8] i386: implement pc interface pc_hot_del_cpu() 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 Implement cpu interface pc_hot_del_cpu() for unrealizing device vCPU. emiting vcpu-remove notifier to ACPI, then ACPI could send sci interrupt to OS for hot-remove vcpu. Signed-off-by: Chen Fan --- hw/i386/pc.c | 29 ++++++++++++++++++++++++++++- qom/cpu.c | 11 +++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f36903f..6f88e41 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -959,7 +959,34 @@ void pc_hot_add_cpu(const int64_t id, Error **errp) void pc_hot_del_cpu(const int64_t id, Error **errp) { - /* TODO: hot remove vCPU. */ + CPUState *cpu; + bool found = false; + X86CPUClass *xcc; + + CPU_FOREACH(cpu) { + CPUClass *cc = CPU_GET_CLASS(cpu); + int64_t cpuid = cc->get_arch_id(cpu); + + if (cpuid == id) { + found = true; + break; + } + } + + if (!found) { + error_setg(errp, "Unable to find cpu-index: %" PRIi64 + ", it doesn't exist or has been deleted.", id); + return; + } + + if (cpu == first_cpu && !CPU_NEXT(cpu)) { + error_setg(errp, "Unable to delete the last" + " cpu when VM running."); + return; + } + + xcc = X86_CPU_GET_CLASS(DEVICE(cpu)); + xcc->parent_unrealize(DEVICE(cpu), errp); } void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge) diff --git a/qom/cpu.c b/qom/cpu.c index c6d7ebc..9cd7fcd 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -227,6 +227,16 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } } +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp) +{ + CPUNotifier notifier; + + notifier.dev = dev; + notifier.type = UNPLUG; + + notifier_list_notify(&cpu_hotplug_notifiers, ¬ifier); +} + static void cpu_common_initfn(Object *obj) { CPUState *cpu = CPU(obj); @@ -257,6 +267,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->gdb_read_register = cpu_common_gdb_read_register; k->gdb_write_register = cpu_common_gdb_write_register; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn; dc->no_user = 1; }