Skip to contentSkip to conversation

CPU hotplug port from qemu-traditionnal to qemu-xen for 4.3.

PATCH Superseded Anthony PERARD 4 participants 21 messages May 31, 2013 – Jun 3, 2013 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover CPU hotplug port from qemu-traditionnal to qemu-xen for 4.3.

Hi all,

This series ports few patches from qemu-xen-traditionnal to qemu-xen (upstream). There is as little modification as possible on those patches so they *can not* be upstream as is. So this is only for 4.3. A proper series will be done for 4.4.

There make possible to have CPU hotplug on qemu-xen.

A patch for libxl will follow, which make use of the old command line -vcpu_avail with qemu-xen. This command line will probably not be upstream.

BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

Regards,

Ian Jackson (4):
HVM vcpu add/remove: qemu logic for vcpu add/revmoe Fix vcpu hotplug bug: get correct vcpu_avail bitmap Update vcpu hotplug logic
Implement 'xm vcpu-set' command for HVM guest

 hmp-commands.hx |  9 ++++++
 hw/acpi_piix4.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 monitor.c       | 18 ++++++++++++
 qemu-options.hx |  3 ++
 sysemu.h        |  4 +++
 vl.c            | 55 ++++++++++++++++++++++++++++++++++++
 xen-all.c       | 65 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 241 insertions(+), 1 deletion(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH 1/4 HVM vcpu add/remove: qemu logic for vcpu add/revmoe

From: Ian Jackson <[email protected]>

-- at qemu side, get vcpu_avail which used for original cpu avail map; -- setup gpe ioread/iowrite at qmeu;
-- setup vcpu add/remove user interface through monitor;
-- setup SCI logic;

[ PATCH 4/4 ] HVM vcpu add/remove: qemu logic for vcpu add/revmoe

Port from qemu-xen-traditionnal to qemu-xen.

---
 hmp-commands.hx |  9 +++++++
 hw/acpi_piix4.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 monitor.c       | 18 ++++++++++++++
 qemu-options.hx |  3 +++
 sysemu.h        |  3 +++
 vl.c            |  6 +++++
 6 files changed, 113 insertions(+), 1 deletion(-)
hmp-commands.hx +9 -0
index 010b8c9..e92f173 100644
@@ -1581,3 +1581,12 @@ ETEXI
 STEXI
 @end table
 ETEXI
+
+HXCOMM TODO doc
+    {
+        .name       = "cpu_set",
+        .args_type  = "cpu_index:i,status:s",
+        .params     = "cpu [online|offline]",
+        .help       = "change cpu state",
+        .mhandler.cmd = do_cpu_set_nr,
+    },
hw/acpi_piix4.c +74 -1

115 lines not on this page · raw message

monitor.c +18 -0
index c0e32d6..564373c 100644
@@ -2421,6 +2421,24 @@ int monitor_handle_fd_param(Monitor *mon, const char *fdname)
     return fd;
 }
 
+static void do_cpu_set_nr(Monitor *mon, const QDict *qdict)
+{
+    int cpu_index = qdict_get_int(qdict, "cpu_index");
+    const char *status = qdict_get_str(qdict, "status");
+    int state;
+
+    if (!strcmp(status, "online")) {
+        state = 1;
+    } else if (!strcmp(status, "offline")) {
+        state = 0;
+    } else {
+        monitor_printf(mon, "invalid status: %s\n", status);
+        return;
+    }
+
+    qemu_cpu_add_remove(cpu_index, state);
+}
+
 /* mon_cmds and info_cmds would be sorted at runtime */
 static mon_cmd_t mon_cmds[] = {
 #include "hmp-commands.h"
qemu-options.hx +3 -0
index de43b1b..0ba668f 100644
@@ -94,6 +94,9 @@ given, the total number of CPUs @var{n} can be omitted. @var{maxcpus}
 specifies the maximum number of hotpluggable CPUs.
 ETEXI
 
+DEF("vcpu_avail", HAS_ARG, QEMU_OPTION_vcpu_avail,
+    "-vcpu_avail bitmap\n", QEMU_ARCH_ALL)
+
 DEF("numa", HAS_ARG, QEMU_OPTION_numa,
     "-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]\n", QEMU_ARCH_ALL)
 STEXI
sysemu.h +3 -0
index f5ac664..ed7b264 100644
@@ -149,6 +149,9 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
                       DriveInfo *dinfo, int type);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
 
+/* cpu hotplug */
+void qemu_cpu_add_remove(int cpu, int state);
+
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
vl.c +6 -0
index a3ab384..27ae6c1 100644
@@ -207,6 +207,7 @@ int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
 int max_cpus = 0;
+uint64_t vcpu_avail = 1;
 int smp_cores = 1;
 int smp_threads = 1;
 #ifdef CONFIG_VNC
@@ -3302,6 +3303,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_vcpu_avail:
+                vcpu_avail = atol(optarg);
+                fprintf(stderr, "qemu: the avail cpu bitmap is %lx\n",
+                        vcpu_avail);
+                break;
 	    case QEMU_OPTION_vnc:
 #ifdef CONFIG_VNC
                 display_remote++;
Signature · 1 line
Anthony PERARD
#2 lore raw

Re: [PATCH 1/4] HVM vcpu add/remove: qemu logic for vcpu add/revmoe

Quoted 28 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

-- at qemu side, get vcpu_avail which used for original cpu avail map; -- setup gpe ioread/iowrite at qmeu;
-- setup vcpu add/remove user interface through monitor;
-- setup SCI logic;

[ PATCH 4/4 ] HVM vcpu add/remove: qemu logic for vcpu add/revmoe

Port from qemu-xen-traditionnal to qemu-xen.

---
 hmp-commands.hx |  9 +++++++
 hw/acpi_piix4.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 monitor.c       | 18 ++++++++++++++
 qemu-options.hx |  3 +++
 sysemu.h        |  3 +++
 vl.c            |  6 +++++
 6 files changed, 113 insertions(+), 1 deletion(-)
hmp-commands.hx +0 -0
index 010b8c9..e92f173 100644

hmp-commands.hx ETEXI · line 1585

Quoted 5 lines
hmp-commands.hx +2 -0
@@ -1581,3 +1581,12 @@ ETEXI
 STEXI
 @end table
 ETEXI
+
+HXCOMM TODO doc

What is the TODO For?

Quoted 24 lines
hmp-commands.hx +7 -0
+    {
+        .name       = "cpu_set",
+        .args_type  = "cpu_index:i,status:s",
+        .params     = "cpu [online|offline]",
+        .help       = "change cpu state",
+        .mhandler.cmd = do_cpu_set_nr,
+    },
hw/acpi_piix4.c +3 -0
index 519269a..c73dc7c 100644
@@ -45,8 +45,11 @@
 #define PCI_DOWN_BASE 0xae04
 #define PCI_EJ_BASE 0xae08
 #define PCI_RMV_BASE 0xae0c
