Received: from eggs.gnu.org ([2001:4830:134:3::10]:58333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya6D1-0001hK-U4 for qemu-devel@nongnu.org; Mon, 23 Mar 2015 13:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ya6Cu-0005OH-Be for qemu-devel@nongnu.org; Mon, 23 Mar 2015 13:32:14 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52967 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya6Cu-0005Nn-29 for qemu-devel@nongnu.org; Mon, 23 Mar 2015 13:32:08 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 23 Mar 2015 18:32:03 +0100 Message-Id: <1427131923-4670-5-git-send-email-afaerber@suse.de> In-Reply-To: <1427131923-4670-1-git-send-email-afaerber@suse.de> References: <1427131923-4670-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH RFC 4/4] pc: Create initial CPUs in-place List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Inline pc_new_cpu() for the initial setup. Signed-off-by: Andreas F=C3=A4rber --- hw/i386/pc.c | 39 ++++++++++++++++++++++++++++++++++----- include/hw/i386/cpu-core.h | 3 +++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 492c262..efc5a23 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -995,13 +995,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, i= nt level) =20 static inline size_t pc_cpu_core_size(void) { - return sizeof(X86CPUCore); + return sizeof(X86CPUCore) + smp_threads * sizeof(X86CPU); } =20 static inline X86CPUCore *pc_cpu_socket_get_core(X86CPUSocket *socket, unsigned int index) { - return &socket->core[index]; + return (void *)&socket->core[0] + index * pc_cpu_core_size(); } =20 static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id, @@ -1083,7 +1083,12 @@ void pc_cpus_init(const char *cpu_model, DeviceSta= te *icc_bridge) X86CPUSocket *socket; X86CPUCore *core; X86CPU *cpu =3D NULL; + X86CPUClass *xcc; + CPUClass *cc; + ObjectClass *cpu_oc; Error *error =3D NULL; + gchar **cpu_model_pieces; + char *cpu_name, *cpu_features; unsigned long apic_id_limit; int sockets, cpu_index =3D 0; =20 @@ -1096,6 +1101,23 @@ void pc_cpus_init(const char *cpu_model, DeviceSta= te *icc_bridge) #endif } current_cpu_model =3D cpu_model; + cpu_model_pieces =3D g_strsplit(cpu_model, ",", 2); + cpu_name =3D cpu_model_pieces[0]; + assert(cpu_name); + cpu_features =3D cpu_model_pieces[1]; + + cpu_oc =3D cpu_class_by_name(TYPE_X86_CPU, cpu_name); + if (cpu_oc =3D=3D NULL) { + error_report("Unable to find CPU definition: %s", cpu_name); + exit(1); + } + cc =3D CPU_CLASS(cpu_oc); + xcc =3D X86_CPU_CLASS(cpu_oc); + + if (xcc->kvm_required && !kvm_enabled()) { + error_report("CPU model '%s' requires KVM", cpu_name); + exit(1); + } =20 apic_id_limit =3D pc_apic_id_limit(max_cpus); if (apic_id_limit > ACPI_CPU_HOTPLUG_ID_LIMIT) { @@ -1120,12 +1142,18 @@ void pc_cpus_init(const char *cpu_model, DeviceSt= ate *icc_bridge) } =20 for (k =3D 0; k < smp_threads; k++) { - cpu =3D pc_new_cpu(cpu_model, - x86_cpu_apic_id_from_index(cpu_index), - icc_bridge, &error); + cpu =3D &core->thread[k]; + object_initialize(cpu, sizeof(*cpu), + object_class_get_name(cpu_oc)); + cc->parse_features(CPU(cpu), cpu_features, &error); if (error) { goto error; } + qdev_set_parent_bus(DEVICE(cpu), + qdev_get_child_bus(icc_bridge, "icc"= )); + object_property_set_int(OBJECT(cpu), + x86_cpu_apic_id_from_index(cpu_i= ndex), + "apic-id", &error); object_property_add_child(OBJECT(core), "thread[*]", OBJECT(cpu), &error); object_unref(OBJECT(cpu)); @@ -1152,6 +1180,7 @@ void pc_cpus_init(const char *cpu_model, DeviceStat= e *icc_bridge) smbios_set_cpuid(cpu->env.cpuid_version, cpu->env.features[FEAT_1_ED= X]); =20 error: + g_strfreev(cpu_model_pieces); if (error) { error_report_err(error); exit(1); diff --git a/include/hw/i386/cpu-core.h b/include/hw/i386/cpu-core.h index be78f95..bb60e8e 100644 --- a/include/hw/i386/cpu-core.h +++ b/include/hw/i386/cpu-core.h @@ -7,6 +7,7 @@ #define HW_I386_CPU_CORE_H =20 #include "hw/qdev.h" +#include "cpu.h" =20 #ifdef TARGET_X86_64 #define TYPE_X86_CPU_CORE "x86_64-cpu-core" @@ -21,6 +22,8 @@ typedef struct X86CPUCore { /*< private >*/ DeviceState parent_obj; /*< public >*/ + + X86CPU thread[0]; } X86CPUCore; =20 #endif --=20 2.1.4