qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [patch] Introduce per machine based max_cpu variable


From: Anthony Liguori
Subject: Re: [Qemu-devel] [patch] Introduce per machine based max_cpu variable
Date: Tue, 30 Sep 2008 09:47:28 -0500
User-agent: Thunderbird 2.0.0.16 (X11/20080723)

Jes Sorensen wrote:

Introduce a max_cpus per-machine variable, allowing individual boards
to limit it's number of CPUs. Check requested number of CPUs in setup
code and exit if it exceeds the supported number for the machine.
This also renders the static MAX_CPUS check obsolete, so remove this
from vl.c.

Signed-off-by: Jes Sorensen <address@hidden>

Index: qemu/hw/an5206.c
===================================================================
--- qemu.orig/hw/an5206.c
+++ qemu/hw/an5206.c
@@ -88,8 +88,9 @@ static void an5206_init(ram_addr_t ram_s
 }
QEMUMachine an5206_machine = {
-    "an5206",
-    "Arnewsh 5206",
-    an5206_init,
-    512,
+    .name = "an5206",
+    .desc = "Arnewsh 5206",
+    .init = an5206_init,
+    .ram_require = 512,
+    .max_cpus = 1,
 };

Your change would be greatly simplified if you defined max_cpus to be such that it was the maximum number of vcpus - 1.

Then the default value of 0 would be sufficient for most machine types.

Index: qemu/hw/boards.h
===================================================================
--- qemu.orig/hw/boards.h
+++ qemu/hw/boards.h
@@ -16,7 +16,8 @@ typedef struct QEMUMachine {
     QEMUMachineInitFunc *init;
 #define RAMSIZE_FIXED  (1 << 0)
     ram_addr_t ram_require;
-    int nodisk_ok;
+    short max_cpus;
+    char nodisk_ok;
     struct QEMUMachine *next;
 } QEMUMachine;

Just use int and please don't change nodisk_ok to char.

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c
+++ qemu/vl.c
@@ -209,13 +209,6 @@ int usb_enabled = 0;
 static VLANState *first_vlan;
 int smp_cpus = 1;
 const char *vnc_display;
-#if defined(TARGET_SPARC)
-#define MAX_CPUS 16
-#elif defined(TARGET_I386)
-#define MAX_CPUS 255
-#else
-#define MAX_CPUS 1
-#endif
 int acpi_enabled = 1;
 int fd_bootchk = 1;
 int no_reboot = 0;
@@ -8772,7 +8765,7 @@ int main(int argc, char **argv)
                 break;
             case QEMU_OPTION_smp:
                 smp_cpus = atoi(optarg);
-                if (smp_cpus < 1 || smp_cpus > MAX_CPUS) {
+                if (smp_cpus < 1) {
                     fprintf(stderr, "Invalid number of CPUs\n");
                     exit(1);
                 }
@@ -8889,6 +8882,13 @@ int main(int argc, char **argv)
         }
     }
+ if (smp_cpus > machine->max_cpus) {
+        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
+                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+                machine->max_cpus);
+        exit(-1);

exit() should be passed something between 0 and 255. WEXITSTATUS always returns the least significant 8 bits so the result will always be 0..255. Moreover, by convention in QEMU we usually exit(1), not exit(-1).

Regards,

Anthony Liguori




reply via email to

[Prev in Thread] Current Thread [Next in Thread]