+/* ioport to monitor cpu add/remove status */
+#define PROC_BASE 0xaf00
 
 #define PIIX4_PCI_HOTPLUG_STATUS 2
+#define PIIX4_CPU_HOTPLUG_STATUS 4
 
 struct pci_status {
     uint32_t up; /* deprecated, maintained for migration compatibility */

hw/acpi_piix4.c typedef struct PIIX4PMState { · line 85

Quoted 6 lines
hw/acpi_piix4.c +3 -0
@@ -77,6 +80,9 @@ typedef struct PIIX4PMState {
     uint8_t disable_s3;
     uint8_t disable_s4;
     uint8_t s4_val;
+
+    /* CPU bitmap */
+    uint8_t cpus_sts[32];

Could we use a #define for it?

Quoted 72 lines
hw/acpi_piix4.c +41 -1
 } PIIX4PMState;
 
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -95,7 +101,7 @@ static void pm_update_sci(PIIX4PMState *s)
                    ACPI_BITMASK_GLOBAL_LOCK_ENABLE |
                    ACPI_BITMASK_TIMER_ENABLE)) != 0) ||
         (((s->ar.gpe.sts[0] & s->ar.gpe.en[0])
-          & PIIX4_PCI_HOTPLUG_STATUS) != 0);
+          & (PIIX4_PCI_HOTPLUG_STATUS|PIIX4_CPU_HOTPLUG_STATUS)) != 0);
 
     qemu_set_irq(s->irq, sci_level);
     /* schedule a timer interruption if needed */
@@ -602,11 +608,48 @@ static uint32_t pcirmv_read(void *opaque, uint32_t addr)
     return s->pci0_hotplug_enable;
 }
 
+static uint32_t gpe_cpus_readb(void *opaque, uint32_t addr)
+{
+    uint32_t val = 0;
+    PIIX4PMState *g = opaque;
+
+    switch (addr) {
+        case PROC_BASE ... PROC_BASE+31:
+            val = g->cpus_sts[addr - PROC_BASE];
+        default:
+            break;
+    }
+
+    return val;
+}
+
+static void gpe_cpus_writeb(void *opaque, uint32_t addr, uint32_t val)
+{
+    switch (addr) {
+        case PROC_BASE ... PROC_BASE + 31:
+            /* don't allow to change cpus_sts from inside a guest */
+            break;
+        default:
+            break;
+    }
+}
+
 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
                                 PCIHotplugState state);
 
+extern uint64_t vcpu_avail;
+static PIIX4PMState *acpi_state;
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 {
+    int i = 0, cpus = max_cpus;
+    char *vcpumap = (char *)&vcpu_avail;
+
+    while (cpus > 0) {
+        s->cpus_sts[i] = vcpumap[i];
+        i++;
+        cpus -= 8;
+    }
+    acpi_state = s;
 
     register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s);
     register_ioport_read(GPE_BASE, GPE_LEN, 1,  gpe_readb, s);
@@ -620,6 +663,9 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 
     register_ioport_read(PCI_RMV_BASE, 4, 4,  pcirmv_read, s);
 
+    register_ioport_read(PROC_BASE, 32, 1,  gpe_cpus_readb, s);
+    register_ioport_write(PROC_BASE, 32, 1, gpe_cpus_writeb, s);
+
     pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
 }
 

hw/acpi_piix4.c static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, · line 713

Quoted 8 lines
hw/acpi_piix4.c +5 -0
@@ -660,3 +706,30 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
 
     return 0;
 }
+
+static void enable_processor(PIIX4PMState *g, int cpu)
+{
+    g->ar.gpe.sts[0] |= 4;
+    g->cpus_sts[cpu/8] |= (1 << (cpu%8));

Is the StyleGuide OK with that? Or should it have a space in front and in the back of "/" and "%" ?

hw/acpi_piix4.c static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, · line 719

Quoted 6 lines
hw/acpi_piix4.c +6 -0
+}
+
+static void disable_processor(PIIX4PMState *g, int cpu)
+{
+    g->ar.gpe.sts[0] |= 4;
+    g->cpus_sts[cpu/8] &= ~(1 << (cpu%8));

Ditto.

Quoted 106 lines
hw/acpi_piix4.c +16 -0
+}
+
+void qemu_cpu_add_remove(int cpu, int state)
+{
+    if ((cpu <=0) || (cpu >= max_cpus)) {
+        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+        return;
+    }
+
+    if (state)
+        enable_processor(acpi_state, cpu);
+    else
+        disable_processor(acpi_state, cpu);
+
+    pm_update_sci(acpi_state);
+}
monitor.c +18 -0
index c0e32d6..564373c 100644
@@ -2421,6 +2421,24 @@ int monitor_handle_fd_param(Monitor *mon, const char *fdname)
     return fd;
 }
 
+static void do_cpu_set_nr(Monitor *mon, const QDict *qdict)
+{
+    int cpu_index = qdict_get_int(qdict, "cpu_index");
+    const char *status = qdict_get_str(qdict, "status");
+    int state;
+
+    if (!strcmp(status, "online")) {
+        state = 1;
+    } else if (!strcmp(status, "offline")) {
+        state = 0;
+    } else {
+        monitor_printf(mon, "invalid status: %s\n", status);
+        return;
+    }
+
+    qemu_cpu_add_remove(cpu_index, state);
+}
+
 /* mon_cmds and info_cmds would be sorted at runtime */
 static mon_cmd_t mon_cmds[] = {
 #include "hmp-commands.h"
qemu-options.hx +3 -0
index de43b1b..0ba668f 100644
@@ -94,6 +94,9 @@ given, the total number of CPUs @var{n} can be omitted. @var{maxcpus}
 specifies the maximum number of hotpluggable CPUs.
 ETEXI
 
+DEF("vcpu_avail", HAS_ARG, QEMU_OPTION_vcpu_avail,
+    "-vcpu_avail bitmap\n", QEMU_ARCH_ALL)
+
 DEF("numa", HAS_ARG, QEMU_OPTION_numa,
     "-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]\n", QEMU_ARCH_ALL)
 STEXI
sysemu.h +3 -0
index f5ac664..ed7b264 100644
@@ -149,6 +149,9 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
                       DriveInfo *dinfo, int type);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
 
+/* cpu hotplug */
+void qemu_cpu_add_remove(int cpu, int state);
+
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
vl.c +6 -0
index a3ab384..27ae6c1 100644
@@ -207,6 +207,7 @@ int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
 int max_cpus = 0;
+uint64_t vcpu_avail = 1;
 int smp_cores = 1;
 int smp_threads = 1;
 #ifdef CONFIG_VNC
