Skip to contentSkip to conversation

Add support for cpu hotplug

PATCH Superseded Glauber Costa 2 participants 9 messages Apr 17, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for cpu hotplug

This is mainly the code we have in kvm-userspace, with a few small improvements.

#1 lore raw

PATCH 1/6 split pc_new_cpu

since it is useful elsewhere.

---
 hw/pc.c |   37 ++++++++++++++++++++++---------------
 hw/pc.h |    1 +
 2 files changed, 23 insertions(+), 15 deletions(-)
hw/pc.c +22 -15
index 6a1750e..39ed066 100644
@@ -775,6 +775,26 @@ static int load_option_rom(const char *oprom, target_phys_addr_t start,
         return size;
 }
 
+CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled)
+{
+    CPUState *env = cpu_init(cpu_model);
+    if (!env) {
+        fprintf(stderr, "Unable to find x86 CPU definition\n");
+        exit(1);
+    }
+    if (cpu != 0)
+        env->halted = 1;
+    if (smp_cpus > 1) {
+        /* XXX: enable it in all cases */
+        env->cpuid_features |= CPUID_APIC;
+    }
+    qemu_register_reset(main_cpu_reset, env);
+    if (pci_enabled) {
+        apic_init(env);
+    }
+    return env;
+}
+
 /* PC hardware initialisation */
 static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
                      const char *boot_device,
@@ -816,23 +836,10 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
     }
     
     for(i = 0; i < smp_cpus; i++) {
-        env = cpu_init(cpu_model);
-        if (!env) {
-            fprintf(stderr, "Unable to find x86 CPU definition\n");
-            exit(1);
-        }
-        if (i != 0)
-            env->halted = 1;
-        if (smp_cpus > 1) {
-            /* XXX: enable it in all cases */
-            env->cpuid_features |= CPUID_APIC;
-        }
-        qemu_register_reset(main_cpu_reset, env);
-        if (pci_enabled) {
-            apic_init(env);
-        }
+        env = pc_new_cpu(i, cpu_model, pci_enabled);
     }
 
+
     vmport_init();
 
     /* allocate RAM */
hw/pc.h +1 -0
index 50e6c39..59047b5 100644
@@ -102,6 +102,7 @@ extern int fd_bootchk;
 
 void ioport_set_a20(int enable);
 int ioport_get_a20(void);
+CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled);
 
 /* acpi.c */
 extern int acpi_enabled;
Signature · 1 line
1.5.6.6
#2 lore raw

PATCH 2/6 always have apic

if we are going to initialize the apic, set cpuid bit unconditionally. As far as I know, we should not do that for isa machines anyway.

---
 hw/pc.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
hw/pc.c +2 -4
index 39ed066..7649f2c 100644
@@ -784,12 +784,10 @@ CPUState *pc_new_cpu(int cpu, const char *cpu_model, int pci_enabled)
     }
     if (cpu != 0)
         env->halted = 1;
-    if (smp_cpus > 1) {
-        /* XXX: enable it in all cases */
-        env->cpuid_features |= CPUID_APIC;
-    }
+
     qemu_register_reset(main_cpu_reset, env);
     if (pci_enabled) {
+        env->cpuid_features |= CPUID_APIC;
         apic_init(env);
     }
     return env;
Signature · 1 line
1.5.6.6
#3 lore raw

PATCH 3/6 Fix warnings and errors with DEBUG enabled

Appearently nobody tried this yet. It produces tons of warning and an one error.

---
 hw/acpi.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/acpi.c +6 -6
index 52f50a0..22fbc4a 100644
@@ -604,7 +604,7 @@ static uint32_t gpe_readb(void *opaque, uint32_t addr)
     }
 
 #if defined(DEBUG)
-    printf("gpe read %lx == %lx\n", addr, val);
+    printf("gpe read %x == %x\n", addr, val);
 #endif
     return val;
 }
@@ -646,7 +646,7 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)
    }
 
 #if defined(DEBUG)
-    printf("gpe write %lx <== %d\n", addr, val);
+    printf("gpe write %x <== %d\n", addr, val);
 #endif
 }
 
