All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Marcel Apfelbaum <marcel@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 34/53] machine: introduce MachineClass.possible_cpu_arch_ids() hook
Date: Fri, 11 Mar 2016 17:09:28 +0200	[thread overview]
Message-ID: <1457708548-14093-35-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1457708548-14093-1-git-send-email-mst@redhat.com>

From: Igor Mammedov <imammedo@redhat.com>

on x86 currently range 0..max_cpus is used to generate
architecture-dependent CPU ID (APIC Id) for each present
and possible CPUs. However architecture-dependent CPU IDs
list could be sparse and code that needs to enumerate
all IDs (ACPI) ended up doing guess work enumerating all
possible and impossible IDs up to
  apic_id_limit = x86_cpu_apic_id_from_index(max_cpus).

That leads to creation of MADT entries and Processor
objects in ACPI tables for not possible CPUs.
Fix it by allowing board specify a concrete list of
CPU IDs accourding its own rules (which for x86 depends
on topology). So that code that needs this list could
request it from board instead of trying to guess
what IDs are correct on its own.

This interface will also allow to help making AML
part of CPU hotplug target independent so it could
be reused for ARM target.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
---
 include/hw/boards.h  | 26 ++++++++++++++++++++++++++
 include/hw/i386/pc.h |  1 +
 hw/i386/pc.c         | 44 ++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index b5d7eae..4b3fdbe 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -8,6 +8,7 @@
 #include "sysemu/accel.h"
 #include "hw/qdev.h"
 #include "qom/object.h"
+#include "qom/cpu.h"
 
 void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
                                           const char *name,
@@ -42,6 +43,26 @@ bool machine_dump_guest_core(MachineState *machine);
 bool machine_mem_merge(MachineState *machine);
 
 /**
+ * CPUArchId:
+ * @arch_id - architecture-dependent CPU ID of present or possible CPU
+ * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
+ */
+typedef struct {
+    uint64_t arch_id;
+    struct CPUState *cpu;
+} CPUArchId;
+
+/**
+ * CPUArchIdList:
+ * @len - number of @CPUArchId items in @cpus array
+ * @cpus - array of present or possible CPUs for current machine configuration
+ */
+typedef struct {
+    int len;
+    CPUArchId cpus[0];
+} CPUArchIdList;
+
+/**
  * MachineClass:
  * @get_hotplug_handler: this function is called during bus-less
  *    device hotplug. If defined it returns pointer to an instance
@@ -57,6 +78,10 @@ bool machine_mem_merge(MachineState *machine);
  *    Set only by old machines because they need to keep
  *    compatibility on code that exposed QEMU_VERSION to guests in
  *    the past (and now use qemu_hw_version()).
+ * @possible_cpu_arch_ids:
+ *    Returns an array of @CPUArchId architecture-dependent CPU IDs
+ *    which includes CPU IDs for present and possible to hotplug CPUs.
+ *    Caller is responsible for freeing returned list.
  */
 struct MachineClass {
     /*< private >*/
@@ -98,6 +123,7 @@ struct MachineClass {
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
     unsigned (*cpu_index_to_socket_id)(unsigned cpu_index);
+    CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
 };
 
 /**
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b049776..8c2bf7f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -67,6 +67,7 @@ struct PCMachineState {
     /* CPU and apic information: */
     bool apic_xrupt_override;
     unsigned apic_id_limit;
+    CPUArchIdList *possible_cpus;
 
     /* NUMA information: */
     uint64_t numa_nodes;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a469979..2ac97c4 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1131,10 +1131,17 @@ void pc_cpus_init(PCMachineState *pcms)
         exit(1);
     }
 
-    for (i = 0; i < smp_cpus; i++) {
-        cpu = pc_new_cpu(machine->cpu_model, x86_cpu_apic_id_from_index(i),
-                         &error_fatal);
-        object_unref(OBJECT(cpu));
+    pcms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
+                                    sizeof(CPUArchId) * max_cpus);
+    for (i = 0; i < max_cpus; i++) {
+        pcms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(i);
+        pcms->possible_cpus->len++;
+        if (i < smp_cpus) {
+            cpu = pc_new_cpu(machine->cpu_model, x86_cpu_apic_id_from_index(i),
+                             &error_fatal);
+            pcms->possible_cpus->cpus[i].cpu = CPU(cpu);
+            object_unref(OBJECT(cpu));
+        }
     }
 
     /* tell smbios about cpuid version and features */
@@ -1657,9 +1664,19 @@ static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
     error_propagate(errp, local_err);
 }
 
+static int pc_apic_cmp(const void *a, const void *b)
+{
+   CPUArchId *apic_a = (CPUArchId *)a;
+   CPUArchId *apic_b = (CPUArchId *)b;
+
+   return apic_a->arch_id - apic_b->arch_id;
+}
+
 static void pc_cpu_plug(HotplugHandler *hotplug_dev,
                         DeviceState *dev, Error **errp)
 {
+    CPUClass *cc = CPU_GET_CLASS(dev);
+    CPUArchId apic_id, *found_cpu;
     HotplugHandlerClass *hhc;
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
@@ -1682,6 +1699,13 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
     /* increment the number of CPUs */
     rtc_set_memory(pcms->rtc, 0x5f, rtc_get_memory(pcms->rtc, 0x5f) + 1);
+
+    apic_id.arch_id = cc->get_arch_id(CPU(dev));
+    found_cpu = bsearch(&apic_id, pcms->possible_cpus->cpus,
+        pcms->possible_cpus->len, sizeof(*pcms->possible_cpus->cpus),
+        pc_apic_cmp);
+    assert(found_cpu);
+    found_cpu->cpu = CPU(dev);
 out:
     error_propagate(errp, local_err);
 }