@@ -3302,6 +3303,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_vcpu_avail:
+                vcpu_avail = atol(optarg);
+                fprintf(stderr, "qemu: the avail cpu bitmap is %lx\n",
+                        vcpu_avail);
+                break;
 	    case QEMU_OPTION_vnc:
 #ifdef CONFIG_VNC
                 display_remote++;
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#3 lore raw

Re: [PATCH 1/4] HVM vcpu add/remove: qemu logic for vcpu add/revmoe

In reply to Anthony PERARD
Quoted 144 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

-- at qemu side, get vcpu_avail which used for original cpu avail map; -- setup gpe ioread/iowrite at qmeu;
-- setup vcpu add/remove user interface through monitor;
-- setup SCI logic;

[ PATCH 4/4 ] HVM vcpu add/remove: qemu logic for vcpu add/revmoe

Port from qemu-xen-traditionnal to qemu-xen.

---
 hmp-commands.hx |  9 +++++++
 hw/acpi_piix4.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 monitor.c       | 18 ++++++++++++++
 qemu-options.hx |  3 +++
 sysemu.h        |  3 +++
 vl.c            |  6 +++++
 6 files changed, 113 insertions(+), 1 deletion(-)
hmp-commands.hx +9 -0
index 010b8c9..e92f173 100644
@@ -1581,3 +1581,12 @@ ETEXI
 STEXI
 @end table
 ETEXI
+
+HXCOMM TODO doc
+    {
+        .name       = "cpu_set",
+        .args_type  = "cpu_index:i,status:s",
+        .params     = "cpu [online|offline]",
+        .help       = "change cpu state",
+        .mhandler.cmd = do_cpu_set_nr,
+    },
hw/acpi_piix4.c +53 -1
index 519269a..c73dc7c 100644
@@ -45,8 +45,11 @@
 #define PCI_DOWN_BASE 0xae04
 #define PCI_EJ_BASE 0xae08
 #define PCI_RMV_BASE 0xae0c
+/* ioport to monitor cpu add/remove status */
+#define PROC_BASE 0xaf00
 
 #define PIIX4_PCI_HOTPLUG_STATUS 2
+#define PIIX4_CPU_HOTPLUG_STATUS 4
 
 struct pci_status {
     uint32_t up; /* deprecated, maintained for migration compatibility */
@@ -77,6 +80,9 @@ typedef struct PIIX4PMState {
     uint8_t disable_s3;
     uint8_t disable_s4;
     uint8_t s4_val;
+
+    /* CPU bitmap */
+    uint8_t cpus_sts[32];
 } PIIX4PMState;
 
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
@@ -95,7 +101,7 @@ static void pm_update_sci(PIIX4PMState *s)
                    ACPI_BITMASK_GLOBAL_LOCK_ENABLE |
                    ACPI_BITMASK_TIMER_ENABLE)) != 0) ||
         (((s->ar.gpe.sts[0] & s->ar.gpe.en[0])
-          & PIIX4_PCI_HOTPLUG_STATUS) != 0);
+          & (PIIX4_PCI_HOTPLUG_STATUS|PIIX4_CPU_HOTPLUG_STATUS)) != 0);
 
     qemu_set_irq(s->irq, sci_level);
     /* schedule a timer interruption if needed */
@@ -602,11 +608,48 @@ static uint32_t pcirmv_read(void *opaque, uint32_t addr)
     return s->pci0_hotplug_enable;
 }
 
+static uint32_t gpe_cpus_readb(void *opaque, uint32_t addr)
+{
+    uint32_t val = 0;
+    PIIX4PMState *g = opaque;
+
+    switch (addr) {
+        case PROC_BASE ... PROC_BASE+31:
+            val = g->cpus_sts[addr - PROC_BASE];
+        default:
+            break;
+    }
+
+    return val;
+}
+
+static void gpe_cpus_writeb(void *opaque, uint32_t addr, uint32_t val)
+{
+    switch (addr) {
+        case PROC_BASE ... PROC_BASE + 31:
+            /* don't allow to change cpus_sts from inside a guest */
+            break;
+        default:
+            break;
+    }
+}
+
 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
                                 PCIHotplugState state);
 
+extern uint64_t vcpu_avail;
+static PIIX4PMState *acpi_state;
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 {
+    int i = 0, cpus = max_cpus;
+    char *vcpumap = (char *)&vcpu_avail;
+
+    while (cpus > 0) {
+        s->cpus_sts[i] = vcpumap[i];
+        i++;
+        cpus -= 8;
+    }
+    acpi_state = s;
 
     register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s);
     register_ioport_read(GPE_BASE, GPE_LEN, 1,  gpe_readb, s);
@@ -620,6 +663,9 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 
     register_ioport_read(PCI_RMV_BASE, 4, 4,  pcirmv_read, s);
 
+    register_ioport_read(PROC_BASE, 32, 1,  gpe_cpus_readb, s);
+    register_ioport_write(PROC_BASE, 32, 1, gpe_cpus_writeb, s);
+
     pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
 }
 
@@ -660,3 +706,30 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
 
     return 0;
 }
+
+static void enable_processor(PIIX4PMState *g, int cpu)
+{
+    g->ar.gpe.sts[0] |= 4;
+    g->cpus_sts[cpu/8] |= (1 << (cpu%8));
+}

hw/acpi_piix4.c static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, · line 724

Quoted 10 lines
hw/acpi_piix4.c +10 -0
+
+static void disable_processor(PIIX4PMState *g, int cpu)
+{
+    g->ar.gpe.sts[0] |= 4;
+    g->cpus_sts[cpu/8] &= ~(1 << (cpu%8));
+}
+
+void qemu_cpu_add_remove(int cpu, int state)
+{
+    if ((cpu <=0) || (cpu >= max_cpus)) {

the original code has cpu < 0

hw/acpi_piix4.c static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, · line 735

Quoted 11 lines
hw/acpi_piix4.c +11 -0
+        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+        return;
+    }
+
+    if (state)
+        enable_processor(acpi_state, cpu);
+    else
+        disable_processor(acpi_state, cpu);
+
+    pm_update_sci(acpi_state);
+}

This is also different, the code we have on qemu-xen-unstable is:

if (gpe_state.gpe0_en[0] & 4) {
        qemu_set_irq(sci_irq, 1);
        qemu_set_irq(sci_irq, 0);
}

what's the reason for the change?

If possible, it would be better to port a QMP command for vcpu hotplug to avoid compatibility problems, so I would get rid of the code below

Quoted 81 lines
monitor.c +18 -0
index c0e32d6..564373c 100644
@@ -2421,6 +2421,24 @@ int monitor_handle_fd_param(Monitor *mon, const char *fdname)
     return fd;
 }
 
