Received: from eggs.gnu.org ([2001:4830:134:3::10]:33193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTakH-0007w3-Bp for qemu-devel@nongnu.org; Thu, 05 Mar 2015 13:43:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTakA-0006Ss-QJ for qemu-devel@nongnu.org; Thu, 05 Mar 2015 13:43:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTakA-0006Sm-Id for qemu-devel@nongnu.org; Thu, 05 Mar 2015 13:43:34 -0500 Date: Thu, 5 Mar 2015 15:43:26 -0300 From: Eduardo Habkost Message-ID: <20150305184326.GJ13041@thinpad.lan.raisama.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 09/10] cpu: add device_add foo-x86_64-cpu support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhu Guihua Cc: qemu-devel@nongnu.org, tangchen@cn.fujitsu.com, chen.fan.fnst@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, imammedo@redhat.com, guz.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, afaerber@suse.de On Fri, Feb 13, 2015 at 06:25:32PM +0800, Zhu Guihua wrote: > From: Chen Fan >=20 > Add support to device_add foo-x86_64-cpu, and additional checks of > apic id are added into x86_cpuid_set_apic_id() to avoid duplicate. > Besides, in order to support "device/device_add foo-x86_64-cpu" > which without specified apic id, we assign cpuid_apic_id with a > default broadcast value (0xFFFFFFFF) in initfn, and a new function > get_free_apic_id() to provide a free apid id to cpuid_apic_id if > it still has the default at realize time (e.g. hot add foo-cpu without > a specified apic id) to avoid apic id duplicates. >=20 > Thanks very much for Igor's suggestion. >=20 > Signed-off-by: Chen Fan > Signed-off-by: Gu Zheng > Signed-off-by: Zhu Guihua > --- > hw/acpi/cpu_hotplug.c | 6 ++++-- > hw/i386/pc.c | 6 ------ > target-i386/cpu.c | 48 +++++++++++++++++++++++++++++++++++++++++++= ++--- > 3 files changed, 49 insertions(+), 11 deletions(-) >=20 > diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c > index b8ebfad..8e4ed6e 100644 > --- a/hw/acpi/cpu_hotplug.c > +++ b/hw/acpi/cpu_hotplug.c > @@ -59,8 +59,10 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq, > return; > } > =20 > - ar->gpe.sts[0] |=3D ACPI_CPU_HOTPLUG_STATUS; > - acpi_update_sci(ar, irq); > + /* Only trigger sci if cpu is hotplugged */ > + if (dev->hotplugged) { > + acpi_send_gpe_event(ar, irq, ACPI_CPU_HOTPLUG_STATUS); > + } > } > =20 > void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 500d369..1187e12 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1637,13 +1637,7 @@ static void pc_cpu_plug(HotplugHandler *hotplug_= dev, > Error *local_err =3D NULL; > PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); > =20 > - if (!dev->hotplugged) { > - goto out; > - } > - > if (!pcms->acpi_dev) { > - error_setg(&local_err, > - "cpu hotplug is not enabled: missing acpi device"); > goto out; > } > =20 > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 028063c..68a6aa4 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -1703,6 +1703,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Vi= sitor *v, void *opaque, > const int64_t max =3D UINT32_MAX; > Error *error =3D NULL; > int64_t value; > + X86CPUTopoInfo topo; > =20 > if (dev->realized) { > error_setg(errp, "Attempt to set property '%s' on '%s' after " > @@ -1722,6 +1723,19 @@ static void x86_cpuid_set_apic_id(Object *obj, V= isitor *v, void *opaque, > return; > } > =20 > + if (value > x86_cpu_apic_id_from_index(max_cpus - 1)) { > + error_setg(errp, "CPU with APIC ID %" PRIi64 > + " is more than MAX APIC ID limits", value); > + return; > + } > + > + x86_topo_ids_from_apic_id(smp_cores, smp_threads, value, &topo); > + if (topo.smt_id >=3D smp_threads || topo.core_id >=3D smp_cores) { > + error_setg(errp, "CPU with APIC ID %" PRIi64 " does not match = " > + "topology configuration.", value); > + return; > + } > + > if ((value !=3D cpu->env.cpuid_apic_id) && cpu_exists(value)) { > error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value)= ; > return; > @@ -2166,8 +2180,10 @@ static void x86_cpu_cpudef_class_init(ObjectClas= s *oc, void *data) > { > X86CPUDefinition *cpudef =3D data; > X86CPUClass *xcc =3D X86_CPU_CLASS(oc); > + DeviceClass *dc =3D DEVICE_CLASS(oc); > =20 > xcc->cpu_def =3D cpudef; > + dc->cannot_instantiate_with_device_add_yet =3D false; > } > =20 > static void x86_register_cpudef_type(X86CPUDefinition *def) > @@ -2176,6 +2192,7 @@ static void x86_register_cpudef_type(X86CPUDefini= tion *def) > TypeInfo ti =3D { > .name =3D typename, > .parent =3D TYPE_X86_CPU, > + .instance_size =3D sizeof(X86CPU), > .class_init =3D x86_cpu_cpudef_class_init, > .class_data =3D def, > }; > @@ -2709,11 +2726,28 @@ static void mce_init(X86CPU *cpu) > } > =20 > #ifndef CONFIG_USER_ONLY > +static uint32_t get_free_apic_id(void) > +{ > + int i; > + > + for (i =3D 0; i < max_cpus; i++) { > + uint32_t id =3D x86_cpu_apic_id_from_index(i); > + > + if (!cpu_exists(id)) { > + return id; > + } > + } > + > + return x86_cpu_apic_id_from_index(max_cpus); > +} > + > +#define APIC_ID_NOT_SET (~0U) This is inside CONFIG_USER_ONLY... > + [...] > @@ -2920,7 +2962,7 @@ static void x86_cpu_initfn(Object *obj) > NULL, NULL, (void *)cpu->filtered_features, NU= LL); > =20 > cpu->hyperv_spinlock_attempts =3D HYPERV_SPINLOCK_NEVER_RETRY; > - env->cpuid_apic_id =3D x86_cpu_apic_id_from_index(cs->cpu_index); > + env->cpuid_apic_id =3D APIC_ID_NOT_SET; ...but this is not. CC x86_64-linux-user/target-i386/cpu.o /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c: In function =E2=80=98= x86_cpu_initfn=E2=80=99: /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:2964:26: error: =E2=80= =98APIC_ID_NOT_SET=E2=80=99 undeclared (first use in this function) env->cpuid_apic_id =3D APIC_ID_NOT_SET; ^ /home/ehabkost/rh/proj/virt/qemu/target-i386/cpu.c:2964:26: note: each = undeclared identifier is reported only once for each function it appears = in /home/ehabkost/rh/proj/virt/qemu/rules.mak:57: recipe for target 'targe= t-i386/cpu.o' failed make[1]: *** [target-i386/cpu.o] Error 1 Makefile:169: recipe for target 'subdir-x86_64-linux-user' failed make: *** [subdir-x86_64-linux-user] Error 2 Also, this will need to be rebased on top of the APIC ID cleanups from my x86 tree, located at: https://github.com/ehabkost/qemu.git x86 > =20 > x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort); > =20 > --=20 > 1.9.3 >=20 >=20 --=20 Eduardo