From patchwork Fri Mar 4 06:54:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 8499571 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 670F5C0553 for ; Fri, 4 Mar 2016 06:57:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EF8D2021F for ; Fri, 4 Mar 2016 06:57:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5010C2011B for ; Fri, 4 Mar 2016 06:57:21 +0000 (UTC) Received: from localhost ([::1]:39123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abjfs-0006Br-N2 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Mar 2016 01:57:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abjdX-0001tt-IE for qemu-devel@nongnu.org; Fri, 04 Mar 2016 01:54:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abjdT-0005Vg-7W for qemu-devel@nongnu.org; Fri, 04 Mar 2016 01:54:55 -0500 Received: from e28smtp03.in.ibm.com ([125.16.236.3]:39368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abjdS-0005VC-8j for qemu-devel@nongnu.org; Fri, 04 Mar 2016 01:54:51 -0500 Received: from localhost by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 4 Mar 2016 12:24:47 +0530 Received: from d28relay02.in.ibm.com (9.184.220.59) by e28smtp03.in.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 4 Mar 2016 12:24:46 +0530 X-IBM-Helo: d28relay02.in.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-ppc@nongnu.org;qemu-devel@nongnu.org Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay02.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u246scp914876960; Fri, 4 Mar 2016 12:24:38 +0530 Received: from d28av03.in.ibm.com (localhost [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u246sgou030172; Fri, 4 Mar 2016 12:24:43 +0530 Received: from bharata.in.ibm.com ([9.124.212.244]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u246sQDX029500; Fri, 4 Mar 2016 12:24:40 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Fri, 4 Mar 2016 12:24:18 +0530 Message-Id: <1457074461-14285-8-git-send-email-bharata@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1457074461-14285-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1457074461-14285-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 16030406-0009-0000-0000-00000AE3B3EB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 125.16.236.3 Cc: mjrosato@linux.vnet.ibm.com, thuth@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, aik@ozlabs.ru, Bharata B Rao , armbru@redhat.com, agraf@suse.de, borntraeger@de.ibm.com, qemu-ppc@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com, mdroth@linux.vnet.ibm.com, afaerber@suse.de, david@gibson.dropbear.id.au Subject: [Qemu-devel] [RFC PATCH v1 07/10] spapr: Represent boot CPUs as spapr-cpu-core devices 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Initialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links. Also prevent topologies that have or can result in incomplete cores. Signed-off-by: Bharata B Rao --- hw/ppc/spapr.c | 85 ++++++++++++++++++++++++++++++++++++++++++------- hw/ppc/spapr_cpu_core.c | 9 ++++++ include/hw/ppc/spapr.h | 4 +++ 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index e9d4abf..5acb612 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -64,6 +64,7 @@ #include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include @@ -1614,8 +1615,11 @@ static void spapr_boot_set(void *opaque, const char *boot_device, machine->boot_order = g_strdup(boot_device); } -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, - Error **errp) +/* + * TODO: Check if some of these can be moved to rtas_start_cpu() where + * a few other things required for hotplugged CPUs are being done. + */ +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp) { CPUPPCState *env = &cpu->env; @@ -1643,7 +1647,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, } xics_cpu_setup(spapr->icp, cpu); - qemu_register_reset(spapr_cpu_reset, cpu); } @@ -1720,6 +1723,28 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* + * Check to see if core is being hot-plugged into an already populated slot. + */ +static void spapr_cpu_core_allow_set_link(Object *obj, const char *name, + Object *val, Error **errp) +{ + Object *core = object_property_get_link(qdev_get_machine(), name, NULL); + + /* + * Allow the link to be unset when the core is unplugged. + */ + if (!val) { + return; + } + + if (core) { + char *path = object_get_canonical_path(core); + error_setg(errp, "Slot %s already populated with %s", name, path); + g_free(path); + } +} + /* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init(MachineState *machine) { @@ -1728,7 +1753,6 @@ static void ppc_spapr_init(MachineState *machine) const char *kernel_filename = machine->kernel_filename; const char *kernel_cmdline = machine->kernel_cmdline; const char *initrd_filename = machine->initrd_filename; - PowerPCCPU *cpu; PCIHostState *phb; int i; MemoryRegion *sysmem = get_system_memory(); @@ -1742,6 +1766,20 @@ static void ppc_spapr_init(MachineState *machine) long load_limit, fw_size; bool kernel_le = false; char *filename; + int spapr_cores = smp_cpus / smp_threads; + int spapr_max_cores = max_cpus / smp_threads; + + if (smp_cpus % smp_threads) { + error_report("smp_cpus (%u) must be multiple of threads (%u)", + smp_cpus, smp_threads); + exit(1); + } + + if (max_cpus % smp_threads) { + error_report("max_cpus (%u) must be multiple of threads (%u)", + max_cpus, smp_threads); + exit(1); + } msi_supported = true; @@ -1800,13 +1838,37 @@ static void ppc_spapr_init(MachineState *machine) if (machine->cpu_model == NULL) { machine->cpu_model = kvm_enabled() ? "host" : "POWER7"; } - for (i = 0; i < smp_cpus; i++) { - cpu = cpu_ppc_init(machine->cpu_model); - if (cpu == NULL) { - error_report("Unable to find PowerPC CPU definition"); - exit(1); + + spapr->cores = g_new0(Object *, spapr_max_cores); + + for (i = 0; i < spapr_max_cores; i++) { + char name[32]; + + /* + * Create links from machine objects to all possible cores. + */ + snprintf(name, sizeof(name), "%s[%d]", SPAPR_MACHINE_CPU_CORE_PROP, i); + object_property_add_link(OBJECT(spapr), name, TYPE_SPAPR_CPU_CORE, + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link, + OBJ_PROP_LINK_UNREF_ON_RELEASE, + &error_fatal); + + /* + * Create cores and set link from machine object to core object for + * boot time CPUs and realize them. + */ + if (i < spapr_cores) { + Object *core = object_new(TYPE_SPAPR_CPU_CORE); + + object_property_set_str(core, machine->cpu_model, "cpu_model", + &error_fatal); + object_property_set_int(core, smp_threads, "nr_threads", + &error_fatal); + object_property_set_str(core, name, CPU_CORE_SLOT_PROP, + &error_fatal); + object_property_set_bool(core, true, "realized", &error_fatal); } - spapr_cpu_init(spapr, cpu, &error_fatal); } if (kvm_enabled()) { @@ -2259,7 +2321,8 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine, DeviceState *dev) { - if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || + object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { return HOTPLUG_HANDLER(machine); } return NULL; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 3f3440c..9ddf3ce 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -17,11 +17,20 @@ static int spapr_cpu_core_realize_child(Object *child, void *opaque) { Error **errp = opaque; + sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); + CPUState *cs = CPU(child); + PowerPCCPU *cpu = POWERPC_CPU(cs); object_property_set_bool(child, true, "realized", errp); if (*errp) { return 1; } + + spapr_cpu_init(spapr, cpu, errp); + if (*errp) { + return 1; + } + return 0; } diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 098d85d..06e6cec 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -79,8 +79,11 @@ struct sPAPRMachineState { /*< public >*/ char *kvm_type; MemoryHotplugState hotplug_memory; + Object **cores; }; +#define SPAPR_MACHINE_CPU_CORE_PROP "core" + #define H_SUCCESS 0 #define H_BUSY 1 /* Hardware busy -- retry later */ #define H_CLOSED 2 /* Resource closed */ @@ -585,6 +588,7 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type, uint32_t count); void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type, uint32_t count); +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp); /* rtas-configure-connector state */ struct sPAPRConfigureConnectorState {