+static void do_cpu_set_nr(Monitor *mon, const QDict *qdict)
+{
+    int cpu_index = qdict_get_int(qdict, "cpu_index");
+    const char *status = qdict_get_str(qdict, "status");
+    int state;
+
+    if (!strcmp(status, "online")) {
+        state = 1;
+    } else if (!strcmp(status, "offline")) {
+        state = 0;
+    } else {
+        monitor_printf(mon, "invalid status: %s\n", status);
+        return;
+    }
+
+    qemu_cpu_add_remove(cpu_index, state);
+}
+
 /* mon_cmds and info_cmds would be sorted at runtime */
 static mon_cmd_t mon_cmds[] = {
 #include "hmp-commands.h"
qemu-options.hx +3 -0
index de43b1b..0ba668f 100644
@@ -94,6 +94,9 @@ given, the total number of CPUs @var{n} can be omitted. @var{maxcpus}
 specifies the maximum number of hotpluggable CPUs.
 ETEXI
 
+DEF("vcpu_avail", HAS_ARG, QEMU_OPTION_vcpu_avail,
+    "-vcpu_avail bitmap\n", QEMU_ARCH_ALL)
+
 DEF("numa", HAS_ARG, QEMU_OPTION_numa,
     "-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]\n", QEMU_ARCH_ALL)
 STEXI
sysemu.h +3 -0
index f5ac664..ed7b264 100644
@@ -149,6 +149,9 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
                       DriveInfo *dinfo, int type);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
 
+/* cpu hotplug */
+void qemu_cpu_add_remove(int cpu, int state);
+
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
vl.c +6 -0
index a3ab384..27ae6c1 100644
@@ -207,6 +207,7 @@ int win2k_install_hack = 0;
 int singlestep = 0;
 int smp_cpus = 1;
 int max_cpus = 0;
+uint64_t vcpu_avail = 1;
 int smp_cores = 1;
 int smp_threads = 1;
 #ifdef CONFIG_VNC
@@ -3302,6 +3303,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_vcpu_avail:
+                vcpu_avail = atol(optarg);
+                fprintf(stderr, "qemu: the avail cpu bitmap is %lx\n",
+                        vcpu_avail);
+                break;
 	    case QEMU_OPTION_vnc:
 #ifdef CONFIG_VNC
                 display_remote++;
#4 lore raw

PATCH 2/4 Fix vcpu hotplug bug: get correct vcpu_avail bitmap

In reply to Anthony PERARD

From: Ian Jackson <[email protected]>

Currently qemu has a bug: When maxvcpus > 64, qemu will get wrong vcpu bitmap (s->cpus_sts[i]) since it only get bitmap from a long variable.

This patch, cooperate with another xend python patch, is to fix this bug. This patch get hex string from xend, transfer it to correct vcpu_avail bitmap which saved at an uint32_t array.

(This is [PATCH 2/2], the other half is in xen-unstable.hg)

Port from qemu-xen-traditionnal to qemu-xen.

---
 hw/acpi_piix4.c |  3 +--
 sysemu.h        |  1 +
 vl.c            | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 55 insertions(+), 6 deletions(-)
hw/acpi_piix4.c +1 -2
index c73dc7c..bc7b454 100644
@@ -637,12 +637,11 @@ static void gpe_cpus_writeb(void *opaque, uint32_t addr, uint32_t val)
 static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
                                 PCIHotplugState state);
 
-extern uint64_t vcpu_avail;
 static PIIX4PMState *acpi_state;
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 {
     int i = 0, cpus = max_cpus;
-    char *vcpumap = (char *)&vcpu_avail;
+    char *vcpumap = (char *)vcpu_avail;
 
     while (cpus > 0) {
         s->cpus_sts[i] = vcpumap[i];
sysemu.h +1 -0
index ed7b264..5789158 100644
@@ -113,6 +113,7 @@ extern int alt_grab;
 extern int ctrl_grab;
 extern int smp_cpus;
 extern int max_cpus;
+extern uint32_t vcpu_avail[];
 extern int cursor_hide;
 extern int graphic_rotate;
 extern int no_quit;
vl.c +53 -4

81 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
#5 lore raw

PATCH 3/4 Update vcpu hotplug logic

In reply to Anthony PERARD

From: Ian Jackson <[email protected]>

Add vcpu online/offline check to avoid redundant SCI interrupt.

Port from qemu-xen-traditionnal to qemu-xen.

---
 hw/acpi_piix4.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
hw/acpi_piix4.c +19 -6
index bc7b454..49c38d3 100644
@@ -706,16 +706,24 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
     return 0;
 }
 
-static void enable_processor(PIIX4PMState *g, int cpu)
+static int enable_processor(PIIX4PMState *g, int cpu)
 {
+    if (g->cpus_sts[cpu/8] & (1 << (cpu%8)))
+        return 0;
+
     g->ar.gpe.sts[0] |= 4;
     g->cpus_sts[cpu/8] |= (1 << (cpu%8));
+    return 1;
 }
 
-static void disable_processor(PIIX4PMState *g, int cpu)
+static int disable_processor(PIIX4PMState *g, int cpu)
 {
+    if (!(g->cpus_sts[cpu/8] & (1 << (cpu%8))))
+        return 0;
+
     g->ar.gpe.sts[0] |= 4;
     g->cpus_sts[cpu/8] &= ~(1 << (cpu%8));
+    return 1;
 }
 
 void qemu_cpu_add_remove(int cpu, int state)
@@ -725,10 +733,15 @@ void qemu_cpu_add_remove(int cpu, int state)
         return;
     }
 
-    if (state)
-        enable_processor(acpi_state, cpu);
-    else
-        disable_processor(acpi_state, cpu);
+    if (state) {
+        if (!enable_processor(acpi_state, cpu)) {
+            return;
+        }
+    } else {
+        if (!disable_processor(acpi_state, cpu)) {
+            return;
+        }
+    }
 
     pm_update_sci(acpi_state);
 }
Signature · 1 line
Anthony PERARD
Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] Update vcpu hotplug logic

Quoted 8 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

Add vcpu online/offline check to avoid redundant SCI interrupt.

Port from qemu-xen-traditionnal to qemu-xen.

.. some notes below.

Quoted 9 lines
---
 hw/acpi_piix4.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
hw/acpi_piix4.c +0 -0
index bc7b454..49c38d3 100644

hw/acpi_piix4.c static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, · line 712

Quoted 8 lines
hw/acpi_piix4.c +3 -1
@@ -706,16 +706,24 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
     return 0;
 }
 
-static void enable_processor(PIIX4PMState *g, int cpu)
+static int enable_processor(PIIX4PMState *g, int cpu)
 {
+    if (g->cpus_sts[cpu/8] & (1 << (cpu%8)))
+        return 0;

Don't know if the styleguide in QEME is at this point, but I thought that it was suppose to have space between the "/" and "%", so you have:

    if (g->cpus_sts[cpu / 8] & (1 << (cpu % 8)))

?

Quoted 47 lines
hw/acpi_piix4.c +16 -5
+
     g->ar.gpe.sts[0] |= 4;
     g->cpus_sts[cpu/8] |= (1 << (cpu%8));
+    return 1;
 }
 
