From patchwork Mon Sep 16 02:40:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 275099 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 8F72A2C00D5 for ; Mon, 16 Sep 2013 12:47:51 +1000 (EST) Received: from localhost ([::1]:59423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLOqr-0003qM-Np for incoming@patchwork.ozlabs.org; Sun, 15 Sep 2013 22:47:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLOmi-00068g-5D for qemu-devel@nongnu.org; Sun, 15 Sep 2013 22:43:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLOmd-0006P4-3S for qemu-devel@nongnu.org; Sun, 15 Sep 2013 22:43:32 -0400 Received: from [222.73.24.84] (port=59971 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLOmc-0006LH-Mx for qemu-devel@nongnu.org; Sun, 15 Sep 2013 22:43:27 -0400 X-IronPort-AV: E=Sophos;i="4.90,912,1371052800"; d="scan'208";a="8533934" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 16 Sep 2013 10:39:58 +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 r8G2h4PW019070; Mon, 16 Sep 2013 10:43:09 +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 2013091610413544-1530032 ; Mon, 16 Sep 2013 10:41:35 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Mon, 16 Sep 2013 10:40:52 +0800 Message-Id: <443499ed1c9978b00f3bdef3218203fc3d3d81e5.1379062188.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/16 10:41:35, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/16 10:41:42, Serialize complete at 2013/09/16 10:41:42 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 v3 08/10] 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 | 30 ++++++++++++++++++++++++++++-- qom/cpu.c | 12 ++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8ab6e4f..ce7b20f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -958,8 +958,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. */ - error_setg(errp, "Hot-remove CPU is not supported."); + 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 " + "one 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..b413a4c 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -227,6 +227,17 @@ 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 +268,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; }