CPU Hotplug v2
v2 cover CPU Hotplug v2
Adressing all concerns.
PATCH v2 1/5 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
@@ -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
@@ -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
PATCH v2 2/5 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
@@ -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
PATCH v2 3/5 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
@@ -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
PATCH v2 4/5 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
@@ -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
PATCH v2 5/5 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 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ monitor.c | 21 +++++++++++++++++++ sysemu.h | 1 + 5 files changed, 103 insertions(+), 0 deletions(-)
cpu-all.h +1 -0
@@ -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
@@ -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 +67 -0
108 lines not on this page · raw message
monitor.c +21 -0
@@ -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
@@ -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