-static void disable_processor(PIIX4PMState *g, int cpu)
+static int disable_processor(PIIX4PMState *g, int cpu)
 {
+    if (!(g->cpus_sts[cpu/8] & (1 << (cpu%8))))
+        return 0;
+
     g->ar.gpe.sts[0] |= 4;
     g->cpus_sts[cpu/8] &= ~(1 << (cpu%8));
+    return 1;
 }
 
 void qemu_cpu_add_remove(int cpu, int state)
@@ -725,10 +733,15 @@ void qemu_cpu_add_remove(int cpu, int state)
         return;
     }
 
-    if (state)
-        enable_processor(acpi_state, cpu);
-    else
-        disable_processor(acpi_state, cpu);
+    if (state) {
+        if (!enable_processor(acpi_state, cpu)) {
+            return;
+        }
+    } else {
+        if (!disable_processor(acpi_state, cpu)) {
+            return;
+        }
+    }
 
     pm_update_sci(acpi_state);
 }
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw

PATCH 4/4 Implement 'xm vcpu-set' command for HVM guest

In reply to Anthony PERARD

From: Ian Jackson <[email protected]>

Currently Xen has 'xm vcpu-set' command for PV domain, but not available for HVM domain. This patch is use to enable 'xm vcpu-set' command for HVM domain. It setup vcpu watch at xenstore, and at qemu side, handle vcpu online/offline accordingly. With this patch, 'xm vcpu-set' command works for both PV and HVM guest with same format.

Port from qemu-xen-traditionnal to qemu-xen:
qemu-xen does not support anymore command through xenstore, so this path include an initialisation of a xenstore loop.
An upstream of this patch would need to go QMP.

---
 hw/acpi_piix4.c |  5 +++--
 xen-all.c       | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
hw/acpi_piix4.c +3 -2
index 49c38d3..4c01aa2 100644
@@ -728,8 +728,8 @@ static int disable_processor(PIIX4PMState *g, int cpu)
 
 void qemu_cpu_add_remove(int cpu, int state)
 {
-    if ((cpu <=0) || (cpu >= max_cpus)) {
-        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+    if ((cpu < 0) || (cpu >= max_cpus)) {
+        fprintf(stderr, "vcpu out of range, should be [0~%d]\n", max_cpus - 1);
         return;
     }
 
@@ -742,6 +742,7 @@ void qemu_cpu_add_remove(int cpu, int state)
             return;
         }
     }
+    fprintf(stderr, "%s vcpu %d\n", state ? "Add" : "Remove", cpu);
 
     pm_update_sci(acpi_state);
 }
xen-all.c +65 -0

80 lines not on this page · raw message

Signature · 1 line
Anthony PERARD
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] Implement 'xm vcpu-set' command for HVM guest

Quoted 8 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

Currently Xen has 'xm vcpu-set' command for PV domain, but not available for HVM domain. This patch is use to enable 'xm vcpu-set' command for HVM domain. It setup vcpu watch at xenstore, and at qemu side, handle vcpu online/offline accordingly. With this patch, 'xm vcpu-set' command works for both PV and HVM guest with same format.

Quoted 8 lines

Port from qemu-xen-traditionnal to qemu-xen:
qemu-xen does not support anymore command through xenstore, so this path include an initialisation of a xenstore loop.
An upstream of this patch would need to go QMP.

Quoted 124 lines
---
 hw/acpi_piix4.c |  5 +++--
 xen-all.c       | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
hw/acpi_piix4.c +3 -2
index 49c38d3..4c01aa2 100644
@@ -728,8 +728,8 @@ static int disable_processor(PIIX4PMState *g, int cpu)
 
 void qemu_cpu_add_remove(int cpu, int state)
 {
-    if ((cpu <=0) || (cpu >= max_cpus)) {
-        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+    if ((cpu < 0) || (cpu >= max_cpus)) {
+        fprintf(stderr, "vcpu out of range, should be [0~%d]\n", max_cpus - 1);
         return;
     }
 
@@ -742,6 +742,7 @@ void qemu_cpu_add_remove(int cpu, int state)
             return;
         }
     }
+    fprintf(stderr, "%s vcpu %d\n", state ? "Add" : "Remove", cpu);
 
     pm_update_sci(acpi_state);
 }
xen-all.c +65 -0
index daf43b9..04b88a6 100644
@@ -99,6 +99,8 @@ typedef struct XenIOState {
     Notifier suspend;
 } XenIOState;
 
+static void xen_xenstore_watch_vcpu_set(XenIOState *state);
+
 /* Xen specific function for piix pci */
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -1170,6 +1172,7 @@ int xen_hvm_init(void)
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
     xen_read_physmap(state);
+    xen_xenstore_watch_vcpu_set(state);
 
     return 0;
 }
@@ -1234,3 +1237,65 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
         }
     }
 }
+
+/* Xenstore watch init for vcpu-set */
+
+static void xenstore_process_vcpu_set_event(char **vec, struct xs_handle *xsh)
+{
+    char *act = NULL;
+    char *vcpustr, *node = vec[XS_WATCH_PATH];
+    unsigned int vcpu, len;
+
+    vcpustr = strstr(node, "cpu/");
+    if (!vcpustr) {
+        fprintf(stderr, "vcpu-set: watch node error.\n");
+        return;
+    }
+    sscanf(vcpustr, "cpu/%u", &vcpu);
+
+    act = xs_read(xsh, XBT_NULL, node, &len);
+    if (!act) {
+        fprintf(stderr, "vcpu-set: no command yet.\n");
+        return;
+    }
+
+    if (!strncmp(act, "online", len))
+        qemu_cpu_add_remove(vcpu, 1);
+    else if (!strncmp(act, "offline", len))
+        qemu_cpu_add_remove(vcpu, 0);
+    else
+        fprintf(stderr, "vcpu-set: command error.\n");
+
+    free(act);
+    return;
+}
+
+static void xenstore_process_event(void *opaque)
+{
+    char **vec;
+    unsigned int num;
+    struct xs_handle *xsh = opaque;
+
+    vec = xs_read_watch(xsh, &num);
+    if (!vec)
+        return;
+
+    if (!strcmp(vec[XS_WATCH_TOKEN], "vcpu-set")) {
+        xenstore_process_vcpu_set_event(vec, xsh);
+        goto out;
+    }
+
+ out:
+    free(vec);
+}
+
+static void xen_xenstore_watch_vcpu_set(XenIOState *state)
+{
+    char path[40];
+    /* Set a watch for vcpu-set */
+    snprintf(path, sizeof(path), "/local/domain/%d/cpu", xen_domid);
+    xs_watch(state->xenstore, path, "vcpu-set");
+
+    qemu_set_fd_handler(xs_fileno(state->xenstore), xenstore_process_event,
+                        NULL, state->xenstore);
+}
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#9 lore raw

