[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/19] add cpu-add qmp command and implement CPU hot
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 19/19] add cpu-add qmp command and implement CPU hot-add for target-i386 |
Date: |
Thu, 11 Apr 2013 16:51:58 +0200 |
... via current_machine->cpu_hot_add() hook called by cpu-set QMP command,
for x86 target.
cpu-add command usage will be descrbed at:
http://wiki.qemu.org/Features/CPUHotplug
Signed-off-by: Igor Mammedov <address@hidden>
---
v4:
* merge "qmp: add cpu-add qmp command" & "target-i386: implement CPU hot-add"
patches
* move notifier call to CPUCLass.realize()
* add hook cpu_hot_add to QEMUMachine
* make QEMUMachineInitArgs global and keep default cpu_model there
v3:
* it appears that 'online/offline' in cpu-set are confusing people
with what command actually does and users might have to distinguish
if 'offline' is not implemented by parsing error message. To simplify
things replace cpu-set with cpu-add command to show more clear what
command does and just add cpu-del when CPU remove is implemented.
v2:
* s/cpu_set/cpu-set/
* qmp doc style fix
* use bool type instead of opencodding online/offline string
suggested-by: Eric Blake <address@hidden>
---
hw/i386/pc.c | 20 ++++++++++++++++++++
include/hw/boards.h | 3 +++
qapi-schema.json | 11 +++++++++++
qmp-commands.hx | 23 +++++++++++++++++++++++
qmp.c | 10 ++++++++++
vl.c | 6 +++++-
6 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ada235c..ba93180 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -53,6 +53,7 @@
#include "qemu/bitmap.h"
#include "qemu/config-file.h"
#include "hw/i386/icc_bus.h"
+#include "hw/boards.h"
/* debug PC/ISA interrupts */
//#define DEBUG_IRQ
@@ -896,6 +897,23 @@ static X86CPU *pc_new_cpu(const char *cpu_model, int64_t
apic_id,
return cpu;
}
+static void do_cpu_hot_add(const int64_t id, Error **errp)
+{
+ if (cpu_exists(id)) {
+ error_setg(errp, "Unable to add CPU with APIC ID: 0x%" PRIx64
+ ", it already exists", id);
+ return;
+ }
+
+ if (id >= pc_apic_id_limit(max_cpus)) {
+ error_setg(errp, "Unable to add CPU with APIC ID: 0x%" PRIx64
+ ", max allowed: 0x%x", id, pc_apic_id_limit(max_cpus) - 1);
+ return;
+ }
+
+ pc_new_cpu(machine_args->cpu_model, id, NULL, errp);
+}
+
void pc_cpus_init(const char *cpu_model)
{
int i;
@@ -910,7 +928,9 @@ void pc_cpus_init(const char *cpu_model)
#else
cpu_model = "qemu32";
#endif
+ machine_args->cpu_model = cpu_model;
}
+ current_machine->hot_add_cpu = do_cpu_hot_add;
ib = SYS_BUS_DEVICE(object_resolve_path_type("icc-bridge",
TYPE_ICC_BRIDGE, NULL));
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 425bdc7..de8f92a 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -18,6 +18,8 @@ typedef struct QEMUMachineInitArgs {
const char *cpu_model;
} QEMUMachineInitArgs;
+extern QEMUMachineInitArgs *machine_args;
+
typedef void QEMUMachineInitFunc(QEMUMachineInitArgs *args);
typedef void QEMUMachineResetFunc(void);
@@ -43,6 +45,7 @@ typedef struct QEMUMachine {
GlobalProperty *compat_props;
struct QEMUMachine *next;
const char *hw_version;
+ void (*hot_add_cpu)(const int64_t id, Error **errp);
} QEMUMachine;
int qemu_register_machine(QEMUMachine *m);
diff --git a/qapi-schema.json b/qapi-schema.json
index db542f6..a760ed5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1387,6 +1387,17 @@
{ 'command': 'cpu', 'data': {'index': 'int'} }
##
+# @cpu-add
+#
+# Adds CPU with specified id
+#
+# @id: cpu id of CPU to be created
+#
+# Returns: Nothing on success
+##
+{ 'command': 'cpu-add', 'data': {'id': 'int'} }
+
+##
# @memsave:
#
# Save a portion of guest memory to a file.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 1e0e11e..79b2ba7 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -407,6 +407,29 @@ Example:
EQMP
{
+ .name = "cpu-add",
+ .args_type = "id:i",
+ .mhandler.cmd_new = qmp_marshal_input_cpu_add,
+ },
+
+SQMP
+cpu-add
+-------
+
+Adds virtual cpu
+
+Arguments:
+
+- "id": cpu id (json-int)
+
+Example:
+
+-> { "execute": "cpu-add", "arguments": { "id": 2 } }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "memsave",
.args_type = "val:l,size:i,filename:s,cpu:i?",
.mhandler.cmd_new = qmp_marshal_input_memsave,
diff --git a/qmp.c b/qmp.c
index 55b056b..8a9fd9e 100644
--- a/qmp.c
+++ b/qmp.c
@@ -24,6 +24,7 @@
#include "hw/qdev.h"
#include "sysemu/blockdev.h"
#include "qom/qom-qobject.h"
+#include "hw/boards.h"
NameInfo *qmp_query_name(Error **errp)
{
@@ -108,6 +109,15 @@ void qmp_cpu(int64_t index, Error **errp)
/* Just do nothing */
}
+void qmp_cpu_add(int64_t id, Error **errp)
+{
+ if (current_machine->hot_add_cpu) {
+ current_machine->hot_add_cpu(id, errp);
+ } else {
+ error_setg(errp, "Not supported");
+ }
+}
+
#ifndef CONFIG_VNC
/* If VNC support is enabled, the "true" query-vnc command is
defined in the VNC subsystem */
diff --git a/vl.c b/vl.c
index 21952c3..cdce08d 100644
--- a/vl.c
+++ b/vl.c
@@ -179,6 +179,8 @@ int main(int argc, char **argv)
#define MAX_VIRTIO_CONSOLES 1
#define MAX_SCLP_CONSOLES 1
+QEMUMachineInitArgs *machine_args;
+
static const char *data_dir[16];
static int data_dir_idx;
const char *bios_name = NULL;
@@ -4310,13 +4312,15 @@ int main(int argc, char **argv, char **envp)
.kernel_cmdline = kernel_cmdline,
.initrd_filename = initrd_filename,
.cpu_model = cpu_model };
+ machine_args = &args;
+ current_machine = machine;
+
machine->init(&args);
cpu_synchronize_all_post_init();
set_numa_modes();
- current_machine = machine;
/* init USB devices */
if (usb_enabled(false)) {
--
1.8.2
- [Qemu-devel] [PATCH 12/19] introduce ICC bus/device/bridge, (continued)
- [Qemu-devel] [PATCH 12/19] introduce ICC bus/device/bridge, Igor Mammedov, 2013/04/11
- [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Igor Mammedov, 2013/04/11
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Eduardo Habkost, 2013/04/11
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Igor Mammedov, 2013/04/12
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Eduardo Habkost, 2013/04/12
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Igor Mammedov, 2013/04/15
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Eduardo Habkost, 2013/04/15
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Igor Mammedov, 2013/04/15
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Eduardo Habkost, 2013/04/15
- Re: [Qemu-devel] [PATCH 18/19] target-i386: expose all possible CPUs as /machine/icc-bridge/cpu[0..N] links, Igor Mammedov, 2013/04/15
- [Qemu-devel] [PATCH 19/19] add cpu-add qmp command and implement CPU hot-add for target-i386,
Igor Mammedov <=