All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [patch 0/2] QEMU maxcpus support
@ 2009-06-23 10:00 Jes Sorensen
  2009-06-23 10:00 ` [Qemu-devel] [patch 1/2] Introduce -maxcpus flag to QEMU and pass the value to the BIOS through FW_CFG Jes Sorensen
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-06-23 10:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Avi Kivity

Hi,

This patch set adds the -maxcpus argument to QEMU and provides the
needed patches to the BOCHS patch queue to make the BIOS use it.

Specifying -maxcpus allows the user to cap the limit of possibly cpus
of the system, as opposed to -smp which specifies the number of
running cpus at startup. This allows us to build BIOS tables
accordingly when trying to scale up in size, and it also allows for
the BIOS to build smaller tables when not needed.

I am going to submit a set of patches directly for BOCHS as well
covering the BIOS part, but I am still waiting for my bochs-developers
subscription to be enabled.

Avi asked me to post this both for QEMU and the BIOS part for BOCHS.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [patch 1/2] Introduce -maxcpus flag to QEMU and pass the value to the BIOS through FW_CFG.
  2009-06-23 10:00 [Qemu-devel] [patch 0/2] QEMU maxcpus support Jes Sorensen
@ 2009-06-23 10:00 ` Jes Sorensen
  2009-06-23 10:00 ` [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
  2009-06-23 11:37 ` [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support Avi Kivity
  2 siblings, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-06-23 10:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Avi Kivity

[-- Attachment #1: 0001-qemu-cfg-maxcpus.patch --]
[-- Type: text/plain, Size: 3145 bytes --]

Follow on patch will use it to determine the size of the MADT and
other BIOS tables.

Signed-off-by: Jes Sorensen <jes@sgi.com>

---
 hw/fw_cfg.c     |    1 +
 hw/fw_cfg.h     |    1 +
 qemu-options.hx |    9 +++++++++
 sysemu.h        |    1 +
 vl.c            |    8 ++++++++
 5 files changed, 20 insertions(+)

Index: qemu/hw/fw_cfg.c
===================================================================
--- qemu.orig/hw/fw_cfg.c
+++ qemu/hw/fw_cfg.c
@@ -279,6 +279,7 @@ void *fw_cfg_init(uint32_t ctl_port, uin
     fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
     fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
     fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 
     register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
     qemu_register_reset(fw_cfg_reset, 0, s);
Index: qemu/hw/fw_cfg.h
===================================================================
--- qemu.orig/hw/fw_cfg.h
+++ qemu/hw/fw_cfg.h
@@ -15,6 +15,7 @@
 #define FW_CFG_INITRD_SIZE      0x0b
 #define FW_CFG_BOOT_DEVICE      0x0c
 #define FW_CFG_NUMA             0x0d
+#define FW_CFG_MAX_CPUS         0x0e
 #define FW_CFG_MAX_ENTRY        0x10
 
 #define FW_CFG_WRITE_CHANNEL    0x4000
Index: qemu/qemu-options.hx
===================================================================
--- qemu.orig/qemu-options.hx
+++ qemu/qemu-options.hx
@@ -47,6 +47,15 @@ CPUs are supported. On Sparc32 target, L
 to 4.
 ETEXI
 
+DEF("maxcpus", HAS_ARG, QEMU_OPTION_maxcpus,
+    "-maxcpus n      set maximum number of possibly CPUs to 'n'\n")
+STEXI
+@item -maxcpus @var{n}
+Set the maximum number of possible CPUs to @var(n). @var(n) has to be
+bigger or equal to the value of -smp. If @var(n) is equal to -smp,
+there will be no space for hotplug cpus to be added later.
+ETEXI
+
 DEF("numa", HAS_ARG, QEMU_OPTION_numa,
     "-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]\n")
 STEXI
Index: qemu/sysemu.h
===================================================================
--- qemu.orig/sysemu.h
+++ qemu/sysemu.h
@@ -118,6 +118,7 @@ extern int alt_grab;
 extern int usb_enabled;
 extern int no_virtio_balloon;
 extern int smp_cpus;
+extern int max_cpus;
 extern int cursor_hide;
 extern int graphic_rotate;
 extern int no_quit;
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c
+++ qemu/vl.c
@@ -241,6 +241,7 @@ int rtc_td_hack = 0;
 int usb_enabled = 0;
 int singlestep = 0;
 int smp_cpus = 1;
+int max_cpus = 16;
 const char *vnc_display;
 int acpi_enabled = 1;
 int no_hpet = 0;
@@ -5556,6 +5557,13 @@ int main(int argc, char **argv, char **e
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_maxcpus:
+                max_cpus = atoi(optarg);
+                if ((max_cpus < 1) || (max_cpus > machine->max_cpus)) {
+                    fprintf(stderr, "Invalid number of CPUs\n");
+                    exit(1);
+                }
+                break;
 	    case QEMU_OPTION_vnc:
                 display_type = DT_VNC;
 		vnc_display = optarg;

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-06-23 10:00 [Qemu-devel] [patch 0/2] QEMU maxcpus support Jes Sorensen
  2009-06-23 10:00 ` [Qemu-devel] [patch 1/2] Introduce -maxcpus flag to QEMU and pass the value to the BIOS through FW_CFG Jes Sorensen
@ 2009-06-23 10:00 ` Jes Sorensen
  2009-06-23 11:37 ` [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support Avi Kivity
  2 siblings, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-06-23 10:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Avi Kivity

[-- Attachment #1: 0002-qemu-bios-patches.patch --]
[-- Type: text/plain, Size: 6708 bytes --]

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch |   57 +++++++++++++
 pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch    |  105 ++++++++++++++++++++++++
 pc-bios/bios-pq/series                          |    2 
 3 files changed, 164 insertions(+)

Index: qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
@@ -0,0 +1,57 @@
+Read max_cpus variable from QEMU_CFG. If not provided, use value of
+smp_cpus.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f861f81..f4a6300 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -436,6 +436,7 @@ void delay_ms(int n)
+ }
+ 
+ uint16_t smp_cpus;
++uint16_t max_cpus;
+ uint32_t cpuid_signature;
+ uint32_t cpuid_features;
+ uint32_t cpuid_ext_features;
+@@ -474,6 +475,7 @@ void wrmsr_smp(uint32_t index, uint64_t val)
+ #define QEMU_CFG_ID         0x01
+ #define QEMU_CFG_UUID       0x02
+ #define QEMU_CFG_NUMA       0x0D
++#define QEMU_CFG_MAX_CPUS   0x0E
+ #define QEMU_CFG_ARCH_LOCAL     0x8000
+ #define QEMU_CFG_ACPI_TABLES  (QEMU_CFG_ARCH_LOCAL + 0)
+ #define QEMU_CFG_SMBIOS_ENTRIES  (QEMU_CFG_ARCH_LOCAL + 1)
+@@ -536,6 +538,19 @@ static uint16_t smbios_entries(void)
+     return cnt;
+ }
+ 
++static uint16_t get_max_cpus(void)
++{
++    uint16_t cnt;
++
++    qemu_cfg_select(QEMU_CFG_MAX_CPUS);
++    qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt));
++
++    if (!cnt)
++        cnt = smp_cpus;
++
++    return cnt;
++}
++
+ uint64_t qemu_cfg_get64 (void)
+ {
+     uint64_t ret;
+@@ -1655,6 +1670,11 @@ void acpi_bios_init(void)
+     uint16_t i, external_tables;
+     int nb_numa_nodes;
+ 
++#ifdef BX_QEMU
++    max_cpus = get_max_cpus();
++#else
++    max_cpus = smp_cpus;
++#endif
+     /* reserve memory space for tables */
+ #ifdef BX_USE_EBDA_TABLES
+     ebda_cur_addr = align(ebda_cur_addr, 16);
Index: qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
@@ -0,0 +1,105 @@
+Use max_cpus when building bios tables.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f4a6300..fb4d663 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1155,13 +1155,13 @@ static void mptable_init(void)
+     putstr(&q, "0.1         "); /* vendor id */
+     putle32(&q, 0); /* OEM table ptr */
+     putle16(&q, 0); /* OEM table size */
+-    putle16(&q, smp_cpus + 18); /* entry count */
++    putle16(&q, max_cpus + 18); /* entry count */
+     putle32(&q, 0xfee00000); /* local APIC addr */
+     putle16(&q, 0); /* ext table length */
+     putb(&q, 0); /* ext table checksum */
+     putb(&q, 0); /* reserved */
+ 
+-    for(i = 0; i < smp_cpus; i++) {
++    for(i = 0; i < max_cpus; i++) {
+         putb(&q, 0); /* entry type = processor */
+         putb(&q, i); /* APIC id */
+         putb(&q, 0x11); /* local APIC version number */
+@@ -1188,7 +1188,7 @@ static void mptable_init(void)
+     putstr(&q, "ISA   ");
+ 
+     /* ioapic */
+-    ioapic_id = smp_cpus;
++    ioapic_id = max_cpus;
+     putb(&q, 2); /* entry type = I/O APIC */
+     putb(&q, ioapic_id); /* apic ID */
+     putb(&q, 0x11); /* I/O APIC version number */
+@@ -1588,7 +1588,7 @@ int acpi_build_processor_ssdt(uint8_t *ssdt)
+ {
+     uint8_t *ssdt_ptr = ssdt;
+     int i, length;
+-    int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
++    int acpi_cpus = max_cpus > 0xff ? 0xff : max_cpus;
+ 
+     ssdt_ptr[9] = 0; // checksum;
+     ssdt_ptr += sizeof(struct acpi_table_header);
+@@ -1725,7 +1725,7 @@ void acpi_bios_init(void)
+         addr = (addr + 7) & ~7;
+         srat_addr = addr;
+         srat_size = sizeof(*srat) +
+-            sizeof(struct srat_processor_affinity) * smp_cpus +
++            sizeof(struct srat_processor_affinity) * max_cpus +
+             sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
+         srat = (void *)(addr);
+         addr += srat_size;
+@@ -1738,7 +1738,7 @@ void acpi_bios_init(void)
+     addr = (addr + 7) & ~7;
+     madt_addr = addr;
+     madt_size = sizeof(*madt) +
+-        sizeof(struct madt_processor_apic) * smp_cpus +
++        sizeof(struct madt_processor_apic) * max_cpus +
+ #ifdef BX_QEMU
+         sizeof(struct madt_io_apic) + sizeof(struct madt_int_override);
+ #else
+@@ -1811,7 +1811,7 @@ void acpi_bios_init(void)
+         madt->local_apic_address = cpu_to_le32(0xfee00000);
+         madt->flags = cpu_to_le32(1);
+         apic = (void *)(madt + 1);
+-        for(i=0;i<smp_cpus;i++) {
++        for(i = 0;i < max_cpus; i++) {
+             apic->type = APIC_PROCESSOR;
+             apic->length = sizeof(*apic);
+             apic->processor_id = i;
+@@ -1822,7 +1822,7 @@ void acpi_bios_init(void)
+         io_apic = (void *)apic;
+         io_apic->type = APIC_IO;
+         io_apic->length = sizeof(*io_apic);
+-        io_apic->io_apic_id = smp_cpus;
++        io_apic->io_apic_id = max_cpus;
+         io_apic->address = cpu_to_le32(0xfec00000);
+         io_apic->interrupt = cpu_to_le32(0);
+ #ifdef BX_QEMU
+@@ -1856,7 +1856,7 @@ void acpi_bios_init(void)
+         srat->reserved1=1;
+  
+         core = (void*)(srat + 1);
+-        for (i = 0; i < smp_cpus; ++i) {
++        for (i = 0; i < max_cpus; ++i) {
+              core->type = SRAT_PROCESSOR;
+              core->length = sizeof(*core);
+              core->local_apic_id = i;
+@@ -1864,7 +1864,7 @@ void acpi_bios_init(void)
+              core->proximity_lo = curnode;
+              memset (core->proximity_hi, 0, 3);
+              core->local_sapic_eid = 0;
+-             if (i < smp_cpus)
++             if (i < max_cpus)
+                  core->flags = cpu_to_le32(1);
+              else
+                  core->flags = 0;
+@@ -2614,7 +2614,7 @@ void smbios_init(void)
+     add_struct(0, p);
+     add_struct(1, p);
+     add_struct(3, p);
+-    for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
++    for (cpu_num = 1; cpu_num <= max_cpus; cpu_num++)
+         add_struct(4, p, cpu_num);
+ 
+     /* Each 'memory device' covers up to 16GB of address space. */
Index: qemu/pc-bios/bios-pq/series
===================================================================
--- qemu.orig/pc-bios/bios-pq/series
+++ qemu/pc-bios/bios-pq/series
@@ -14,3 +14,5 @@
 0014_add-srat-acpi-table-support.patch
 0015_enable-power-button-even-generation.patch
 0016-use-correct-mask-to-size-pci-option-rom-bar.patch
+0017-qemu-kvm-cfg-maxcpus.patch
+0018-qemu-madt-maxcpus.patch

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 10:00 [Qemu-devel] [patch 0/2] QEMU maxcpus support Jes Sorensen
  2009-06-23 10:00 ` [Qemu-devel] [patch 1/2] Introduce -maxcpus flag to QEMU and pass the value to the BIOS through FW_CFG Jes Sorensen
  2009-06-23 10:00 ` [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
@ 2009-06-23 11:37 ` Avi Kivity
  2009-06-23 13:32   ` Jes Sorensen
  2 siblings, 1 reply; 24+ messages in thread
From: Avi Kivity @ 2009-06-23 11:37 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, qemu-devel

On 06/23/2009 01:00 PM, Jes Sorensen wrote:
> Hi,
>
> This patch set adds the -maxcpus argument to QEMU and provides the
> needed patches to the BOCHS patch queue to make the BIOS use it.
>
> Specifying -maxcpus allows the user to cap the limit of possibly cpus
> of the system, as opposed to -smp which specifies the number of
> running cpus at startup. This allows us to build BIOS tables
> accordingly when trying to scale up in size, and it also allows for
> the BIOS to build smaller tables when not needed.
>
> I am going to submit a set of patches directly for BOCHS as well
> covering the BIOS part, but I am still waiting for my bochs-developers
> subscription to be enabled.
>
> Avi asked me to post this both for QEMU and the BIOS part for BOCHS.
>    

I should have said this at your previous post, but it only occurred to 
me now:  we could have -smp 4,maxcpus=65536 instead of a new parameter.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 11:37 ` [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support Avi Kivity
@ 2009-06-23 13:32   ` Jes Sorensen
  2009-06-23 13:36     ` Avi Kivity
  0 siblings, 1 reply; 24+ messages in thread
From: Jes Sorensen @ 2009-06-23 13:32 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, qemu-devel

On 06/23/2009 01:37 PM, Avi Kivity wrote:
> On 06/23/2009 01:00 PM, Jes Sorensen wrote:
>> Avi asked me to post this both for QEMU and the BIOS part for BOCHS.
>
> I should have said this at your previous post, but it only occurred to
> me now: we could have -smp 4,maxcpus=65536 instead of a new parameter.
>

We could do that too, but is it really worth it? It seems to me -maxcpus
is fine?

Cheers,
Jes

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 13:32   ` Jes Sorensen
@ 2009-06-23 13:36     ` Avi Kivity
  2009-06-23 15:07       ` Jes Sorensen
  0 siblings, 1 reply; 24+ messages in thread
From: Avi Kivity @ 2009-06-23 13:36 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, qemu-devel

On 06/23/2009 04:32 PM, Jes Sorensen wrote:
>> I should have said this at your previous post, but it only occurred to
>> me now: we could have -smp 4,maxcpus=65536 instead of a new parameter.
>>
>
>
> We could do that too, but is it really worth it? It seems to me -maxcpus
> is fine?

The trend is to consolidate related options into a single option, -to 
-avoid -command -lines -with -too -many -dashes.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 13:36     ` Avi Kivity
@ 2009-06-23 15:07       ` Jes Sorensen
  2009-06-23 15:47         ` Avi Kivity
  0 siblings, 1 reply; 24+ messages in thread
From: Jes Sorensen @ 2009-06-23 15:07 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

On 06/23/2009 03:36 PM, Avi Kivity wrote:
> On 06/23/2009 04:32 PM, Jes Sorensen wrote:
>>> I should have said this at your previous post, but it only occurred to
>>> me now: we could have -smp 4,maxcpus=65536 instead of a new parameter.
>>
>> We could do that too, but is it really worth it? It seems to me -maxcpus
>> is fine?
>
> The trend is to consolidate related options into a single option, -to
> -avoid -command -lines -with -too -many -dashes.

Ok, so how about this then?

Jes


[-- Attachment #2: 0001-qemu-cfg-maxcpus.patch --]
[-- Type: text/x-patch, Size: 3847 bytes --]

Introduce -smp ,maxcpus= flag to specify maximum number of CPUS.

Follow on patch will use it to determine the size of the MADT and
other BIOS tables.

Signed-off-by: Jes Sorensen <jes@sgi.com>

---
 hw/fw_cfg.c     |    1 +
 hw/fw_cfg.h     |    1 +
 qemu-options.hx |    5 ++++-
 sysemu.h        |    1 +
 vl.c            |   20 +++++++++++++++++++-
 5 files changed, 26 insertions(+), 2 deletions(-)

Index: qemu/hw/fw_cfg.c
===================================================================
--- qemu.orig/hw/fw_cfg.c
+++ qemu/hw/fw_cfg.c
@@ -279,6 +279,7 @@ void *fw_cfg_init(uint32_t ctl_port, uin
     fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
     fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
     fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
+    fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 
     register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
     qemu_register_reset(fw_cfg_reset, 0, s);
Index: qemu/hw/fw_cfg.h
===================================================================
--- qemu.orig/hw/fw_cfg.h
+++ qemu/hw/fw_cfg.h
@@ -15,6 +15,7 @@
 #define FW_CFG_INITRD_SIZE      0x0b
 #define FW_CFG_BOOT_DEVICE      0x0c
 #define FW_CFG_NUMA             0x0d
+#define FW_CFG_MAX_CPUS         0x0e
 #define FW_CFG_MAX_ENTRY        0x10
 
 #define FW_CFG_WRITE_CHANNEL    0x4000
Index: qemu/qemu-options.hx
===================================================================
--- qemu.orig/qemu-options.hx
+++ qemu/qemu-options.hx
@@ -39,7 +39,10 @@ Select CPU model (-cpu ? for list and ad
 ETEXI
 
 DEF("smp", HAS_ARG, QEMU_OPTION_smp,
-    "-smp n          set the number of CPUs to 'n' [default=1]\n")
+    "-smp n,[maxcpus=cpus]\n"
+    "                set the number of CPUs to 'n' [default=1]\n"
+    "                maxcpus= maximum number of total cpus, including\n"
+    "                offline CPUs for hotplug etc.\n")
 STEXI
 @item -smp @var{n}
 Simulate an SMP system with @var{n} CPUs. On the PC target, up to 255
Index: qemu/sysemu.h
===================================================================
--- qemu.orig/sysemu.h
+++ qemu/sysemu.h
@@ -118,6 +118,7 @@ extern int alt_grab;
 extern int usb_enabled;
 extern int no_virtio_balloon;
 extern int smp_cpus;
+extern int max_cpus;
 extern int cursor_hide;
 extern int graphic_rotate;
 extern int no_quit;
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c
+++ qemu/vl.c
@@ -241,6 +241,7 @@ int rtc_td_hack = 0;
 int usb_enabled = 0;
 int singlestep = 0;
 int smp_cpus = 1;
+int max_cpus = 16;
 const char *vnc_display;
 int acpi_enabled = 1;
 int no_hpet = 0;
@@ -5550,12 +5551,29 @@ int main(int argc, char **argv, char **e
                 usb_devices_index++;
                 break;
             case QEMU_OPTION_smp:
-                smp_cpus = atoi(optarg);
+            {
+                char *p;
+                char option[128];
+                smp_cpus = strtol(optarg, &p, 10);
                 if (smp_cpus < 1) {
                     fprintf(stderr, "Invalid number of CPUs\n");
                     exit(1);
                 }
+                if (*p++ != ',')
+                    break;
+                if (get_param_value(option, 128, "maxcpus", p))
+                    max_cpus = strtol(option, NULL, 0);
+                if (max_cpus < smp_cpus) {
+                    fprintf(stderr, "maxcpus must be equal to or greater than "
+                            "smp\n");
+                    exit(1);
+                }
+                if (max_cpus > 255) {
+                    fprintf(stderr, "Unsupported number of maxcpus\n");
+                    exit(1);
+                }
                 break;
+            }
 	    case QEMU_OPTION_vnc:
                 display_type = DT_VNC;
 		vnc_display = optarg;

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 15:07       ` Jes Sorensen
@ 2009-06-23 15:47         ` Avi Kivity
  2009-06-24  7:16           ` Jes Sorensen
  0 siblings, 1 reply; 24+ messages in thread
From: Avi Kivity @ 2009-06-23 15:47 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, qemu-devel

On 06/23/2009 06:07 PM, Jes Sorensen wrote:
> On 06/23/2009 03:36 PM, Avi Kivity wrote:
>> On 06/23/2009 04:32 PM, Jes Sorensen wrote:
>>>> I should have said this at your previous post, but it only occurred to
>>>> me now: we could have -smp 4,maxcpus=65536 instead of a new parameter.
>>>
>>> We could do that too, but is it really worth it? It seems to me 
>>> -maxcpus
>>> is fine?
>>
>> The trend is to consolidate related options into a single option, -to
>> -avoid -command -lines -with -too -many -dashes.
>
> Ok, so how about this then?
>
>
>   DEF("smp", HAS_ARG, QEMU_OPTION_smp,
> -    "-smp n          set the number of CPUs to 'n' [default=1]\n")
> +    "-smp n,[maxcpus=cpus]\n"
>    

-smp n[,maxcpus=cpus]

> @@ -5550,12 +5551,29 @@ int main(int argc, char **argv, char **e
>                   usb_devices_index++;
>                   break;
>               case QEMU_OPTION_smp:
> -                smp_cpus = atoi(optarg);
> +            {
> +                char *p;
> +                char option[128];
> +                smp_cpus = strtol(optarg,&p, 10);
>                   if (smp_cpus<  1) {
>                       fprintf(stderr, "Invalid number of CPUs\n");
>                       exit(1);
>                   }
> +                if (*p++ != ',')
> +                    break;
>    

Won't this misparse "-smp 17z"?

> +                if (get_param_value(option, 128, "maxcpus", p))
> +                    max_cpus = strtol(option, NULL, 0);
> +                if (max_cpus<  smp_cpus) {
> +                    fprintf(stderr, "maxcpus must be equal to or greater than "
> +                            "smp\n");
> +                    exit(1);
> +                }
> +                if (max_cpus>  255) {
> +                    fprintf(stderr, "Unsupported number of maxcpus\n");
> +                    exit(1);
> +                }
>                   break;
> +            }
>    

We really need a table-driven parser for options.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-23 15:47         ` Avi Kivity
@ 2009-06-24  7:16           ` Jes Sorensen
  2009-06-24  7:25             ` Filip Navara
  0 siblings, 1 reply; 24+ messages in thread
From: Jes Sorensen @ 2009-06-24  7:16 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, qemu-devel

On 06/23/2009 05:47 PM, Avi Kivity wrote:
> On 06/23/2009 06:07 PM, Jes Sorensen wrote:
>> DEF("smp", HAS_ARG, QEMU_OPTION_smp,
>> - "-smp n set the number of CPUs to 'n' [default=1]\n")
>> + "-smp n,[maxcpus=cpus]\n"
>
> -smp n[,maxcpus=cpus]

I don't follow you there, please elaborate.

>> + if (*p++ != ',')
>> + break;
>
> Won't this misparse "-smp 17z"?

It will be parsed as -smp 17, which is consistent with how the rest of
the options are parsed in QEMU. I am not going to rewrite the whole
parser for you :)

Cheers,
Jes

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support
  2009-06-24  7:16           ` Jes Sorensen
@ 2009-06-24  7:25             ` Filip Navara
  0 siblings, 0 replies; 24+ messages in thread
From: Filip Navara @ 2009-06-24  7:25 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, Avi Kivity, qemu-devel

On Wed, Jun 24, 2009 at 9:16 AM, Jes Sorensen<jes@sgi.com> wrote:
> On 06/23/2009 05:47 PM, Avi Kivity wrote:
>>
>> On 06/23/2009 06:07 PM, Jes Sorensen wrote:
>>>
>>> DEF("smp", HAS_ARG, QEMU_OPTION_smp,
>>> - "-smp n set the number of CPUs to 'n' [default=1]\n")
>>> + "-smp n,[maxcpus=cpus]\n"
>>
>> -smp n[,maxcpus=cpus]
>
> I don't follow you there, please elaborate.
>

The comma should be inside the brackets, not outside.

Best regards,
Filip Navara

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-23 15:03 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v4 Jes Sorensen
@ 2009-07-23 15:03 ` Jes Sorensen
  0 siblings, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-07-23 15:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, gleb

[-- Attachment #1: 0002-qemu-bios-patches.patch --]
[-- Type: text/plain, Size: 7054 bytes --]

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch |   62 ++++++++++++
 pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch    |  117 ++++++++++++++++++++++++
 pc-bios/bios-pq/series                          |    2 
 3 files changed, 181 insertions(+)

Index: qemu/pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch
@@ -0,0 +1,62 @@
+Read max_cpus variable from QEMU_CFG. If not provided, use value of
+smp_cpus.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios.h b/bios/rombios.h
+index 8ece2ee..dbf3bd3 100644
+--- a/bios/rombios.h
++++ b/bios/rombios.h
+@@ -65,6 +65,7 @@
+ #define QEMU_CFG_UUID             0x02
+ #define QEMU_CFG_NUMA             0x0d
+ #define QEMU_CFG_BOOT_MENU        0x0e
++#define QEMU_CFG_MAX_CPUS         0x0f
+ #define QEMU_CFG_ARCH_LOCAL       0x8000
+ #define QEMU_CFG_ACPI_TABLES      (QEMU_CFG_ARCH_LOCAL + 0)
+ #define QEMU_CFG_SMBIOS_ENTRIES   (QEMU_CFG_ARCH_LOCAL + 1)
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index 69e82b1..610fc1f 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -436,6 +436,7 @@ void delay_ms(int n)
+ }
+ 
+ uint16_t smp_cpus;
++uint16_t max_cpus;
+ uint32_t cpuid_signature;
+ uint32_t cpuid_features;
+ uint32_t cpuid_ext_features;
+@@ -526,6 +527,19 @@ static uint16_t smbios_entries(void)
+     return cnt;
+ }
+ 
++static uint16_t get_max_cpus(void)
++{
++    uint16_t cnt;
++
++    qemu_cfg_select(QEMU_CFG_MAX_CPUS);
++    qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt));
++
++    if (!cnt)
++        cnt = smp_cpus;
++
++    return cnt;
++}
++
+ uint64_t qemu_cfg_get64 (void)
+ {
+     uint64_t ret;
+@@ -2689,6 +2703,12 @@ void rombios32_init(uint32_t *s3_resume_vector, uint8_t *shutdown_flag)
+ 
+     smp_probe();
+ 
++#ifdef BX_QEMU
++    max_cpus = get_max_cpus();
++#else
++    max_cpus = smp_cpus;
++#endif
++
+     find_bios_table_area();
+ 
+     if (*shutdown_flag == 0xfe) {
Index: qemu/pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch
@@ -0,0 +1,117 @@
+Use max_cpus when building bios tables.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index e6bb164..3d15283 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1145,23 +1145,25 @@ static void mptable_init(void)
+     putle32(&q, 0); /* OEM table ptr */
+     putle16(&q, 0); /* OEM table size */
+ #ifdef BX_QEMU
+-    putle16(&q, smp_cpus + 17); /* entry count */
++    putle16(&q, max_cpus + 17); /* entry count */
+ #else
+-    putle16(&q, smp_cpus + 18); /* entry count */
++    putle16(&q, max_cpus + 18); /* entry count */
+ #endif
+     putle32(&q, 0xfee00000); /* local APIC addr */
+     putle16(&q, 0); /* ext table length */
+     putb(&q, 0); /* ext table checksum */
+     putb(&q, 0); /* reserved */
+ 
+-    for(i = 0; i < smp_cpus; i++) {
++    for(i = 0; i < max_cpus; i++) {
+         putb(&q, 0); /* entry type = processor */
+         putb(&q, i); /* APIC id */
+         putb(&q, 0x11); /* local APIC version number */
+         if (i == 0)
+             putb(&q, 3); /* cpu flags: enabled, bootstrap cpu */
+-        else
++        else if (i < smp_cpus)
+             putb(&q, 1); /* cpu flags: enabled */
++        else
++            putb(&q, 0); /* cpu flags: disabled */
+         putb(&q, 0); /* cpu signature */
+         putb(&q, 6);
+         putb(&q, 0);
+@@ -1181,7 +1183,7 @@ static void mptable_init(void)
+     putstr(&q, "ISA   ");
+ 
+     /* ioapic */
+-    ioapic_id = smp_cpus;
++    ioapic_id = max_cpus;
+     putb(&q, 2); /* entry type = I/O APIC */
+     putb(&q, ioapic_id); /* apic ID */
+     putb(&q, 0x11); /* I/O APIC version number */
+@@ -1581,7 +1583,7 @@ int acpi_build_processor_ssdt(uint8_t *ssdt)
+ {
+     uint8_t *ssdt_ptr = ssdt;
+     int i, length;
+-    int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
++    int acpi_cpus = max_cpus > 0xff ? 0xff : max_cpus;
+ 
+     ssdt_ptr[9] = 0; // checksum;
+     ssdt_ptr += sizeof(struct acpi_table_header);
+@@ -1713,7 +1715,7 @@ void acpi_bios_init(void)
+         addr = (addr + 7) & ~7;
+         srat_addr = addr;
+         srat_size = sizeof(*srat) +
+-            sizeof(struct srat_processor_affinity) * smp_cpus +
++            sizeof(struct srat_processor_affinity) * max_cpus +
+             sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
+         srat = (void *)(addr);
+         addr += srat_size;
+@@ -1726,7 +1728,7 @@ void acpi_bios_init(void)
+     addr = (addr + 7) & ~7;
+     madt_addr = addr;
+     madt_size = sizeof(*madt) +
+-        sizeof(struct madt_processor_apic) * smp_cpus +
++        sizeof(struct madt_processor_apic) * max_cpus +
+ #ifdef BX_QEMU
+         sizeof(struct madt_io_apic) + sizeof(struct madt_int_override);
+ #else
+@@ -1799,18 +1801,21 @@ void acpi_bios_init(void)
+         madt->local_apic_address = cpu_to_le32(0xfee00000);
+         madt->flags = cpu_to_le32(1);
+         apic = (void *)(madt + 1);
+-        for(i=0;i<smp_cpus;i++) {
++        for(i = 0;i < max_cpus; i++) {
+             apic->type = APIC_PROCESSOR;
+             apic->length = sizeof(*apic);
+             apic->processor_id = i;
+             apic->local_apic_id = i;
+-            apic->flags = cpu_to_le32(1);
++            if (i < smp_cpus)
++                apic->flags = cpu_to_le32(1);
++            else
++                apic->flags = 0;
+             apic++;
+         }
+         io_apic = (void *)apic;
+         io_apic->type = APIC_IO;
+         io_apic->length = sizeof(*io_apic);
+-        io_apic->io_apic_id = smp_cpus;
++        io_apic->io_apic_id = max_cpus;
+         io_apic->address = cpu_to_le32(0xfec00000);
+         io_apic->interrupt = cpu_to_le32(0);
+ #ifdef BX_QEMU
+@@ -1844,7 +1849,7 @@ void acpi_bios_init(void)
+         srat->reserved1=1;
+  
+         core = (void*)(srat + 1);
+-        for (i = 0; i < smp_cpus; ++i) {
++        for (i = 0; i < max_cpus; ++i) {
+              core->type = SRAT_PROCESSOR;
+              core->length = sizeof(*core);
+              core->local_apic_id = i;
+@@ -2603,7 +2608,7 @@ void smbios_init(void)
+     add_struct(0, p);
+     add_struct(1, p);
+     add_struct(3, p);
+-    for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
++    for (cpu_num = 1; cpu_num <= max_cpus; cpu_num++)
+         add_struct(4, p, cpu_num);
+ 
+     /* Each 'memory device' covers up to 16GB of address space. */
Index: qemu/pc-bios/bios-pq/series
===================================================================
--- qemu.orig/pc-bios/bios-pq/series
+++ qemu/pc-bios/bios-pq/series
@@ -17,3 +17,5 @@
 0017-bochs-bios-Move-QEMU_CFG-constants-to-rombios.h.patch
 0018-bochs-bios-Make-boot-prompt-optional.patch
 0019-bios-fix-multiple-calls.patch
+0020-qemu-kvm-cfg-maxcpus.patch
+0021-qemu-madt-maxcpus.patch

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-20 14:43 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v3 Jes Sorensen
@ 2009-07-20 14:43 ` Jes Sorensen
  0 siblings, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-07-20 14:43 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

[-- Attachment #1: 0002-qemu-bios-patches.patch --]
[-- Type: text/plain, Size: 6458 bytes --]

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch |   61 +++++++++++++++
 pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch    |   96 ++++++++++++++++++++++++
 pc-bios/bios-pq/series                          |    2 
 3 files changed, 159 insertions(+)

Index: qemu/pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0020-qemu-kvm-cfg-maxcpus.patch
@@ -0,0 +1,61 @@
+Read max_cpus variable from QEMU_CFG. If not provided, use value of
+smp_cpus.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios.h b/bios/rombios.h
+index 8ece2ee..dbf3bd3 100644
+--- a/bios/rombios.h
++++ b/bios/rombios.h
+@@ -65,6 +65,7 @@
+ #define QEMU_CFG_UUID             0x02
+ #define QEMU_CFG_NUMA             0x0d
+ #define QEMU_CFG_BOOT_MENU        0x0e
++#define QEMU_CFG_MAX_CPUS         0x0f
+ #define QEMU_CFG_ARCH_LOCAL       0x8000
+ #define QEMU_CFG_ACPI_TABLES      (QEMU_CFG_ARCH_LOCAL + 0)
+ #define QEMU_CFG_SMBIOS_ENTRIES   (QEMU_CFG_ARCH_LOCAL + 1)
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index 69e82b1..462884a 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -436,6 +436,7 @@ void delay_ms(int n)
+ }
+ 
+ uint16_t smp_cpus;
++uint16_t max_cpus;
+ uint32_t cpuid_signature;
+ uint32_t cpuid_features;
+ uint32_t cpuid_ext_features;
+@@ -526,6 +527,19 @@ static uint16_t smbios_entries(void)
+     return cnt;
+ }
+ 
++static uint16_t get_max_cpus(void)
++{
++    uint16_t cnt;
++
++    qemu_cfg_select(QEMU_CFG_MAX_CPUS);
++    qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt));
++
++    if (!cnt)
++        cnt = smp_cpus;
++
++    return cnt;
++}
++
+ uint64_t qemu_cfg_get64 (void)
+ {
+     uint64_t ret;
+@@ -1645,6 +1659,11 @@ void acpi_bios_init(void)
+     uint16_t i, external_tables;
+     int nb_numa_nodes;
+ 
++#ifdef BX_QEMU
++    max_cpus = get_max_cpus();
++#else
++    max_cpus = smp_cpus;
++#endif
+     /* reserve memory space for tables */
+ #ifdef BX_USE_EBDA_TABLES
+     ebda_cur_addr = align(ebda_cur_addr, 16);
Index: qemu/pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0021-qemu-madt-maxcpus.patch
@@ -0,0 +1,96 @@
+Use max_cpus when building bios tables.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index 462884a..1ec4a09 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1144,13 +1144,13 @@ static void mptable_init(void)
+     putstr(&q, "0.1         "); /* vendor id */
+     putle32(&q, 0); /* OEM table ptr */
+     putle16(&q, 0); /* OEM table size */
+-    putle16(&q, smp_cpus + 18); /* entry count */
++    putle16(&q, max_cpus + 18); /* entry count */
+     putle32(&q, 0xfee00000); /* local APIC addr */
+     putle16(&q, 0); /* ext table length */
+     putb(&q, 0); /* ext table checksum */
+     putb(&q, 0); /* reserved */
+ 
+-    for(i = 0; i < smp_cpus; i++) {
++    for(i = 0; i < max_cpus; i++) {
+         putb(&q, 0); /* entry type = processor */
+         putb(&q, i); /* APIC id */
+         putb(&q, 0x11); /* local APIC version number */
+@@ -1177,7 +1177,7 @@ static void mptable_init(void)
+     putstr(&q, "ISA   ");
+ 
+     /* ioapic */
+-    ioapic_id = smp_cpus;
++    ioapic_id = max_cpus;
+     putb(&q, 2); /* entry type = I/O APIC */
+     putb(&q, ioapic_id); /* apic ID */
+     putb(&q, 0x11); /* I/O APIC version number */
+@@ -1577,7 +1577,7 @@ int acpi_build_processor_ssdt(uint8_t *ssdt)
+ {
+     uint8_t *ssdt_ptr = ssdt;
+     int i, length;
+-    int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
++    int acpi_cpus = max_cpus > 0xff ? 0xff : max_cpus;
+ 
+     ssdt_ptr[9] = 0; // checksum;
+     ssdt_ptr += sizeof(struct acpi_table_header);
+@@ -1714,7 +1714,7 @@ void acpi_bios_init(void)
+         addr = (addr + 7) & ~7;
+         srat_addr = addr;
+         srat_size = sizeof(*srat) +
+-            sizeof(struct srat_processor_affinity) * smp_cpus +
++            sizeof(struct srat_processor_affinity) * max_cpus +
+             sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
+         srat = (void *)(addr);
+         addr += srat_size;
+@@ -1727,7 +1727,7 @@ void acpi_bios_init(void)
+     addr = (addr + 7) & ~7;
+     madt_addr = addr;
+     madt_size = sizeof(*madt) +
+-        sizeof(struct madt_processor_apic) * smp_cpus +
++        sizeof(struct madt_processor_apic) * max_cpus +
+ #ifdef BX_QEMU
+         sizeof(struct madt_io_apic) + sizeof(struct madt_int_override);
+ #else
+@@ -1800,7 +1800,7 @@ void acpi_bios_init(void)
+         madt->local_apic_address = cpu_to_le32(0xfee00000);
+         madt->flags = cpu_to_le32(1);
+         apic = (void *)(madt + 1);
+-        for(i=0;i<smp_cpus;i++) {
++        for(i = 0;i < max_cpus; i++) {
+             apic->type = APIC_PROCESSOR;
+             apic->length = sizeof(*apic);
+             apic->processor_id = i;
+@@ -1811,7 +1811,7 @@ void acpi_bios_init(void)
+         io_apic = (void *)apic;
+         io_apic->type = APIC_IO;
+         io_apic->length = sizeof(*io_apic);
+-        io_apic->io_apic_id = smp_cpus;
++        io_apic->io_apic_id = max_cpus;
+         io_apic->address = cpu_to_le32(0xfec00000);
+         io_apic->interrupt = cpu_to_le32(0);
+ #ifdef BX_QEMU
+@@ -1845,7 +1845,7 @@ void acpi_bios_init(void)
+         srat->reserved1=1;
+  
+         core = (void*)(srat + 1);
+-        for (i = 0; i < smp_cpus; ++i) {
++        for (i = 0; i < max_cpus; ++i) {
+              core->type = SRAT_PROCESSOR;
+              core->length = sizeof(*core);
+              core->local_apic_id = i;
+@@ -2604,7 +2604,7 @@ void smbios_init(void)
+     add_struct(0, p);
+     add_struct(1, p);
+     add_struct(3, p);
+-    for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
++    for (cpu_num = 1; cpu_num <= max_cpus; cpu_num++)
+         add_struct(4, p, cpu_num);
+ 
+     /* Each 'memory device' covers up to 16GB of address space. */
Index: qemu/pc-bios/bios-pq/series
===================================================================
--- qemu.orig/pc-bios/bios-pq/series
+++ qemu/pc-bios/bios-pq/series
@@ -17,3 +17,5 @@
 0017-bochs-bios-Move-QEMU_CFG-constants-to-rombios.h.patch
 0018-bochs-bios-Make-boot-prompt-optional.patch
 0019-bios-fix-multiple-calls.patch
+0020-qemu-kvm-cfg-maxcpus.patch
+0021-qemu-madt-maxcpus.patch

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14 12:53 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v2 Jes Sorensen
@ 2009-07-14 12:53 ` Jes Sorensen
  0 siblings, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-07-14 12:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, filip.navara, Avi Kivity, gleb

[-- Attachment #1: 0002-qemu-bios-patches.patch --]
[-- Type: text/plain, Size: 6351 bytes --]

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch |   57 ++++++++++++++
 pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch    |   96 ++++++++++++++++++++++++
 pc-bios/bios-pq/series                          |    2 
 3 files changed, 155 insertions(+)

Index: qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
@@ -0,0 +1,57 @@
+Read max_cpus variable from QEMU_CFG. If not provided, use value of
+smp_cpus.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f861f81..f4a6300 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -436,6 +436,7 @@ void delay_ms(int n)
+ }
+ 
+ uint16_t smp_cpus;
++uint16_t max_cpus;
+ uint32_t cpuid_signature;
+ uint32_t cpuid_features;
+ uint32_t cpuid_ext_features;
+@@ -474,6 +475,7 @@ void wrmsr_smp(uint32_t index, uint64_t val)
+ #define QEMU_CFG_ID         0x01
+ #define QEMU_CFG_UUID       0x02
+ #define QEMU_CFG_NUMA       0x0D
++#define QEMU_CFG_MAX_CPUS   0x0E
+ #define QEMU_CFG_ARCH_LOCAL     0x8000
+ #define QEMU_CFG_ACPI_TABLES  (QEMU_CFG_ARCH_LOCAL + 0)
+ #define QEMU_CFG_SMBIOS_ENTRIES  (QEMU_CFG_ARCH_LOCAL + 1)
+@@ -536,6 +538,19 @@ static uint16_t smbios_entries(void)
+     return cnt;
+ }
+ 
++static uint16_t get_max_cpus(void)
++{
++    uint16_t cnt;
++
++    qemu_cfg_select(QEMU_CFG_MAX_CPUS);
++    qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt));
++
++    if (!cnt)
++        cnt = smp_cpus;
++
++    return cnt;
++}
++
+ uint64_t qemu_cfg_get64 (void)
+ {
+     uint64_t ret;
+@@ -1655,6 +1670,11 @@ void acpi_bios_init(void)
+     uint16_t i, external_tables;
+     int nb_numa_nodes;
+ 
++#ifdef BX_QEMU
++    max_cpus = get_max_cpus();
++#else
++    max_cpus = smp_cpus;
++#endif
+     /* reserve memory space for tables */
+ #ifdef BX_USE_EBDA_TABLES
+     ebda_cur_addr = align(ebda_cur_addr, 16);
Index: qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
@@ -0,0 +1,96 @@
+Use max_cpus when building bios tables.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f4a6300..c0159be 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1155,13 +1155,13 @@ static void mptable_init(void)
+     putstr(&q, "0.1         "); /* vendor id */
+     putle32(&q, 0); /* OEM table ptr */
+     putle16(&q, 0); /* OEM table size */
+-    putle16(&q, smp_cpus + 18); /* entry count */
++    putle16(&q, max_cpus + 18); /* entry count */
+     putle32(&q, 0xfee00000); /* local APIC addr */
+     putle16(&q, 0); /* ext table length */
+     putb(&q, 0); /* ext table checksum */
+     putb(&q, 0); /* reserved */
+ 
+-    for(i = 0; i < smp_cpus; i++) {
++    for(i = 0; i < max_cpus; i++) {
+         putb(&q, 0); /* entry type = processor */
+         putb(&q, i); /* APIC id */
+         putb(&q, 0x11); /* local APIC version number */
+@@ -1188,7 +1188,7 @@ static void mptable_init(void)
+     putstr(&q, "ISA   ");
+ 
+     /* ioapic */
+-    ioapic_id = smp_cpus;
++    ioapic_id = max_cpus;
+     putb(&q, 2); /* entry type = I/O APIC */
+     putb(&q, ioapic_id); /* apic ID */
+     putb(&q, 0x11); /* I/O APIC version number */
+@@ -1588,7 +1588,7 @@ int acpi_build_processor_ssdt(uint8_t *ssdt)
+ {
+     uint8_t *ssdt_ptr = ssdt;
+     int i, length;
+-    int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
++    int acpi_cpus = max_cpus > 0xff ? 0xff : max_cpus;
+ 
+     ssdt_ptr[9] = 0; // checksum;
+     ssdt_ptr += sizeof(struct acpi_table_header);
+@@ -1725,7 +1725,7 @@ void acpi_bios_init(void)
+         addr = (addr + 7) & ~7;
+         srat_addr = addr;
+         srat_size = sizeof(*srat) +
+-            sizeof(struct srat_processor_affinity) * smp_cpus +
++            sizeof(struct srat_processor_affinity) * max_cpus +
+             sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
+         srat = (void *)(addr);
+         addr += srat_size;
+@@ -1738,7 +1738,7 @@ void acpi_bios_init(void)
+     addr = (addr + 7) & ~7;
+     madt_addr = addr;
+     madt_size = sizeof(*madt) +
+-        sizeof(struct madt_processor_apic) * smp_cpus +
++        sizeof(struct madt_processor_apic) * max_cpus +
+ #ifdef BX_QEMU
+         sizeof(struct madt_io_apic) + sizeof(struct madt_int_override);
+ #else
+@@ -1811,7 +1811,7 @@ void acpi_bios_init(void)
+         madt->local_apic_address = cpu_to_le32(0xfee00000);
+         madt->flags = cpu_to_le32(1);
+         apic = (void *)(madt + 1);
+-        for(i=0;i<smp_cpus;i++) {
++        for(i = 0;i < max_cpus; i++) {
+             apic->type = APIC_PROCESSOR;
+             apic->length = sizeof(*apic);
+             apic->processor_id = i;
+@@ -1822,7 +1822,7 @@ void acpi_bios_init(void)
+         io_apic = (void *)apic;
+         io_apic->type = APIC_IO;
+         io_apic->length = sizeof(*io_apic);
+-        io_apic->io_apic_id = smp_cpus;
++        io_apic->io_apic_id = max_cpus;
+         io_apic->address = cpu_to_le32(0xfec00000);
+         io_apic->interrupt = cpu_to_le32(0);
+ #ifdef BX_QEMU
+@@ -1856,7 +1856,7 @@ void acpi_bios_init(void)
+         srat->reserved1=1;
+  
+         core = (void*)(srat + 1);
+-        for (i = 0; i < smp_cpus; ++i) {
++        for (i = 0; i < max_cpus; ++i) {
+              core->type = SRAT_PROCESSOR;
+              core->length = sizeof(*core);
+              core->local_apic_id = i;
+@@ -2614,7 +2614,7 @@ void smbios_init(void)
+     add_struct(0, p);
+     add_struct(1, p);
+     add_struct(3, p);
+-    for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
++    for (cpu_num = 1; cpu_num <= max_cpus; cpu_num++)
+         add_struct(4, p, cpu_num);
+ 
+     /* Each 'memory device' covers up to 16GB of address space. */
Index: qemu/pc-bios/bios-pq/series
===================================================================
--- qemu.orig/pc-bios/bios-pq/series
+++ qemu/pc-bios/bios-pq/series
@@ -14,3 +14,5 @@
 0014_add-srat-acpi-table-support.patch
 0015_enable-power-button-even-generation.patch
 0016-use-correct-mask-to-size-pci-option-rom-bar.patch
+0017-qemu-kvm-cfg-maxcpus.patch
+0018-qemu-madt-maxcpus.patch

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14  9:21       ` Filip Navara
  2009-07-14  9:32         ` Gleb Natapov
@ 2009-07-14 11:21         ` Jes Sorensen
  1 sibling, 0 replies; 24+ messages in thread
From: Jes Sorensen @ 2009-07-14 11:21 UTC (permalink / raw)
  To: Filip Navara; +Cc: Anthony Liguori, qemu-devel, Avi Kivity

On 07/14/2009 11:21 AM, Filip Navara wrote:
> BTW, many other guests complain when ACPI describes more processors
> than actually present in machine. That's why I implemented the dynamic
> DSDT generation in Bochs BIOS in the first place. One that comes to
> mind is MacOS X, or the Darwin kernel respectively.

Hi Filip,

As Gleb mentioned, this is pretty common behavior on real hardware. Most
of the boards I have here, declare the maximum number of possible CPUs,
even when they are not all active (like if you disable hyper threading).

I like the idea of dynamic declerations, but it's problematic as the
ACPI code gets more complicated.

I'd like to try and find out what broke in Anthony's case.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14 10:16           ` Alexander Graf
@ 2009-07-14 11:15             ` Filip Navara
  0 siblings, 0 replies; 24+ messages in thread
From: Filip Navara @ 2009-07-14 11:15 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Anthony Liguori, Jes Sorensen, qemu-devel, Gleb Natapov, Avi Kivity

On Tue, Jul 14, 2009 at 12:16 PM, Alexander Graf<agraf@suse.de> wrote:
>
> On 14.07.2009, at 11:32, Gleb Natapov wrote:
>
>> On Tue, Jul 14, 2009 at 11:21:53AM +0200, Filip Navara wrote:
>>>
>>> On Tue, Jul 14, 2009 at 10:38 AM, Jes Sorensen<jes@sgi.com> wrote:
>>>>
>>>> On 07/09/2009 11:57 PM, Anthony Liguori wrote:
>>>>>
>>>>> These changes make my Ubuntu server guest very unhappy.  I get a bunch
>>>>> of messages about "Not responding." on startup.
>>>>>
>>>>> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU
>>>>> hotplug (and I don't think we should).
>>>>
>>>> Anthony,
>>>>
>>>> Sorry haven't gotten back to you earlier as I was on vacation. Are you
>>>> saying the Ubuntu kernel doesn't like having more CPU entries in the
>>>> ACPI table than it actually boots on?
>>>>
>>>> Does the same guest boot using an older KVM setup? Curious since it does
>>>> have the larger CPU table in the DSDT.
>>>>
>>>> Cheers,
>>>> Jes
>>>>
>>>
>>> BTW, many other guests complain when ACPI describes more processors
>>> than actually present in machine. That's why I implemented the dynamic
>>> DSDT generation in Bochs BIOS in the first place. One that comes to
>>> mind is MacOS X, or the Darwin kernel respectively.
>>>
>> There is nothing wrong in describing more processors than actually
>> present. The disable flag is defined by ACPI for a reason. My real HW
>> IBM server does this.
>
> Yeah, last time I tried MacOS X was happy with more CPU descriptions than
> actual CPUs too as long as they were in disabled state. Has anything changed
> there I should know about?
>
> Alex

Not really... it just spits warnings that are not seen unless you
explicitly ask for complete debug/io logs (not sure which one it is
in). In any case the disabled flag was not set in QEMU when I was
debugging the code.

Best regards,
Filip Navara

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14  9:32         ` Gleb Natapov
@ 2009-07-14 10:16           ` Alexander Graf
  2009-07-14 11:15             ` Filip Navara
  0 siblings, 1 reply; 24+ messages in thread
From: Alexander Graf @ 2009-07-14 10:16 UTC (permalink / raw)
  To: Gleb Natapov
  Cc: Filip Navara, Jes Sorensen, Avi Kivity, Anthony Liguori, qemu-devel


On 14.07.2009, at 11:32, Gleb Natapov wrote:

> On Tue, Jul 14, 2009 at 11:21:53AM +0200, Filip Navara wrote:
>> On Tue, Jul 14, 2009 at 10:38 AM, Jes Sorensen<jes@sgi.com> wrote:
>>> On 07/09/2009 11:57 PM, Anthony Liguori wrote:
>>>>
>>>> These changes make my Ubuntu server guest very unhappy.  I get a  
>>>> bunch
>>>> of messages about "Not responding." on startup.
>>>>
>>>> If nothing else, maxcpus ==smp_cpus under QEMU because we don't  
>>>> do CPU
>>>> hotplug (and I don't think we should).
>>>
>>> Anthony,
>>>
>>> Sorry haven't gotten back to you earlier as I was on vacation. Are  
>>> you
>>> saying the Ubuntu kernel doesn't like having more CPU entries in the
>>> ACPI table than it actually boots on?
>>>
>>> Does the same guest boot using an older KVM setup? Curious since  
>>> it does
>>> have the larger CPU table in the DSDT.
>>>
>>> Cheers,
>>> Jes
>>>
>>
>> BTW, many other guests complain when ACPI describes more processors
>> than actually present in machine. That's why I implemented the  
>> dynamic
>> DSDT generation in Bochs BIOS in the first place. One that comes to
>> mind is MacOS X, or the Darwin kernel respectively.
>>
> There is nothing wrong in describing more processors than actually
> present. The disable flag is defined by ACPI for a reason. My real HW
> IBM server does this.

Yeah, last time I tried MacOS X was happy with more CPU descriptions  
than actual CPUs too as long as they were in disabled state. Has  
anything changed there I should know about?

Alex

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14  9:21       ` Filip Navara
@ 2009-07-14  9:32         ` Gleb Natapov
  2009-07-14 10:16           ` Alexander Graf
  2009-07-14 11:21         ` Jes Sorensen
  1 sibling, 1 reply; 24+ messages in thread
From: Gleb Natapov @ 2009-07-14  9:32 UTC (permalink / raw)
  To: Filip Navara; +Cc: Anthony Liguori, Jes Sorensen, qemu-devel, Avi Kivity

On Tue, Jul 14, 2009 at 11:21:53AM +0200, Filip Navara wrote:
> On Tue, Jul 14, 2009 at 10:38 AM, Jes Sorensen<jes@sgi.com> wrote:
> > On 07/09/2009 11:57 PM, Anthony Liguori wrote:
> >>
> >> These changes make my Ubuntu server guest very unhappy.  I get a bunch
> >> of messages about "Not responding." on startup.
> >>
> >> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU
> >> hotplug (and I don't think we should).
> >
> > Anthony,
> >
> > Sorry haven't gotten back to you earlier as I was on vacation. Are you
> > saying the Ubuntu kernel doesn't like having more CPU entries in the
> > ACPI table than it actually boots on?
> >
> > Does the same guest boot using an older KVM setup? Curious since it does
> > have the larger CPU table in the DSDT.
> >
> > Cheers,
> > Jes
> >
> 
> BTW, many other guests complain when ACPI describes more processors
> than actually present in machine. That's why I implemented the dynamic
> DSDT generation in Bochs BIOS in the first place. One that comes to
> mind is MacOS X, or the Darwin kernel respectively.
> 
There is nothing wrong in describing more processors than actually
present. The disable flag is defined by ACPI for a reason. My real HW
IBM server does this.

--
			Gleb.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-14  8:38     ` Jes Sorensen
@ 2009-07-14  9:21       ` Filip Navara
  2009-07-14  9:32         ` Gleb Natapov
  2009-07-14 11:21         ` Jes Sorensen
  0 siblings, 2 replies; 24+ messages in thread
From: Filip Navara @ 2009-07-14  9:21 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, qemu-devel, Avi Kivity

On Tue, Jul 14, 2009 at 10:38 AM, Jes Sorensen<jes@sgi.com> wrote:
> On 07/09/2009 11:57 PM, Anthony Liguori wrote:
>>
>> These changes make my Ubuntu server guest very unhappy.  I get a bunch
>> of messages about "Not responding." on startup.
>>
>> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU
>> hotplug (and I don't think we should).
>
> Anthony,
>
> Sorry haven't gotten back to you earlier as I was on vacation. Are you
> saying the Ubuntu kernel doesn't like having more CPU entries in the
> ACPI table than it actually boots on?
>
> Does the same guest boot using an older KVM setup? Curious since it does
> have the larger CPU table in the DSDT.
>
> Cheers,
> Jes
>

BTW, many other guests complain when ACPI describes more processors
than actually present in machine. That's why I implemented the dynamic
DSDT generation in Bochs BIOS in the first place. One that comes to
mind is MacOS X, or the Darwin kernel respectively.

Best regards,
Filip Navara

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-09 21:57   ` Anthony Liguori
  2009-07-12  9:39     ` Avi Kivity
@ 2009-07-14  8:38     ` Jes Sorensen
  2009-07-14  9:21       ` Filip Navara
  1 sibling, 1 reply; 24+ messages in thread
From: Jes Sorensen @ 2009-07-14  8:38 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Anthony Liguori, qemu-devel, Avi Kivity

On 07/09/2009 11:57 PM, Anthony Liguori wrote:
> These changes make my Ubuntu server guest very unhappy.  I get a bunch
> of messages about "Not responding." on startup.
>
> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU
> hotplug (and I don't think we should).

Anthony,

Sorry haven't gotten back to you earlier as I was on vacation. Are you
saying the Ubuntu kernel doesn't like having more CPU entries in the
ACPI table than it actually boots on?

Does the same guest boot using an older KVM setup? Curious since it does
have the larger CPU table in the DSDT.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-12 13:23       ` Anthony Liguori
@ 2009-07-12 13:36         ` Avi Kivity
  0 siblings, 0 replies; 24+ messages in thread
From: Avi Kivity @ 2009-07-12 13:36 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Anthony Liguori, Jes Sorensen, qemu-devel

On 07/12/2009 04:23 PM, Anthony Liguori wrote:
>>> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do 
>>> CPU hotplug (and I don't think we should).
>>>
>>
>> Why shouldn't we do cpu hotplug?
>
>
> I don't think we should do cpu hotplug via ACPI. 

Well, that's a different story from "we shouldn't do cou hotplug".

> I don't think ACPI actually models CPU hotplug and the fact that this 
> works with Linux in KVM is a happy accident. 

I think it's based on the Unisys machines and thus no accident.

> VMware only supports CPU hotplug for Windows 7/2k8 guests so I'm 
> assuming their using Viridian PV extensions to do it.

I don't recall seeing hotplug support in Viridian.  Further, Windows 
2008 appears to support cpu hotplug on bare metal.  My guess is that it 
uses ACPI, perhaps with an additional vendor driver.

> I think we should go the PV route for Linux too. 

Seems like needless churn, plus disabling that functionality for older 
kernels.

> I'd rather see us create all vcpu threads at once and then let the 
> guest offline each vcpu via a PV notification. 

That doesn't work, for example, when the guest reboots into an older 
version of itself.  It also gives control of resource usage to the guest 
instead of the host.  The latter issue can be fixed using control 
groups, but I'd rather not break it in the first place.

> I don't see a lot of value in spawning/terminating vcpu threads 
> dynamically and it adds an awful lot of complexity.  There's very 
> little overhead to an idle thread.

Can you elaborate on the complexity you think dynamic vcpu threads add?  
IIRC there's some synchronization to be done at startup, but nothing 
that merits the label "awful".

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-12  9:39     ` Avi Kivity
@ 2009-07-12 13:23       ` Anthony Liguori
  2009-07-12 13:36         ` Avi Kivity
  0 siblings, 1 reply; 24+ messages in thread
From: Anthony Liguori @ 2009-07-12 13:23 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, Jes Sorensen, qemu-devel

Avi Kivity wrote:
> On 07/10/2009 12:57 AM, Anthony Liguori wrote:
>> These changes make my Ubuntu server guest very unhappy.  I get a 
>> bunch of messages about "Not responding." on startup.
>>
>> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do 
>> CPU hotplug (and I don't think we should).
>>
>
> Why shouldn't we do cpu hotplug?

I don't think we should do cpu hotplug via ACPI.  I don't think ACPI 
actually models CPU hotplug and the fact that this works with Linux in 
KVM is a happy accident.  VMware only supports CPU hotplug for Windows 
7/2k8 guests so I'm assuming their using Viridian PV extensions to do it.

I think we should go the PV route for Linux too.  I'd rather see us 
create all vcpu threads at once and then let the guest offline each vcpu 
via a PV notification.  I don't see a lot of value in 
spawning/terminating vcpu threads dynamically and it adds an awful lot 
of complexity.  There's very little overhead to an idle thread.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-07-09 21:57   ` Anthony Liguori
@ 2009-07-12  9:39     ` Avi Kivity
  2009-07-12 13:23       ` Anthony Liguori
  2009-07-14  8:38     ` Jes Sorensen
  1 sibling, 1 reply; 24+ messages in thread
From: Avi Kivity @ 2009-07-12  9:39 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Anthony Liguori, Jes Sorensen, qemu-devel

On 07/10/2009 12:57 AM, Anthony Liguori wrote:
> These changes make my Ubuntu server guest very unhappy.  I get a bunch 
> of messages about "Not responding." on startup.
>
> If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU 
> hotplug (and I don't think we should).
>

Why shouldn't we do cpu hotplug?

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-06-24  8:35 ` [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
@ 2009-07-09 21:57   ` Anthony Liguori
  2009-07-12  9:39     ` Avi Kivity
  2009-07-14  8:38     ` Jes Sorensen
  0 siblings, 2 replies; 24+ messages in thread
From: Anthony Liguori @ 2009-07-09 21:57 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Anthony Liguori, qemu-devel, Avi Kivity

These changes make my Ubuntu server guest very unhappy.  I get a bunch 
of messages about "Not responding." on startup.

If nothing else, maxcpus ==smp_cpus under QEMU because we don't do CPU 
hotplug (and I don't think we should).

Regards,

Anthony Liguori

Jes Sorensen wrote:

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value.
  2009-06-24  8:35 [Qemu-devel] [patch 0/2] QEMU maxcpus support v2 Jes Sorensen
@ 2009-06-24  8:35 ` Jes Sorensen
  2009-07-09 21:57   ` Anthony Liguori
  0 siblings, 1 reply; 24+ messages in thread
From: Jes Sorensen @ 2009-06-24  8:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Avi Kivity

[-- Attachment #1: 0002-qemu-bios-patches.patch --]
[-- Type: text/plain, Size: 6708 bytes --]

Signed-off-by: Jes Sorensen <jes@sgi.com>
---
 pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch |   57 +++++++++++++
 pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch    |  105 ++++++++++++++++++++++++
 pc-bios/bios-pq/series                          |    2 
 3 files changed, 164 insertions(+)

Index: qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0017-qemu-kvm-cfg-maxcpus.patch
@@ -0,0 +1,57 @@
+Read max_cpus variable from QEMU_CFG. If not provided, use value of
+smp_cpus.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f861f81..f4a6300 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -436,6 +436,7 @@ void delay_ms(int n)
+ }
+ 
+ uint16_t smp_cpus;
++uint16_t max_cpus;
+ uint32_t cpuid_signature;
+ uint32_t cpuid_features;
+ uint32_t cpuid_ext_features;
+@@ -474,6 +475,7 @@ void wrmsr_smp(uint32_t index, uint64_t val)
+ #define QEMU_CFG_ID         0x01
+ #define QEMU_CFG_UUID       0x02
+ #define QEMU_CFG_NUMA       0x0D
++#define QEMU_CFG_MAX_CPUS   0x0E
+ #define QEMU_CFG_ARCH_LOCAL     0x8000
+ #define QEMU_CFG_ACPI_TABLES  (QEMU_CFG_ARCH_LOCAL + 0)
+ #define QEMU_CFG_SMBIOS_ENTRIES  (QEMU_CFG_ARCH_LOCAL + 1)
+@@ -536,6 +538,19 @@ static uint16_t smbios_entries(void)
+     return cnt;
+ }
+ 
++static uint16_t get_max_cpus(void)
++{
++    uint16_t cnt;
++
++    qemu_cfg_select(QEMU_CFG_MAX_CPUS);
++    qemu_cfg_read((uint8_t*)&cnt, sizeof(cnt));
++
++    if (!cnt)
++        cnt = smp_cpus;
++
++    return cnt;
++}
++
+ uint64_t qemu_cfg_get64 (void)
+ {
+     uint64_t ret;
+@@ -1655,6 +1670,11 @@ void acpi_bios_init(void)
+     uint16_t i, external_tables;
+     int nb_numa_nodes;
+ 
++#ifdef BX_QEMU
++    max_cpus = get_max_cpus();
++#else
++    max_cpus = smp_cpus;
++#endif
+     /* reserve memory space for tables */
+ #ifdef BX_USE_EBDA_TABLES
+     ebda_cur_addr = align(ebda_cur_addr, 16);
Index: qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
===================================================================
--- /dev/null
+++ qemu/pc-bios/bios-pq/0018-qemu-madt-maxcpus.patch
@@ -0,0 +1,105 @@
+Use max_cpus when building bios tables.
+
+Signed-off-by: Jes Sorensen <jes@sgi.com>
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index f4a6300..fb4d663 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1155,13 +1155,13 @@ static void mptable_init(void)
+     putstr(&q, "0.1         "); /* vendor id */
+     putle32(&q, 0); /* OEM table ptr */
+     putle16(&q, 0); /* OEM table size */
+-    putle16(&q, smp_cpus + 18); /* entry count */
++    putle16(&q, max_cpus + 18); /* entry count */
+     putle32(&q, 0xfee00000); /* local APIC addr */
+     putle16(&q, 0); /* ext table length */
+     putb(&q, 0); /* ext table checksum */
+     putb(&q, 0); /* reserved */
+ 
+-    for(i = 0; i < smp_cpus; i++) {
++    for(i = 0; i < max_cpus; i++) {
+         putb(&q, 0); /* entry type = processor */
+         putb(&q, i); /* APIC id */
+         putb(&q, 0x11); /* local APIC version number */
+@@ -1188,7 +1188,7 @@ static void mptable_init(void)
+     putstr(&q, "ISA   ");
+ 
+     /* ioapic */
+-    ioapic_id = smp_cpus;
++    ioapic_id = max_cpus;
+     putb(&q, 2); /* entry type = I/O APIC */
+     putb(&q, ioapic_id); /* apic ID */
+     putb(&q, 0x11); /* I/O APIC version number */
+@@ -1588,7 +1588,7 @@ int acpi_build_processor_ssdt(uint8_t *ssdt)
+ {
+     uint8_t *ssdt_ptr = ssdt;
+     int i, length;
+-    int acpi_cpus = smp_cpus > 0xff ? 0xff : smp_cpus;
++    int acpi_cpus = max_cpus > 0xff ? 0xff : max_cpus;
+ 
+     ssdt_ptr[9] = 0; // checksum;
+     ssdt_ptr += sizeof(struct acpi_table_header);
+@@ -1725,7 +1725,7 @@ void acpi_bios_init(void)
+         addr = (addr + 7) & ~7;
+         srat_addr = addr;
+         srat_size = sizeof(*srat) +
+-            sizeof(struct srat_processor_affinity) * smp_cpus +
++            sizeof(struct srat_processor_affinity) * max_cpus +
+             sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2);
+         srat = (void *)(addr);
+         addr += srat_size;
+@@ -1738,7 +1738,7 @@ void acpi_bios_init(void)
+     addr = (addr + 7) & ~7;
+     madt_addr = addr;
+     madt_size = sizeof(*madt) +
+-        sizeof(struct madt_processor_apic) * smp_cpus +
++        sizeof(struct madt_processor_apic) * max_cpus +
+ #ifdef BX_QEMU
+         sizeof(struct madt_io_apic) + sizeof(struct madt_int_override);
+ #else
+@@ -1811,7 +1811,7 @@ void acpi_bios_init(void)
+         madt->local_apic_address = cpu_to_le32(0xfee00000);
+         madt->flags = cpu_to_le32(1);
+         apic = (void *)(madt + 1);
+-        for(i=0;i<smp_cpus;i++) {
++        for(i = 0;i < max_cpus; i++) {
+             apic->type = APIC_PROCESSOR;
+             apic->length = sizeof(*apic);
+             apic->processor_id = i;
+@@ -1822,7 +1822,7 @@ void acpi_bios_init(void)
+         io_apic = (void *)apic;
+         io_apic->type = APIC_IO;
+         io_apic->length = sizeof(*io_apic);
+-        io_apic->io_apic_id = smp_cpus;
++        io_apic->io_apic_id = max_cpus;
+         io_apic->address = cpu_to_le32(0xfec00000);
+         io_apic->interrupt = cpu_to_le32(0);
+ #ifdef BX_QEMU
+@@ -1856,7 +1856,7 @@ void acpi_bios_init(void)
+         srat->reserved1=1;
+  
+         core = (void*)(srat + 1);
+-        for (i = 0; i < smp_cpus; ++i) {
++        for (i = 0; i < max_cpus; ++i) {
+              core->type = SRAT_PROCESSOR;
+              core->length = sizeof(*core);
+              core->local_apic_id = i;
+@@ -1864,7 +1864,7 @@ void acpi_bios_init(void)
+              core->proximity_lo = curnode;
+              memset (core->proximity_hi, 0, 3);
+              core->local_sapic_eid = 0;
+-             if (i < smp_cpus)
++             if (i < max_cpus)
+                  core->flags = cpu_to_le32(1);
+              else
+                  core->flags = 0;
+@@ -2614,7 +2614,7 @@ void smbios_init(void)
+     add_struct(0, p);
+     add_struct(1, p);
+     add_struct(3, p);
+-    for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
++    for (cpu_num = 1; cpu_num <= max_cpus; cpu_num++)
+         add_struct(4, p, cpu_num);
+ 
+     /* Each 'memory device' covers up to 16GB of address space. */
Index: qemu/pc-bios/bios-pq/series
===================================================================
--- qemu.orig/pc-bios/bios-pq/series
+++ qemu/pc-bios/bios-pq/series
@@ -14,3 +14,5 @@
 0014_add-srat-acpi-table-support.patch
 0015_enable-power-button-even-generation.patch
 0016-use-correct-mask-to-size-pci-option-rom-bar.patch
+0017-qemu-kvm-cfg-maxcpus.patch
+0018-qemu-madt-maxcpus.patch

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2009-07-23 15:06 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-23 10:00 [Qemu-devel] [patch 0/2] QEMU maxcpus support Jes Sorensen
2009-06-23 10:00 ` [Qemu-devel] [patch 1/2] Introduce -maxcpus flag to QEMU and pass the value to the BIOS through FW_CFG Jes Sorensen
2009-06-23 10:00 ` [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
2009-06-23 11:37 ` [Qemu-devel] Re: [patch 0/2] QEMU maxcpus support Avi Kivity
2009-06-23 13:32   ` Jes Sorensen
2009-06-23 13:36     ` Avi Kivity
2009-06-23 15:07       ` Jes Sorensen
2009-06-23 15:47         ` Avi Kivity
2009-06-24  7:16           ` Jes Sorensen
2009-06-24  7:25             ` Filip Navara
2009-06-24  8:35 [Qemu-devel] [patch 0/2] QEMU maxcpus support v2 Jes Sorensen
2009-06-24  8:35 ` [Qemu-devel] [patch 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
2009-07-09 21:57   ` Anthony Liguori
2009-07-12  9:39     ` Avi Kivity
2009-07-12 13:23       ` Anthony Liguori
2009-07-12 13:36         ` Avi Kivity
2009-07-14  8:38     ` Jes Sorensen
2009-07-14  9:21       ` Filip Navara
2009-07-14  9:32         ` Gleb Natapov
2009-07-14 10:16           ` Alexander Graf
2009-07-14 11:15             ` Filip Navara
2009-07-14 11:21         ` Jes Sorensen
2009-07-14 12:53 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v2 Jes Sorensen
2009-07-14 12:53 ` [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
2009-07-20 14:43 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v3 Jes Sorensen
2009-07-20 14:43 ` [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen
2009-07-23 15:03 [Qemu-devel] [PATCH 0/2] QEMU maxcpus support v4 Jes Sorensen
2009-07-23 15:03 ` [Qemu-devel] [PATCH 2/2] QEMU BOCHS bios patches to use maxcpus value Jes Sorensen

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.