Re: [PATCH 4/4] Implement 'xm vcpu-set' command for HVM guest

In reply to Anthony PERARD
Quoted 8 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

Currently Xen has 'xm vcpu-set' command for PV domain, but not available for HVM domain. This patch is use to enable 'xm vcpu-set' command for HVM domain. It setup vcpu watch at xenstore, and at qemu side, handle vcpu online/offline accordingly. With this patch, 'xm vcpu-set' command works for both PV and HVM guest with same format.

Quoted 6 lines

Port from qemu-xen-traditionnal to qemu-xen:
qemu-xen does not support anymore command through xenstore, so this path include an initialisation of a xenstore loop.
An upstream of this patch would need to go QMP.

Because of this forward port the title is inaccurate, since this doesn't do anything for xm and only xl, right?

How much of the original patch is actually left?

BTW, for forward (or backward) ports including the original changeset ID in the new comment is very useful.

Quoted 22 lines
---
 hw/acpi_piix4.c |  5 +++--
 xen-all.c       | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
hw/acpi_piix4.c +2 -2
index 49c38d3..4c01aa2 100644
@@ -728,8 +728,8 @@ static int disable_processor(PIIX4PMState *g, int cpu)
 
 void qemu_cpu_add_remove(int cpu, int state)
 {
-    if ((cpu <=0) || (cpu >= max_cpus)) {
-        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+    if ((cpu < 0) || (cpu >= max_cpus)) {
+        fprintf(stderr, "vcpu out of range, should be [0~%d]\n", max_cpus - 1);
         return;
     }
 

hw/acpi_piix4.c void qemu_cpu_add_remove(int cpu, int state) · line 745

Quoted 4 lines
hw/acpi_piix4.c +1 -0
@@ -742,6 +742,7 @@ void qemu_cpu_add_remove(int cpu, int state)
             return;
         }
     }
+    fprintf(stderr, "%s vcpu %d\n", state ? "Add" : "Remove", cpu);

Is this left over debugging?

Quoted 89 lines
hw/acpi_piix4.c +0 -0
     pm_update_sci(acpi_state);
 }
xen-all.c +65 -0
index daf43b9..04b88a6 100644
@@ -99,6 +99,8 @@ typedef struct XenIOState {
     Notifier suspend;
 } XenIOState;
 
+static void xen_xenstore_watch_vcpu_set(XenIOState *state);
+
 /* Xen specific function for piix pci */
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -1170,6 +1172,7 @@ int xen_hvm_init(void)
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
     xen_read_physmap(state);
+    xen_xenstore_watch_vcpu_set(state);
 
     return 0;
 }
@@ -1234,3 +1237,65 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
         }
     }
 }
+
+/* Xenstore watch init for vcpu-set */
+
+static void xenstore_process_vcpu_set_event(char **vec, struct xs_handle *xsh)
+{
+    char *act = NULL;
+    char *vcpustr, *node = vec[XS_WATCH_PATH];
+    unsigned int vcpu, len;
+
+    vcpustr = strstr(node, "cpu/");
+    if (!vcpustr) {
+        fprintf(stderr, "vcpu-set: watch node error.\n");
+        return;
+    }
+    sscanf(vcpustr, "cpu/%u", &vcpu);
+
+    act = xs_read(xsh, XBT_NULL, node, &len);
+    if (!act) {
+        fprintf(stderr, "vcpu-set: no command yet.\n");
+        return;
+    }
+
+    if (!strncmp(act, "online", len))
+        qemu_cpu_add_remove(vcpu, 1);
+    else if (!strncmp(act, "offline", len))
+        qemu_cpu_add_remove(vcpu, 0);
+    else
+        fprintf(stderr, "vcpu-set: command error.\n");
+
+    free(act);
+    return;
+}
+
+static void xenstore_process_event(void *opaque)
+{
+    char **vec;
+    unsigned int num;
+    struct xs_handle *xsh = opaque;
+
+    vec = xs_read_watch(xsh, &num);
+    if (!vec)
+        return;
+
+    if (!strcmp(vec[XS_WATCH_TOKEN], "vcpu-set")) {
+        xenstore_process_vcpu_set_event(vec, xsh);
+        goto out;
+    }
+
+ out:
+    free(vec);
+}
+
+static void xen_xenstore_watch_vcpu_set(XenIOState *state)
+{
+    char path[40];
+    /* Set a watch for vcpu-set */
+    snprintf(path, sizeof(path), "/local/domain/%d/cpu", xen_domid);
+    xs_watch(state->xenstore, path, "vcpu-set");
+
+    qemu_set_fd_handler(xs_fileno(state->xenstore), xenstore_process_event,
+                        NULL, state->xenstore);
+}
#10 lore raw

Re: [PATCH 4/4] Implement 'xm vcpu-set' command for HVM guest

In reply to Anthony PERARD
Quoted 26 lines · Anthony PERARD

From: Ian Jackson <[email protected]>

Currently Xen has 'xm vcpu-set' command for PV domain, but not available for HVM domain. This patch is use to enable 'xm vcpu-set' command for HVM domain. It setup vcpu watch at xenstore, and at qemu side, handle vcpu online/offline accordingly. With this patch, 'xm vcpu-set' command works for both PV and HVM guest with same format.

Port from qemu-xen-traditionnal to qemu-xen:
qemu-xen does not support anymore command through xenstore, so this path include an initialisation of a xenstore loop.
An upstream of this patch would need to go QMP.

---
 hw/acpi_piix4.c |  5 +++--
 xen-all.c       | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)
hw/acpi_piix4.c +0 -0
index 49c38d3..4c01aa2 100644

hw/acpi_piix4.c static int disable_processor(PIIX4PMState *g, int cpu) · line 734

Quoted 9 lines
hw/acpi_piix4.c +2 -2
@@ -728,8 +728,8 @@ static int disable_processor(PIIX4PMState *g, int cpu)
 
 void qemu_cpu_add_remove(int cpu, int state)
 {
-    if ((cpu <=0) || (cpu >= max_cpus)) {
-        fprintf(stderr, "vcpu out of range, should be [1~%d]\n", max_cpus - 1);
+    if ((cpu < 0) || (cpu >= max_cpus)) {
+        fprintf(stderr, "vcpu out of range, should be [0~%d]\n", max_cpus - 1);
         return;
     }

I see where this change is coming from now but..

hw/acpi_piix4.c void qemu_cpu_add_remove(int cpu, int state) · line 748

Quoted 8 lines
hw/acpi_piix4.c +1 -0
@@ -742,6 +742,7 @@ void qemu_cpu_add_remove(int cpu, int state)
             return;
         }
     }
