On Tue, Feb 25, 2014 at 05:07:32PM +0800, Chen Fan wrote: > Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com> > --- > hw/i386/pc.c | 40 ++++++++++++++++++++++++++++++++++++---- > 1 file changed, 36 insertions(+), 4 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 348b15f..4e07ef9 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -57,6 +57,7 @@ > #include "hw/boards.h" > #include "hw/pci/pci_host.h" > #include "acpi-build.h" > +#include "qom/node.h" > > /* debug PC/ISA interrupts */ > //#define DEBUG_IRQ > @@ -927,11 +928,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int > level) > } > } > > -static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id, > +static X86CPU *pc_new_cpu(const char *cpu_model, int64_t id, > DeviceState *icc_bridge, Error **errp)
What about "decoding" the CPU index as soon as possible, and making this function get the full CPU "location", instead of adding more CPU-index-based logic to the rest of the code? > { > X86CPU *cpu; > Error *local_err = NULL; > + Object *thread; > + int64_t apic_id = x86_cpu_apic_id_from_index(id); > > cpu = cpu_x86_create(cpu_model, icc_bridge, &local_err); > if (local_err != NULL) { > @@ -942,11 +945,17 @@ static X86CPU *pc_new_cpu(const char *cpu_model, > int64_t apic_id, > object_property_set_int(OBJECT(cpu), apic_id, "apic-id", &local_err); > object_property_set_bool(OBJECT(cpu), true, "realized", &local_err); > > + thread = object_get_thread_from_index(id); If you just separate the topo_ids_from_idx() and topo_make_apicid() calls, the IDs calculated by topo_ids_from_idx() will be useful for two things: 1) QOM object path construction; and 2) APIC ID calculation (topo_make_apicid()), and you won't even need to implement object_get_thread_from_index(). (...except when compat_apic_id_mode bug-compatibility is enabled. In this case, either the APIC IDs won't match the QOM hierarchy, or we will present a QOM hierarchy different from the one requested by the user.) By the way: a hierarchical node/socket/core/thread abstraction will probably break with current NUMA command-lines that are working. e.g.: $ qemu-system-x86_64 -smp 8,cores=2,threads=2 \ -numa node,cpus=0-2 \ -numa node,cpus=3-5 \ -numa node,cpus=6-7 The above command-line makes threads on the same socket/core appear on different NUMA nodes. Do we want to keep this (weird) topology configuration working? > + if (thread) { > + object_property_set_link(thread, OBJECT(cpu), "cpu", &local_err); > + } > + > if (local_err) { > error_propagate(errp, local_err); > object_unref(OBJECT(cpu)); > cpu = NULL; > } > + > return cpu; > } > > @@ -976,7 +985,29 @@ void pc_hot_add_cpu(const int64_t id, Error **errp) > > icc_bridge = DEVICE(object_resolve_path_type("icc-bridge", > TYPE_ICC_BRIDGE, NULL)); > - pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp); > + pc_new_cpu(current_cpu_model, id, icc_bridge, errp); > +} > + > +static void qdev_cpus_init(void) > +{ > + int i, nodes; > + gchar *node_name; > + Object *obj; > + > + if (nb_numa_nodes) { > + nodes = nb_numa_nodes; > + } else { > + nodes = 1; > + } > + > + for (i = 0; i < nodes; i++) { > + obj = object_new(TYPE_NODE); > + node_name = g_strdup_printf("node[%" PRIi32 "]", i); > + object_property_add_child(qdev_get_machine(), > + node_name, obj, NULL); > + g_free(node_name); > + } > + > } > > void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge) > @@ -995,9 +1026,10 @@ void pc_cpus_init(const char *cpu_model, DeviceState > *icc_bridge) > } > current_cpu_model = cpu_model; > > + qdev_cpus_init(); > + > for (i = 0; i < smp_cpus; i++) { > - cpu = pc_new_cpu(cpu_model, x86_cpu_apic_id_from_index(i), > - icc_bridge, &error); > + cpu = pc_new_cpu(cpu_model, i, icc_bridge, &error); > if (error) { > error_report("%s", error_get_pretty(error)); > error_free(error); > -- > 1.8.1.4 > -- Eduardo