From nobody Wed Nov 5 10:51:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504540976326259.9002436813274; Mon, 4 Sep 2017 09:02:56 -0700 (PDT) Received: from localhost ([::1]:54596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotpu-0002nQ-Q3 for importer@patchew.org; Mon, 04 Sep 2017 12:02:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dotXt-0004tT-Ey for qemu-devel@nongnu.org; Mon, 04 Sep 2017 11:44:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dotXo-0001Pr-IX for qemu-devel@nongnu.org; Mon, 04 Sep 2017 11:44:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37106) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dotXo-0001PR-AD for qemu-devel@nongnu.org; Mon, 04 Sep 2017 11:44:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58F124D4C6; Mon, 4 Sep 2017 15:44:11 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B89E11CC32; Mon, 4 Sep 2017 15:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 58F124D4C6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 4 Sep 2017 17:43:15 +0200 Message-Id: <20170904154316.4148-19-david@redhat.com> In-Reply-To: <20170904154316.4148-1-david@redhat.com> References: <20170904154316.4148-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 04 Sep 2017 15:44:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 18/19] s390x: implement query-hotpluggable-cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Eduardo Habkost , david@redhat.com, cohuck@redhat.com, Richard Henderson , Alexander Graf , borntraeger@de.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" CPU hotplug is only possible on a per core basis on s390x. As we now have ms->possible_cpus, we can get rid of the global variable cpu_states. Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 90 +++++++++++++++++++++++++++++++++---------= ---- qapi-schema.json | 16 +++++++++ 2 files changed, 81 insertions(+), 25 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index dd149567bb..458615252c 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -36,22 +36,40 @@ #include "qapi/qmp/qerror.h" #include "hw/nmi.h" =20 -static S390CPU **cpu_states; +static CPUArchId *s390_find_cpu_slot(MachineState *ms, uint32_t core_id, + int *idx) +{ + if (core_id >=3D ms->possible_cpus->len) { + return NULL; + } + /* core_id corresponds to the index */ + if (idx) { + *idx =3D core_id; + } + return &ms->possible_cpus->cpus[core_id]; +} =20 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) { - if (cpu_addr >=3D max_cpus) { - return NULL; + static MachineState *ms; + CPUArchId *found; + + if (!ms) { + ms =3D MACHINE(qdev_get_machine()); } =20 - /* Fast lookup via CPU ID */ - return cpu_states[cpu_addr]; + /* CPU address corresponds to core_id */ + found =3D s390_find_cpu_slot(ms, cpu_addr, NULL); + if (!found) { + return NULL; + } + return S390_CPU(found->cpu); } =20 static void s390_init_cpus(MachineState *machine) { + MachineClass *mc =3D MACHINE_GET_CLASS(machine); int i; - gchar *name; =20 if (machine->cpu_model =3D=3D NULL) { machine->cpu_model =3D s390_default_cpu_model_name(); @@ -63,17 +81,8 @@ static void s390_init_cpus(MachineState *machine) exit(1); } =20 - cpu_states =3D g_new0(S390CPU *, max_cpus); - - for (i =3D 0; i < max_cpus; i++) { - name =3D g_strdup_printf("cpu[%i]", i); - object_property_add_link(OBJECT(machine), name, TYPE_S390_CPU, - (Object **) &cpu_states[i], - object_property_allow_set_link, - OBJ_PROP_LINK_UNREF_ON_RELEASE, - &error_abort); - g_free(name); - } + /* initialize possible_cpus */ + mc->possible_cpu_arch_ids(machine); =20 for (i =3D 0; i < smp_cpus; i++) { s390x_new_cpu(machine->cpu_model, i, &error_fatal); @@ -304,17 +313,14 @@ static void ccw_init(MachineState *machine) register_savevm_live(NULL, "todclock", 0, 1, &savevm_gtod, NULL); } =20 -static void s390_cpu_plug(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void s390_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp) { - gchar *name; + MachineState *ms =3D MACHINE(hotplug_dev); S390CPU *cpu =3D S390_CPU(dev); - CPUState *cs =3D CPU(dev); =20 - name =3D g_strdup_printf("cpu[%i]", cpu->env.core_id); - object_property_set_link(OBJECT(hotplug_dev), OBJECT(cs), name, - errp); - g_free(name); + g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu); + ms->possible_cpus->cpus[cpu->env.core_id].cpu =3D OBJECT(dev); } =20 static void s390_machine_reset(void) @@ -347,6 +353,37 @@ static void s390_machine_device_unplug_request(Hotplug= Handler *hotplug_dev, } } =20 +static CpuInstanceProperties s390_cpu_index_to_props(MachineState *machine, + unsigned cpu_index) +{ + CPUArchId *slot =3D s390_find_cpu_slot(machine, cpu_index, NULL); + + assert(slot); + return slot->props; +} + +static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms) +{ + int i; + + if (ms->possible_cpus) { + g_assert(ms->possible_cpus && ms->possible_cpus->len =3D=3D max_cp= us); + return ms->possible_cpus; + } + + ms->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + + sizeof(CPUArchId) * max_cpus); + ms->possible_cpus->len =3D max_cpus; + for (i =3D 0; i < ms->possible_cpus->len; i++) { + ms->possible_cpus->cpus[i].vcpus_count =3D 1; + ms->possible_cpus->cpus[i].arch_id =3D i; + ms->possible_cpus->cpus[i].props.has_core_id =3D true; + ms->possible_cpus->cpus[i].props.core_id =3D i; + } + + return ms->possible_cpus; +} + static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, DeviceState *dev) { @@ -394,7 +431,10 @@ static void ccw_machine_class_init(ObjectClass *oc, vo= id *data) mc->no_sdcard =3D 1; mc->use_sclp =3D 1; mc->max_cpus =3D 248; + mc->has_hotpluggable_cpus =3D true; mc->get_hotplug_handler =3D s390_get_hotplug_handler; + mc->cpu_index_to_instance_props =3D s390_cpu_index_to_props; + mc->possible_cpu_arch_ids =3D s390_possible_cpu_arch_ids; hc->plug =3D s390_machine_device_plug; hc->unplug_request =3D s390_machine_device_unplug_request; nc->nmi_monitor_handler =3D s390_nmi; diff --git a/qapi-schema.json b/qapi-schema.json index f3af2cb851..79e9f85404 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3121,6 +3121,22 @@ # } # ]} # +# For s390x-virtio-ccw machine type started with -smp 1,maxcpus=3D2 -cpu q= emu +# (Since: 2.11): +# +# -> { "execute": "query-hotpluggable-cpus" } +# <- {"return": [ +# { +# "type": "qemu-s390-cpu", "vcpus-count": 1, +# "props": { "core-id": 1 } +# }, +# { +# "qom-path": "/machine/unattached/device[0]", +# "type": "qemu-s390-cpu", "vcpus-count": 1, +# "props": { "core-id": 0 } +# } +# ]} +# ## { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] } =20 --=20 2.13.5