+    fprintf(stderr, "%s vcpu %d\n", state ? "Add" : "Remove", cpu);
 
     pm_update_sci(acpi_state);
 }

..the pm_update_sci is still in place

Quoted 90 lines
xen-all.c +65 -0
index daf43b9..04b88a6 100644
@@ -99,6 +99,8 @@ typedef struct XenIOState {
     Notifier suspend;
 } XenIOState;
 
+static void xen_xenstore_watch_vcpu_set(XenIOState *state);
+
 /* Xen specific function for piix pci */
 
 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
@@ -1170,6 +1172,7 @@ int xen_hvm_init(void)
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
     xen_read_physmap(state);
+    xen_xenstore_watch_vcpu_set(state);
 
     return 0;
 }
@@ -1234,3 +1237,65 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
         }
     }
 }
+
+/* Xenstore watch init for vcpu-set */
+
+static void xenstore_process_vcpu_set_event(char **vec, struct xs_handle *xsh)
+{
+    char *act = NULL;
+    char *vcpustr, *node = vec[XS_WATCH_PATH];
+    unsigned int vcpu, len;
+
+    vcpustr = strstr(node, "cpu/");
+    if (!vcpustr) {
+        fprintf(stderr, "vcpu-set: watch node error.\n");
+        return;
+    }
+    sscanf(vcpustr, "cpu/%u", &vcpu);
+
+    act = xs_read(xsh, XBT_NULL, node, &len);
+    if (!act) {
+        fprintf(stderr, "vcpu-set: no command yet.\n");
+        return;
+    }
+
+    if (!strncmp(act, "online", len))
+        qemu_cpu_add_remove(vcpu, 1);
+    else if (!strncmp(act, "offline", len))
+        qemu_cpu_add_remove(vcpu, 0);
+    else
+        fprintf(stderr, "vcpu-set: command error.\n");
+
+    free(act);
+    return;
+}
+
+static void xenstore_process_event(void *opaque)
+{
+    char **vec;
+    unsigned int num;
+    struct xs_handle *xsh = opaque;
+
+    vec = xs_read_watch(xsh, &num);
+    if (!vec)
+        return;
+
+    if (!strcmp(vec[XS_WATCH_TOKEN], "vcpu-set")) {
+        xenstore_process_vcpu_set_event(vec, xsh);
+        goto out;
+    }
+
+ out:
+    free(vec);
+}
+
+static void xen_xenstore_watch_vcpu_set(XenIOState *state)
+{
+    char path[40];
+    /* Set a watch for vcpu-set */
+    snprintf(path, sizeof(path), "/local/domain/%d/cpu", xen_domid);
+    xs_watch(state->xenstore, path, "vcpu-set");
+
+    qemu_set_fd_handler(xs_fileno(state->xenstore), xenstore_process_event,
+                        NULL, state->xenstore);
+}
Signature · 1 line
Anthony PERARD
#11 lore raw

PATCH 1/1 libxl: Use -vcpu_avail with qemu-xen.

In reply to Anthony PERARD

This require the series CPU hotplug for qemu-xen.

Note: this patch is valid only for 4.3 as the -vcpu_avail will probably not be upstream to Qemu.

---
 tools/libxl/libxl_dm.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/libxl/libxl_dm.c +6 -0
index 1e3a9f4..2db2372 100644
@@ -530,11 +530,17 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
             flexarray_append(dm_args, "-smp");
             if (b_info->avail_vcpus.size) {
                 int nr_set_cpus = 0;
+                char *s;
                 nr_set_cpus = libxl_bitmap_count_set(&b_info->avail_vcpus);
 
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d,maxcpus=%d",
                                                          nr_set_cpus,
                                                          b_info->max_vcpus));
+                
+                s = libxl_bitmap_to_hex_string(CTX, &b_info->avail_vcpus);
+                flexarray_vappend(dm_args, "-vcpu_avail",
+                                  libxl__sprintf(gc, "%s", s), NULL);
+                free(s);
             } else
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d",
                                                          b_info->max_vcpus));
Signature · 1 line
Anthony PERARD
#12 lore raw

Re: [PATCH] libxl: Use -vcpu_avail with qemu-xen.

Quoted 4 lines · Anthony PERARD

This require the series CPU hotplug for qemu-xen.

Note: this patch is valid only for 4.3 as the -vcpu_avail will probably not be upstream to Qemu.

Ugh. So how are we going to handle this in the future? libxl ideally needs to work with upstream qemu or our qemu seamlessly, which would mean needed to know whether to use -vcpu_avail vs. whatever upstream has. I'd much prefer to make our qemu export the same interface and use that...

Quoted 28 lines
---
 tools/libxl/libxl_dm.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/libxl/libxl_dm.c +6 -0
index 1e3a9f4..2db2372 100644
@@ -530,11 +530,17 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
             flexarray_append(dm_args, "-smp");
             if (b_info->avail_vcpus.size) {
                 int nr_set_cpus = 0;
+                char *s;
                 nr_set_cpus = libxl_bitmap_count_set(&b_info->avail_vcpus);
 
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d,maxcpus=%d",
                                                          nr_set_cpus,
                                                          b_info->max_vcpus));
+                
+                s = libxl_bitmap_to_hex_string(CTX, &b_info->avail_vcpus);
+                flexarray_vappend(dm_args, "-vcpu_avail",
+                                  libxl__sprintf(gc, "%s", s), NULL);
+                free(s);
             } else
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d",
                                                          b_info->max_vcpus));
#13 lore raw

Re: [PATCH] libxl: Use -vcpu_avail with qemu-xen.

Quoted 11 lines · Ian Campbell
Quoted 4 lines · Anthony PERARD

This require the series CPU hotplug for qemu-xen.

Note: this patch is valid only for 4.3 as the -vcpu_avail will probably not be upstream to Qemu.

Ugh. So how are we going to handle this in the future? libxl ideally needs to work with upstream qemu or our qemu seamlessly, which would mean needed to know whether to use -vcpu_avail vs. whatever upstream has. I'd much prefer to make our qemu export the same interface and use that...

Yes, I agree.

Quoted 30 lines
Quoted 28 lines
---
 tools/libxl/libxl_dm.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/libxl/libxl_dm.c +6 -0
index 1e3a9f4..2db2372 100644
@@ -530,11 +530,17 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
             flexarray_append(dm_args, "-smp");
             if (b_info->avail_vcpus.size) {
                 int nr_set_cpus = 0;
+                char *s;
                 nr_set_cpus = libxl_bitmap_count_set(&b_info->avail_vcpus);
 
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d,maxcpus=%d",
                                                          nr_set_cpus,
                                                          b_info->max_vcpus));
