From patchwork Fri Aug 1 11:49:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshul Makkar X-Patchwork-Id: 375720 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A687A1400FA for ; Fri, 1 Aug 2014 21:50:23 +1000 (EST) Received: from localhost ([::1]:38570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDBLp-0007De-Kf for incoming@patchwork.ozlabs.org; Fri, 01 Aug 2014 07:50:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDBLT-0006oz-7L for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:50:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDBLM-0006Rd-Vk for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:49:59 -0400 Received: from mail-qa0-f42.google.com ([209.85.216.42]:34219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDBLM-0006RX-QF for qemu-devel@nongnu.org; Fri, 01 Aug 2014 07:49:52 -0400 Received: by mail-qa0-f42.google.com with SMTP id j15so3781802qaq.15 for ; Fri, 01 Aug 2014 04:49:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=Y9uSe4zikIhxhTgtQbY0ExPbHamIww+fdVFGkYkvnVI=; b=ltJMpDxj+1h7SMtydxAqNj2FcPyQTgjddByVdh6OeXge6IEpJbiX1EymT9/2+3kzD3 XD0Hy5WPm4zY22BVH9TjL6VEkQSzHxudmq51QCtsrLe9MYZRzsqL8fU3RaT73yBwUuZC nXsHe5uQIs/AnzZFlnYiKglpbXOj86W11unXA5/CAMFChVivGmCAiRjB6E4fRuqH3MLq vObnQ1YhHS0AEERaKzuPyo50x3UPxifzc8R72qN1MuJ8Bo5wcJV3F8ds6SsXT9YzAeEp bmGmzb7TJcNTJInRJVJfyXHynWjW4H02hX83yWwGgszOeWUug+L/9pywXJL+QWnYWgvW sISg== X-Gm-Message-State: ALoCoQlYvx+AbgHoi1aYHnnAt+nz0RHSvungFAKIef5jyMqcMKbwcbQQBr982V/2p99YXYMUX8Nn X-Received: by 10.224.104.1 with SMTP id m1mr8328914qao.81.1406893792016; Fri, 01 Aug 2014 04:49:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.85.149 with HTTP; Fri, 1 Aug 2014 04:49:31 -0700 (PDT) From: Anshul Makkar Date: Fri, 1 Aug 2014 13:49:31 +0200 Message-ID: To: qemu-devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.216.42 Subject: [Qemu-devel] "cpu-del" support over and above the RFC patches for cpu-hotunplug 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 Hi, Attached is the patch for addition of "cpu-del" command over and above the below patches for hot removing the cpu. [RFC PATCH 0/7] i386: add cpu hot remove support [RFC PATCH 1/7] x86: add x86_cpu_unrealizefn() for cpu apic remove [RFC PATCH 2/7] i386: add cpu device_del support [RFC PATCH 3/7] qom cpu: rename variable 'cpu_added_notifier' to 'cpu_hotplug_notifier' [RFC PATCH 4/7] qom cpu: add UNPLUG cpu notify support [RFC PATCH 5/7] i386: implement pc interface cpu_common_unrealizefn() in qom/cpu.c [RFC PATCH 6/7] cpu hotplug: implement function cpu_status_write() for vcpu ejection [RFC PATCH 7/7] cpus: reclaim allocated vCPU objects Useful, just in case if anyone wants to continue with the old / compatible "cpu-del" command. Patch for addition of "cpu-del" command: +++ b/include/hw/boards.h @@ -25,6 +25,8 @@ typedef void QEMUMachineResetFunc(void); typedef void QEMUMachineHotAddCPUFunc(const int64_t id, Error **errp); +typedef void QEMUMachineHotDelCPUFunc(const int64_t id, Error **errp); + typedef int QEMUMachineGetKvmtypeFunc(const char *arg); struct QEMUMachine { @@ -34,6 +36,7 @@ struct QEMUMachine { QEMUMachineInitFunc *init; QEMUMachineResetFunc *reset; QEMUMachineHotAddCPUFunc *hot_add_cpu; + QEMUMachineHotDelCPUFunc *hot_del_cpu; QEMUMachineGetKvmtypeFunc *kvm_type; BlockInterfaceType block_default_type; int max_cpus; hw/i386/pc.c +void pc_hot_del_cpu(const int64_t id, Error **errp) +{ + int64_t apic_id = x86_cpu_apic_id_from_index(id); + fprintf(stderr, "pc.c: pc_hot_del_cpu for apic_id = %d\n", apic_id); + + if (id < 0) { + error_setg(errp, "Invalid CPU id: %" PRIi64, id); + return; + } + + if (!cpu_exists(apic_id)) { + error_setg(errp, "Unable to remove CPU: %" PRIi64 + ", it does not exists", id); + return; + } + + if (id >= max_cpus) { + error_setg(errp, "Unable to remove CPU: %" PRIi64 + ", max allowed: %d", id, max_cpus - 1); + return; + } + + CPUState *cpu = first_cpu; + X86CPUClass *xcc = NULL; + while (cpu = CPU_NEXT(cpu)) { + fprintf(stderr, "cpu threa_id = %d, cpu_index = %d\n", cpu->thread_id, cpu->cpu_index); + if ((cpu->cpu_index + 1) == apic_id) + break; + } if (cpu == first_cpu) { fprintf(stderr, "Unable to delete the last one cpu.\n"); return; } xcc = X86_CPU_GET_CLASS(DEVICE(cpu)); xcc->parent_unrealize(DEVICE(cpu), errp); } Anshul Makkar wwwdotjustkerneldotcom diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index f2d39d2..33350fc 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -163,6 +163,7 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level); void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge); void pc_hot_add_cpu(const int64_t id, Error **errp); +void pc_hot_del_cpu(const int64_t id, Error **errp); void pc_acpi_init(const char *default_dsdt); PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size, @@ -472,6 +473,7 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); #define PC_DEFAULT_MACHINE_OPTIONS \ PC_COMMON_MACHINE_OPTIONS, \ .hot_add_cpu = pc_hot_add_cpu, \ + .hot_del_cpu = pc_hot_del_cpu, \ .max_cpus = 255 #endif diff --git a/qmp.c b/qmp.c index 95369f9..fc494da 100644 --- a/qmp.c +++ b/qmp.c @@ -126,6 +126,18 @@ void qmp_cpu_add(int64_t id, Error **errp) } } +void qmp_cpu_del(int64_t id, Error **errp) +{ + MachineClass *mc; + mc = MACHINE_GET_CLASS(current_machine); + if (mc->qemu_machine->hot_del_cpu) { + mc->qemu_machine->hot_del_cpu(id, errp); + } + else { + error_setg(errp, "Not supported"); + } +} + #ifndef CONFIG_VNC /* If VNC support is enabled, the "true" query-vnc command is defined in the VNC subsystem */