[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 11/16] pc: Add 'etc/boot-cpus' fw_cfg file for mac
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL v2 11/16] pc: Add 'etc/boot-cpus' fw_cfg file for machine with more than 255 CPUs |
Date: |
Mon, 24 Oct 2016 17:52:20 -0200 |
From: Igor Mammedov <address@hidden>
Currently firmware uses 1 byte at 0x5F offset in RTC CMOS
to get number of CPUs present at boot. However 1 byte is
not enough to handle more than 255 CPUs. So add a new
fw_cfg file that would allow QEMU to tell it.
For compat reasons add file only for machine types that
support more than 255 CPUs.
Signed-off-by: Igor Mammedov <address@hidden>
Reviewed-by: Eduardo Habkost <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
hw/i386/pc.c | 44 +++++++++++++++++++++++++++++---------------
include/hw/i386/pc.h | 2 ++
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 83ad556..f9f85bf 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1085,17 +1085,6 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int
level)
}
}
-static int pc_present_cpus_count(PCMachineState *pcms)
-{
- int i, boot_cpus = 0;
- for (i = 0; i < pcms->possible_cpus->len; i++) {
- if (pcms->possible_cpus->cpus[i].cpu) {
- boot_cpus++;
- }
- }
- return boot_cpus;
-}
-
static X86CPU *pc_new_cpu(const char *typename, int64_t apic_id,
Error **errp)
{
@@ -1232,6 +1221,19 @@ static void pc_build_feature_control_file(PCMachineState
*pcms)
fw_cfg_add_file(pcms->fw_cfg, "etc/msr_feature_control", val,
sizeof(*val));
}
+static void rtc_set_cpus_count(ISADevice *rtc, uint16_t cpus_count)
+{
+ if (cpus_count > 0xff) {
+ /* If the number of CPUs can't be represented in 8 bits, the
+ * BIOS must use "etc/boot-cpus". Set RTC field to 0 just
+ * to make old BIOSes fail more predictably.
+ */
+ rtc_set_memory(rtc, 0x5f, 0);
+ } else {
+ rtc_set_memory(rtc, 0x5f, cpus_count - 1);
+ }
+}
+
static
void pc_machine_done(Notifier *notifier, void *data)
{
@@ -1240,7 +1242,7 @@ void pc_machine_done(Notifier *notifier, void *data)
PCIBus *bus = pcms->bus;
/* set the number of CPUs */
- rtc_set_memory(pcms->rtc, 0x5f, pc_present_cpus_count(pcms) - 1);
+ rtc_set_cpus_count(pcms->rtc, le16_to_cpu(pcms->boot_cpus_le));
if (bus) {
int extra_hosts = 0;
@@ -1261,8 +1263,15 @@ void pc_machine_done(Notifier *notifier, void *data)
acpi_setup();
if (pcms->fw_cfg) {
+ MachineClass *mc = MACHINE_GET_CLASS(pcms);
+
pc_build_smbios(pcms->fw_cfg);
pc_build_feature_control_file(pcms);
+
+ if (mc->max_cpus > 255) {
+ fw_cfg_add_file(pcms->fw_cfg, "etc/boot-cpus", &pcms->boot_cpus_le,
+ sizeof(pcms->boot_cpus_le));
+ }
}
}
@@ -1786,9 +1795,11 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
}
}
+ /* increment the number of CPUs */
+ pcms->boot_cpus_le = cpu_to_le16(le16_to_cpu(pcms->boot_cpus_le) + 1);
if (dev->hotplugged) {
- /* increment the number of CPUs */
- rtc_set_memory(pcms->rtc, 0x5f, rtc_get_memory(pcms->rtc, 0x5f) + 1);
+ /* Update the number of CPUs in CMOS */
+ rtc_set_cpus_count(pcms->rtc, le16_to_cpu(pcms->boot_cpus_le));
}
found_cpu = pc_find_cpu_slot(pcms, CPU(dev), NULL);
@@ -1842,7 +1853,10 @@ static void pc_cpu_unplug_cb(HotplugHandler *hotplug_dev,
found_cpu->cpu = NULL;
object_unparent(OBJECT(dev));
- rtc_set_memory(pcms->rtc, 0x5f, rtc_get_memory(pcms->rtc, 0x5f) - 1);
+ /* decrement the number of CPUs */
+ pcms->boot_cpus_le = cpu_to_le16(le16_to_cpu(pcms->boot_cpus_le) - 1);
+ /* Update the number of CPUs in CMOS */
+ rtc_set_cpus_count(pcms->rtc, le16_to_cpu(pcms->boot_cpus_le));
out:
error_propagate(errp, local_err);
}
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b16c448..17fff80 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -37,6 +37,7 @@
/**
* PCMachineState:
* @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
+ * @boot_cpus_le: number of present VCPUs, referenced by 'etc/boot-cpus' fw_cfg
*/
struct PCMachineState {
/*< private >*/
@@ -69,6 +70,7 @@ struct PCMachineState {
bool apic_xrupt_override;
unsigned apic_id_limit;
CPUArchIdList *possible_cpus;
+ uint16_t boot_cpus_le;
/* NUMA information: */
uint64_t numa_nodes;
--
2.7.4
- [Qemu-devel] [PULL v2 01/16] pc: acpi: x2APIC support for MADT table and _MAT method, (continued)
- [Qemu-devel] [PULL v2 01/16] pc: acpi: x2APIC support for MADT table and _MAT method, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 02/16] pc: acpi: x2APIC support for SRAT table, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 03/16] acpi: cphp: Force switch to modern cpu hotplug if APIC ID > 254, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 04/16] pc: Leave max apic_id_limit only in legacy cpu hotplug code, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 06/16] pc: apic_common: Restore APIC ID to initial ID on reset, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 05/16] pc: apic_common: Extend APIC ID property to 32bit, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 08/16] pc: kvm_apic: Pass APIC ID depending on xAPIC/x2APIC mode, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 07/16] pc: apic_common: Reset APIC ID to initial ID when switching into x2APIC mode, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 09/16] pc: Clarify FW_CFG_MAX_CPUS usage comment, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 10/16] Increase MAX_CPUMASK_BITS from 255 to 288, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 11/16] pc: Add 'etc/boot-cpus' fw_cfg file for machine with more than 255 CPUs,
Eduardo Habkost <=
- [Qemu-devel] [PULL v2 13/16] pc: q35: Bump max_cpus to 288, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 12/16] pc: Require IRQ remapping and EIM if there could be x2APIC CPUs, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 14/16] exec: split cpu_exec_init(), Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 16/16] exec: call cpu_exec_exit() from a CPU unrealize common function, Eduardo Habkost, 2016/10/24
- [Qemu-devel] [PULL v2 15/16] exec: move cpu_exec_init() calls to realize functions, Eduardo Habkost, 2016/10/24
- Re: [Qemu-devel] [PULL v2 00/16] x86 and CPU queue, 2016-10-24, Peter Maydell, 2016/10/25