@@ -666,7 +666,7 @@ static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
     }
 
 #if defined(DEBUG)
-    printf("pcihotplug read %lx == %lx\n", addr, val);
+    printf("pcihotplug read %x == %x\n", addr, val);
 #endif
     return val;
 }
@@ -684,14 +684,14 @@ static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val)
    }
 
 #if defined(DEBUG)
-    printf("pcihotplug write %lx <== %d\n", addr, val);
+    printf("pcihotplug write %x <== %d\n", addr, val);
 #endif
 }
 
 static uint32_t pciej_read(void *opaque, uint32_t addr)
 {
 #if defined(DEBUG)
-    printf("pciej read %lx == %lx\n", addr, val);
+    printf("pciej read %x == %x\n", addr, 0);
 #endif
     return 0;
 }
@@ -705,7 +705,7 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 #endif
 
 #if defined(DEBUG)
-    printf("pciej write %lx <== %d\n", addr, val);
+    printf("pciej write %x <== %d\n", addr, val);
 #endif
 }
 
Signature · 1 line
1.5.6.6
#4 lore raw

PATCH 4/6 disallow kqemu if we fail to load it.

Since we're not retrying it anyway, set kqemu_allowed = 0 if we fail to load it. It will allow us to test for kqemu runtime presence where we don't have an env pointer, possibly because we don't have a cpu yet.

The monitor code is such an example.

---
 kqemu.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
kqemu.c +4 -2
index 040e817..e0e0499 100644
@@ -179,14 +179,14 @@ int kqemu_init(CPUState *env)
     if (kqemu_fd == KQEMU_INVALID_FD) {
         fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %lu\n",
                 KQEMU_DEVICE, GetLastError());
-        return -1;
+        goto out;
     }
 #else
     kqemu_fd = open(KQEMU_DEVICE, O_RDWR);
     if (kqemu_fd == KQEMU_INVALID_FD) {
         fprintf(stderr, "Could not open '%s' - QEMU acceleration layer not activated: %s\n",
                 KQEMU_DEVICE, strerror(errno));
-        return -1;
+        goto out;
     }
 #endif
     version = 0;
@@ -239,6 +239,8 @@ int kqemu_init(CPUState *env)
     fail:
         kqemu_closefd(kqemu_fd);
         kqemu_fd = KQEMU_INVALID_FD;
+    out:
+        kqemu_allowed = 0;
         return -1;
     }
     kqemu_update_cpuid(env);
Signature · 1 line
1.5.6.6
#5 lore raw

PATCH 5/6 enable cpu hotplug

This patch enable cpu hotplug to happen via acpi events. Note that all it does is generate acpi messages. It still needs guest cooperation, in the very way as real hardware.

It is basically what we have in kvm, but in a qemuish style, with a few improvements.

---
 cpu-all.h |    1 +
 exec.c    |   13 +++++++++++
 hw/acpi.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 monitor.c |   21 ++++++++++++++++++
 sysemu.h  |    1 +
 5 files changed, 105 insertions(+), 0 deletions(-)
cpu-all.h +1 -0
index aaaa70d..a0c97f7 100644
@@ -745,6 +745,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags);
 
 void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