+                
+                s = libxl_bitmap_to_hex_string(CTX, &b_info->avail_vcpus);
+                flexarray_vappend(dm_args, "-vcpu_avail",
+                                  libxl__sprintf(gc, "%s", s), NULL);
+                free(s);
             } else
                 flexarray_append(dm_args, libxl__sprintf(gc, "%d",
                                                          b_info->max_vcpus));
#14 lore raw

Re: [PATCH] libxl: Use -vcpu_avail with qemu-xen.

In reply to Ian Campbell
Quoted 10 lines · Ian Campbell
Quoted 4 lines · Anthony PERARD
Quoted 4 lines

This require the series CPU hotplug for qemu-xen.

Note: this patch is valid only for 4.3 as the -vcpu_avail will probably not be upstream to Qemu.

Ugh. So how are we going to handle this in the future? libxl ideally needs to work with upstream qemu or our qemu seamlessly, which would mean needed to know whether to use -vcpu_avail vs. whatever upstream has. I'd much prefer to make our qemu export the same interface and use that...

It could maybe be removed all together. QEMU already know how many initial CPUs there is. The only difference is the bitmap. -vcpu_avail is giving to QEMU a bitmap of the running CPUs.

But I don't know if it useful to have a bitmap, or if a number is enough.

With QEMU upstream, we could actually pass the bitmap through several QMP command "cpu-add CPUx", if a number is not enough.

Signature · 1 line
Anthony PERARD
#15 lore raw
In reply to Anthony PERARD
Quoted 12 lines · Anthony PERARD

Hi all,

This series ports few patches from qemu-xen-traditionnal to qemu-xen (upstream). There is as little modification as possible on those patches so they *can not* be upstream as is. So this is only for 4.3. A proper series will be done for 4.4.

There make possible to have CPU hotplug on qemu-xen.

A patch for libxl will follow, which make use of the old command line -vcpu_avail with qemu-xen. This command line will probably not be upstream.

Quoted 8 lines
BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

To let you know, I just realize that QEMU 1.5 (we are using 1.3, I think) already have everything needed for CPU hotplug. It will just be a matter of plumbing libxl to use the cpu-add QMP command. But cpu-remove QMP command seams to be missing from QEMU.

Regards,

Signature · 1 line
Anthony PERARD
#16 lore raw
Quoted 22 lines · Anthony PERARD
Quoted 12 lines · Anthony PERARD

Hi all,

This series ports few patches from qemu-xen-traditionnal to qemu-xen (upstream). There is as little modification as possible on those patches so they *can not* be upstream as is. So this is only for 4.3. A proper series will be done for 4.4.

There make possible to have CPU hotplug on qemu-xen.

A patch for libxl will follow, which make use of the old command line -vcpu_avail with qemu-xen. This command line will probably not be upstream.

Quoted 8 lines
BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

Quoted 3 lines

To let you know, I just realize that QEMU 1.5 (we are using 1.3, I think) already have everything needed for CPU hotplug. It will just be a matter of plumbing libxl to use the cpu-add QMP command.

Cool! Is the implementation be very different to what we have here? Is it backportable?

At a minimum I'd prefer that whatever we do now interface wise will allow libxl to work with the qemu upstream mechanisms in the future (see my comment on your libxl patch).

Quoted 1 line

But cpu-remove QMP command seams to be missing from QEMU.

For a long time we didn't support CPU hot remove from HVM guests, in fact I'm not even sure that we support it today with qemu-trad.

Perhaps we do for PVHVM guests, but I'd half expect that to be using the PV path.

Ian.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
In reply to Anthony PERARD
Quoted 12 lines · Anthony PERARD

Hi all,

This series ports few patches from qemu-xen-traditionnal to qemu-xen (upstream). There is as little modification as possible on those patches so they *can not* be upstream as is. So this is only for 4.3. A proper series will be done for 4.4.

There make possible to have CPU hotplug on qemu-xen.

A patch for libxl will follow, which make use of the old command line -vcpu_avail with qemu-xen. This command line will probably not be upstream.

Quoted 8 lines
BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

I'm a bit confused -- if SeaBIOS has an infinite loop how do you even get to know Linux is OK?

Do you have a fix for SeaBIOS, I don't see it in this series.

Ian.

#20 lore raw
Quoted 8 lines · Ian Campbell
Quoted 8 lines
Quoted 8 lines
BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

Quoted 4 lines

I'm a bit confused -- if SeaBIOS has an infinite loop how do you even get to know Linux is OK?

Do you have a fix for SeaBIOS, I don't see it in this series.

The thing is, I don't know how to fix this bug. This is why there is no patch.

The probleme is this loop:

Quoted 3 lines

u8 cmos_smp_count = inb_cmos(CMOS_BIOS_SMP_COUNT); while (cmos_smp_count + 1 != readl(&CountCPUs))
;

where CountCPUs is incremented by each CPU by a small piece of code and cmos_smp_count is equal to 1, which is the number of expected vcpus-1. CountCPUs always go up to maxvcpus under Xen.

I could simply replace the '!=' by a '>' but it feel like a workaround...

Signature · 1 line
Anthony PERARD
#21 lore raw
In reply to Anthony PERARD
Quoted 12 lines · Anthony PERARD

Hi all,

This series ports few patches from qemu-xen-traditionnal to qemu-xen (upstream). There is as little modification as possible on those patches so they *can not* be upstream as is. So this is only for 4.3. A proper series will be done for 4.4.

There make possible to have CPU hotplug on qemu-xen.

A patch for libxl will follow, which make use of the old command line -vcpu_avail with qemu-xen. This command line will probably not be upstream.

Quoted 8 lines
BUG: There is an issue with SeaBIOS (used with qemu-xen). At SMP

initialisation, SeaBIOS will count the number of CPU running, and the number is always equal to maxvcpu when SeaBIOS expect less. This happen when we have something like:
vcpus = 2
maxvcpus = 8
in the VM config file. Linux is fine with this and will use only $vcpus. So the probleme is: an infinit loop in SeaBIOS.

Is a patch coming for that?

Quoted 19 lines

Ian Jackson (4):
HVM vcpu add/remove: qemu logic for vcpu add/revmoe Fix vcpu hotplug bug: get correct vcpu_avail bitmap Update vcpu hotplug logic
Implement 'xm vcpu-set' command for HVM guest

 hmp-commands.hx |  9 ++++++
 hw/acpi_piix4.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 monitor.c       | 18 ++++++++++++
 qemu-options.hx |  3 ++
 sysemu.h        |  4 +++
 vl.c            | 55 ++++++++++++++++++++++++++++++++++++
 xen-all.c       | 65 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 241 insertions(+), 1 deletion(-)
Signature · 1 line
Anthony PERARD