@@ -1924,6 +1948,17 @@ static unsigned pc_cpu_index_to_socket_id(unsigned cpu_index)
     return topo.pkg_id;
 }
 
+static CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *machine)
+{
+    PCMachineState *pcms = PC_MACHINE(machine);
+    int len = sizeof(CPUArchIdList) +
+              sizeof(CPUArchId) * (pcms->possible_cpus->len);
+    CPUArchIdList *list = g_malloc(len);
+
+    memcpy(list, pcms->possible_cpus, len);
+    return list;
+}
+
 static void pc_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -1946,6 +1981,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->save_tsc_khz = true;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->cpu_index_to_socket_id = pc_cpu_index_to_socket_id;
+    mc->possible_cpu_arch_ids = pc_possible_cpu_arch_ids;
     mc->default_boot_order = "cad";
     mc->hot_add_cpu = pc_hot_add_cpu;
     mc->max_cpus = 255;
-- 
MST

  parent reply	other threads:[~2016-03-11 15:09 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-11 15:07 [Qemu-devel] [PULL 00/53] vhost, virtio, pci, pc, acpi Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 01/53] acpi: add aml_create_field() Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 02/53] acpi: add aml_concatenate() Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 03/53] acpi: allow using object as offset for OperationRegion Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 04/53] acpi: add build_append_named_dword, returning an offset in buffer Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 05/53] balloon: fix segfault and harden the stats queue Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 06/53] hw/virtio: fix double use of a virtio flag Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 07/53] hw/virtio: group virtio flags into an enum Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 08/53] virtio-balloon: add 'available' counter Michael S. Tsirkin
2016-03-11 15:07 ` [Qemu-devel] [PULL 09/53] vhost-user: verify that number of queues is less than MAX_QUEUE_NUM Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 10/53] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy() Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 11/53] i386/acpi: make floppy controller object dynamic Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 12/53] i386: expose floppy drive CMOS type Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 13/53] fdc: add function to determine drive chs limits Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 14/53] i386: populate floppy drive information in DSDT Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 15/53] i386: update expected DSDT Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 16/53] virtio-pci: call pci reset variant when guest requests reset Michael S. Tsirkin
2016-03-14  1:36   ` Laszlo Ersek
2016-03-14  1:45     ` Laszlo Ersek
2016-03-11 15:08 ` [Qemu-devel] [PULL 17/53] msi_supported -> msi_nonbroken Michael S. Tsirkin
2016-03-11 15:08   ` Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 18/53] ich9lpc: fix typo Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 19/53] hw/acpi: fix Q35 support for legacy Windows OS Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 20/53] acpi-test-data: add _DIS methods Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 21/53] pci-ids: add virtio 1.0 ids to spec Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 22/53] nvdimm acpi: initialize the resource used by NVDIMM ACPI Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 23/53] nvdimm acpi: introduce patched dsm memory Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 24/53] nvdimm acpi: let qemu handle _DSM method Michael S. Tsirkin
2016-03-11 15:08 ` [Qemu-devel] [PULL 25/53] nvdimm acpi: emulate dsm method Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 26/53] vhost-user: fix use after free Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 27/53] vhost-user: remove useless is_server field Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 28/53] qemu-char: avoid potential double-free Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 29/53] qemu-char: remove all msgfds on disconnect Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 30/53] qemu-char: make tcp_chr_disconnect() reentrant-safe Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 31/53] pxb: cleanup Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 32/53] pc: acpi: remove NOP assignment Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 33/53] pc: init pcms->apic_id_limit once and use it throughout pc.c Michael S. Tsirkin
2016-03-11 15:09 ` Michael S. Tsirkin [this message]
2016-03-11 15:09 ` [Qemu-devel] [PULL 35/53] pc: acpi: cleanup qdev_get_machine() calls Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 36/53] pc: acpi: SRAT: create only valid processor lapic entries Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 37/53] pc: acpi: create MADT.lapic entries only for valid lapics Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 38/53] pc: acpi: create Processor and Notify objects " Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 39/53] pc: acpi: drop cpu->found_cpus bitmap Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 40/53] pc: acpi: clarify why possible LAPIC entries must be present in MADT Michael S. Tsirkin
2016-03-11 15:09 ` [Qemu-devel] [PULL 41/53] MAINTAINERS: Add an entry for virtio header files Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 42/53] MAINTAINERS: machine core Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 43/53] ipmi: remove IPMI_CHECK_CMD_LEN() macro Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 44/53] ipmi: replace IPMI_ADD_RSP_DATA() macro with inline helpers Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 45/53] ipmi: remove IPMI_CHECK_RESERVATION() macro Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 46/53] ipmi: add rsp_buffer_set_error() helper Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 47/53] ipmi: add a realize function to the device class Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 48/53] ipmi: use a function to initialize the SDR table Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 49/53] ipmi: remove the need of an ending record in " Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 50/53] ipmi: add some local variables in ipmi_sdr_init Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 51/53] ipmi: use a file to load SDRs Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 52/53] ipmi: provide support for FRUs Michael S. Tsirkin
2016-03-11 15:10 ` [Qemu-devel] [PULL 53/53] fw-cfg: support writeable blobs Michael S. Tsirkin
2016-03-14 15:10 ` [Qemu-devel] [PULL 00/53] vhost, virtio, pci, pc, acpi Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457708548-14093-35-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=marcel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.