+CPUState *qemu_get_cpu(int cpu);
 
 void cpu_dump_state(CPUState *env, FILE *f,
                     int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
exec.c +13 -0
index 13e43d0..a7ac18f 100644
@@ -538,6 +538,19 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
+CPUState *qemu_get_cpu(int cpu)
+{
+    CPUState *env = first_cpu;
+
+    while (env) {
+        if (env->cpu_index == cpu)
+            break;
+        env = env->next_cpu;
+    }
+
+    return env;
+}
+
 void cpu_exec_init(CPUState *env)
 {
     CPUState **penv;
hw/acpi.c +69 -0

110 lines not on this page · raw message

monitor.c +21 -0
index e764b5d..53e5938 100644
@@ -372,6 +372,26 @@ static void do_cpu_set(Monitor *mon, int index)
         monitor_printf(mon, "Invalid CPU index\n");
 }
 
+static void do_cpu_set_nr(Monitor *mon, int value, const char *status)
+{
+    int state;
+
+    if (kvm_enabled() || kqemu_allowed) {
+        monitor_printf(mon, "CPU hotplug not supported\n");
+        return;
+    }
+
+    if (!strcmp(status, "online"))
+       state = 1;
+    else if (!strcmp(status, "offline"))
+       state = 0;
+    else {
+        monitor_printf(mon, "invalid status: %s\n", status);
+        return;
+    }
+    qemu_system_cpu_hot_add(value, state);
+}
+
 static void do_info_jit(Monitor *mon)
 {
     dump_exec_info((FILE *)mon, monitor_fprintf);
@@ -1739,6 +1759,7 @@ static const mon_cmd_t mon_cmds[] = {
       "target", "request VM to change it's memory allocation (in MB)" },
     { "set_link", "ss", do_set_link,
       "name [up|down]", "change the link status of a network adapter" },
+    { "cpu_set", "is", do_cpu_set_nr, "cpu [online|offline]", "change cpu state" },
     { "acl", "sss?i?", do_acl, "<command> <aclname> [<match>] [<index>]\n",
                                "acl show vnc.username\n"
                                "acl policy vnc.username deny\n"
sysemu.h +1 -0
index 3eab34b..b69c6f0 100644
@@ -175,6 +175,7 @@ extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
 /* acpi */
 void qemu_system_hot_add_init(void);
 void qemu_system_device_hot_add(int pcibus, int slot, int state);
+void qemu_system_cpu_hot_add(int cpu, int state);
 
 /* device-hotplug */
 
Signature · 1 line
1.5.6.6
#6 lore raw

PATCH 6/6 add bios support for cpu hotplug.

This adds patches to bochs-bios to support cpu hotplug

first one creates entries in acpi tables, and the second one removes the now unused static sdt.

---
 ...012-qemu-bios-create-acpi-cpu-definitions.patch |  293 ++++++++++++++++++++
 ...emu-bios-remove-acpi_build_processor_ssdt.patch |   55 ++++
 pc-bios/bios-pq/series                             |    2 +
 3 files changed, 350 insertions(+), 0 deletions(-)
 create mode 100644 pc-bios/bios-pq/0012-qemu-bios-create-acpi-cpu-definitions.patch
 create mode 100644 pc-bios/bios-pq/0013-qemu-bios-remove-acpi_build_processor_ssdt.patch
pc-bios/bios-pq/0012-qemu-bios-create-acpi-cpu-definitions.patch new file +293 -0
new file mode 100644
index 0000000..89bf081
@@ -0,0 +1,293 @@
+From 09ce41fd61e075c47777df08641cd76ca733f172 Mon Sep 17 00:00:00 2001
+From: Glauber Costa <[email protected]>
+Date: Fri, 17 Apr 2009 10:51:18 -0400
+Subject: [PATCH] create acpi cpu definitions
+
+This comes directly from kvm-userspace. It creates
+the necessary infrastructure for cpu hotplug, by
+creating _MAT and _STA entries in cpu devices,
+and by allowing notifications to the guest to happen
+
+note that now, we have to fill acpi tables with MAX_CPUS,
+instead of smp_cpus, otherwise we'll never be able to grow
+the cpu number.
+
+Signed-off-by: Glauber Costa <[email protected]>
+---
+ bios/acpi-dsdt.dsl |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++-
+ bios/rombios.h     |    2 +
+ bios/rombios32.c   |   72 +++++---------------------------
+ 3 files changed, 128 insertions(+), 62 deletions(-)
+
+diff --git a/bios/acpi-dsdt.dsl b/bios/acpi-dsdt.dsl
+index 7bff30a..23d8d6c 100644
+--- a/bios/acpi-dsdt.dsl
++++ b/bios/acpi-dsdt.dsl
+@@ -25,6 +25,120 @@ DefinitionBlock (
+     0x1                 // OEM Revision
+     )
+ {
++   Scope (\_PR)
++   {
++	OperationRegion(PRST, SystemIO, 0xaf00, 32)
++	Field (PRST, ByteAcc, NoLock, Preserve)
++	{
++		PRS, 256
++	}
++
++	Name(PRSS, Buffer(32){}) /* shadow CPU status bitmask */
++	Name(SSVL, 0)
++
++	Method(CRST, 1) {
++		If (LEqual(SSVL, 0)) {
++			Store(PRS, PRSS) /* read CPUs status bitmaks from HW */
++			Store(1, SSVL)
++                }
++		ShiftRight(Arg0, 3, Local1)
++		Store(DerefOf(Index(PRSS, Local1)), Local2)
++	        Return(And(Local2, ShiftLeft(1, And(Arg0, 0x7))))
++	}
++
++#define gen_processor(nr, name) 				            \
++	Processor (CPU##name, nr, 0x0000b010, 0x06) {                       \
++            Name (PREN, Buffer(0x8) {0x0, 0x8, nr, nr, 0x1, 0x0, 0x0, 0x0}) \
++            Name (PRDS, Buffer(0x8) {0x0, 0x8, nr, nr, 0x0, 0x0, 0x0, 0x0}) \
++            Method(_MAT, 0) {                                               \
++                If (CRST(nr)) { Return(PREN) }                              \
++                Else { Return(PRDS) }                                       \
++            }                                                               \
++            Method (_STA) {                                                 \
++                If (CRST(nr)) { Return(0xF) }                               \
++                Else { Return(0x9) }                                        \
++            }                                                               \
++        }                                                                   \
++
++
++	gen_processor(0, 0)
++	gen_processor(1, 1)
++	gen_processor(2, 2)
++	gen_processor(3, 3)
++	gen_processor(4, 4)
++	gen_processor(5, 5)
++	gen_processor(6, 6)
++	gen_processor(7, 7)
++	gen_processor(8, 8)
++	gen_processor(9, 9)
++	gen_processor(10, A)
++	gen_processor(11, B)
++	gen_processor(12, C)
++	gen_processor(13, D)
++	gen_processor(14, E)
++
++	Method (NTFY, 2) {
++#define gen_ntfy(nr)                              \
++	If (LEqual(Arg0, 0x##nr)) {               \
++		Notify(CPU##nr, Arg1)             \
++	}
++		gen_ntfy(0)
++		gen_ntfy(1)
++		gen_ntfy(2)
++		gen_ntfy(3)
++		gen_ntfy(4)
++		gen_ntfy(5)
++		gen_ntfy(6)
++		gen_ntfy(7)
++		gen_ntfy(8)
++		gen_ntfy(9)
++		gen_ntfy(A)
++		gen_ntfy(B)
++		gen_ntfy(C)
++		gen_ntfy(D)
++		gen_ntfy(E)
++		Return(One)
++	}
++
++	/* Works on 8 bit quentity.
++         * Arg1 - Shadow status bits
++         * Arg2 - Current status bits
++	 */
++        Method(PR1, 3) {
++	    Xor(Arg1, Arg2, Local0) /* figure out what chaged */
++	    ShiftLeft(Arg0, 3, Local1)
++            While (LNotEqual(Local0, Zero)) {
++		If (And(Local0, 1)) {      /* if staus have changed */
++                    if(And(Arg2, 1)) {     /* check previous status */
++	                Store(3, Local3)
++		    } Else {
++	                Store(1, Local3)
++	            }
++		    NTFY(Local1, Local3)
++                }
++		ShiftRight(Local0, 1, Local0)
++		ShiftRight(Arg2, 1, Arg2)
++		Increment(Local1)
++	    }
++	    Return(One)
++	}
++
++	Method(PRSC, 0) {
++		Store(Buffer(32){}, Local0)
++		Store(PRS, Local0) /* read CPUs status bitmask into Local0 */
++		Store(Zero, Local1)
++		/* loop over bitmask byte by byte to see what have chaged */
++		While(LLess(Local1, 32)) {
++			Store(DerefOf(Index(Local0, Local1)), Local2)
++			Store(DerefOf(Index(PRSS, Local1)), Local3)
++			PR1(Local1, Local2, Local3)
++			Increment(Local1)
++                }
++		Store(Local0, PRSS) /* store curr satust bitmask into shadow */
++		Return(One)
++	}
++    }
++
+     Scope (\)
+     {
+         /* Debug Output */
+@@ -706,7 +820,7 @@ DefinitionBlock (
+
+         }
+         Method(_L02) {
+-            Return(0x01)
++	    Return(\_PR.PRSC())
+         }
+         Method(_L03) {
+             Return(0x01)
+diff --git a/bios/rombios.h b/bios/rombios.h
+index 6f9cbb1..085e287 100644
+--- a/bios/rombios.h
++++ b/bios/rombios.h
+@@ -58,6 +58,8 @@
+ #define SMB_IO_BASE       0xb100
+ #define SMP_MSR_ADDR      0x0510
+
++#define MAX_CPUS	256
++
+   // Define the application NAME
+ #if defined(BX_QEMU)
+ #  define BX_APPNAME "QEMU"
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index 7be4216..3063409 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1126,20 +1126,22 @@ 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 */
+         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);
+@@ -1508,57 +1510,6 @@ static void acpi_build_table_header(struct acpi_table_header *h,
+     h->checksum = acpi_checksum((void *)h, len);
+ }
+
+-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;
+-
+-    ssdt_ptr[9] = 0; // checksum;
+-    ssdt_ptr += sizeof(struct acpi_table_header);
+-
+-    // caluculate the length of processor block and scope block excluding PkgLength
+-    length = 0x0d * acpi_cpus + 4;
+-
+-    // build processor scope header
+-    *(ssdt_ptr++) = 0x10; // ScopeOp
+-    if (length <= 0x3e) {
+-        *(ssdt_ptr++) = length + 1;
+-    } else {
+-        *(ssdt_ptr++) = 0x7F;
+-        *(ssdt_ptr++) = (length + 2) >> 6;
+-    }
+-    *(ssdt_ptr++) = '_'; // Name
+-    *(ssdt_ptr++) = 'P';
+-    *(ssdt_ptr++) = 'R';
+-    *(ssdt_ptr++) = '_';
+-
+-    // build object for each processor
+-    for(i=0;i<acpi_cpus;i++) {
+-        *(ssdt_ptr++) = 0x5B; // ProcessorOp
+-        *(ssdt_ptr++) = 0x83;
+-        *(ssdt_ptr++) = 0x0B; // Length
+-        *(ssdt_ptr++) = 'C';  // Name (CPUxx)
+-        *(ssdt_ptr++) = 'P';
+-        if ((i & 0xf0) != 0)
+-            *(ssdt_ptr++) = (i >> 4) < 0xa ? (i >> 4) + '0' : (i >> 4) + 'A' - 0xa;
+-        else
+-            *(ssdt_ptr++) = 'U';
+-        *(ssdt_ptr++) = (i & 0xf) < 0xa ? (i & 0xf) + '0' : (i & 0xf) + 'A' - 0xa;
+-        *(ssdt_ptr++) = i;
+-        *(ssdt_ptr++) = 0x10; // Processor block address
+-        *(ssdt_ptr++) = 0xb0;
+-        *(ssdt_ptr++) = 0;
+-        *(ssdt_ptr++) = 0;
+-        *(ssdt_ptr++) = 6;    // Processor block length
+-    }
+-
+-    acpi_build_table_header((struct acpi_table_header *)ssdt,
+-                            "SSDT", ssdt_ptr - ssdt, 1);
+-
+-    return ssdt_ptr - ssdt;
+-}
+-
+ /* base_addr must be a multiple of 4KB */
+ void acpi_bios_init(void)
+ {
+@@ -1613,14 +1564,10 @@ void acpi_bios_init(void)
+     dsdt = (void *)(addr);
+     addr += sizeof(AmlCode);
+
+-    ssdt_addr = addr;
+-    ssdt = (void *)(addr);
+-    addr += acpi_build_processor_ssdt(ssdt);
+-
+     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
+@@ -1693,12 +1640,15 @@ 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;
+--
+1.5.6.6
+
pc-bios/bios-pq/0013-qemu-bios-remove-acpi_build_processor_ssdt.patch new file +55 -0

55 lines not on this page · raw message

pc-bios/bios-pq/series +2 -0
index 5a29df9..8f88ee1 100644
@@ -9,3 +9,5 @@
 0009_qemu-bios-pci-hotplug-support.patch
 0010_bios-mark-the-acpi-sci-interrupt-as-connected-to-irq-9.patch
 0011_read-additional-acpi-tables-from-a-vm.patch
+0012-qemu-bios-create-acpi-cpu-definitions.patch
+0013-qemu-bios-remove-acpi_build_processor_ssdt.patch
Signature · 1 line
1.5.6.6
#7 lore raw

[Qemu-devel] Re: [PATCH 6/6] add bios support for cpu hotplug.

Quoted 7 lines · Glauber Costa

This adds patches to bochs-bios to support cpu hotplug

first one creates entries in acpi tables, and the second one removes the now unused static sdt.

Please send these as patches against bochs, and CC bochs-devel. I'll stick them into the appropriate place in the patch queue when committing.

Signature · 3 lines
Regards,

Anthony Liguori
#8 lore raw

[Qemu-devel] Re: [PATCH 5/6] enable cpu hotplug

In reply to Glauber Costa
Quoted 57 lines · Glauber Costa

This patch enable cpu hotplug to happen via acpi events. Note that all it does is generate acpi messages. It still needs guest cooperation, in the very way as real hardware.

It is basically what we have in kvm, but in a qemuish style, with a few improvements.

---
 cpu-all.h |    1 +
 exec.c    |   13 +++++++++++
 hw/acpi.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 monitor.c |   21 ++++++++++++++++++
 sysemu.h  |    1 +
 5 files changed, 105 insertions(+), 0 deletions(-)
cpu-all.h +1 -0
index aaaa70d..a0c97f7 100644
@@ -745,6 +745,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags);
 
 void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
+CPUState *qemu_get_cpu(int cpu);
 
 void cpu_dump_state(CPUState *env, FILE *f,
                     int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
exec.c +13 -0
index 13e43d0..a7ac18f 100644
@@ -538,6 +538,19 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
+CPUState *qemu_get_cpu(int cpu)
+{
+    CPUState *env = first_cpu;
+
+    while (env) {
+        if (env->cpu_index == cpu)
+            break;
+        env = env->next_cpu;
+    }
+
+    return env;
+}
+
 void cpu_exec_init(CPUState *env)
 {
     CPUState **penv;
hw/acpi.c +0 -0
index 22fbc4a..10c0e69 100644

hw/acpi.c line 30

Quoted 5 lines
hw/acpi.c +1 -0
@@ -26,6 +26,7 @@
 #include "kvm.h"
 
 //#define DEBUG
+//#define DEBUG_CPU
 

Consider introducing a cpu_dprintf() or something like that.

hw/acpi.c static void pciej_write(void *opaque, uint32_t addr, uint32_t val) · line 722

Quoted 12 lines
hw/acpi.c +7 -0
@@ -709,11 +712,44 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 #endif
 }
 
+static uint32_t cpuhotplug_read(void *opaque, uint32_t addr)
+{
+    if ((addr < PROC_BASE) || (addr > (PROC_BASE + 31))) {
+        /* should never happen, so return a poison */
+        return 0xabcdefab;
+    }
+    else {
 

Should be one line.

hw/acpi.c void qemu_system_device_hot_add(int bus, int slot, int state)

Quoted 13 lines
hw/acpi.c +12 -0
+void qemu_system_cpu_hot_add(int cpu, int state)
+{
+    CPUState *env;
+
+    if ((state) && !qemu_get_cpu(cpu)) {
+#ifdef DEBUG_CPU
+        printf("creatng new cpu %d\n", cpu);
+#endif
+        env = pc_new_cpu(cpu, first_cpu->cpu_model_str, 1);
+        enable_processor(&gpe, cpu);
+    }
+    else {
 

Should be one line.

hw/acpi.c static void pciej_write(void *opaque, uint32_t addr, uint32_t val) · line 741

Quoted 6 lines
hw/acpi.c +5 -0
+
+    if (!strcmp(status, "online"))
+       state = 1;
+    else if (!strcmp(status, "offline"))
+       state = 0;
 

Should have {}s.

Signature · 3 lines
Regards,

Anthony Liguori