Skip to contentSkip to conversation

s390: Allow hotplug of s390 CPUs

PATCH Superseded Matthew Rosato 4 participants 13 messages Nov 9, 2015 – Nov 10, 2015

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover s390: Allow hotplug of s390 CPUs

The following patchset enables hotplug of s390 CPUs.

The standard interface is used -- to configure a guest with 2 CPUs online at boot and 4 maximum:

qemu -smp 2,maxcpus=4

Or, when using libvirt:
<domain>

    ...
    <vcpu current="2">4</vcpu>
    ...

</domain>

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

At this point, the guest must bring the CPU online for use -- This can be achieved via "echo 1 > /sys/devices/system/cpu/cpuX/online" or via a management tool like cpuplugd.

This patch set is based on work previously done by Jason Herne.

Matthew Rosato (4):
s390x/cpu: Cleanup init in preparation for hotplug s390x/cpu: Set initial CPU state in common routine s390x/cpu: Add function to set CPU state s390x/cpu: Allow hotplug of CPUs

 hw/s390x/s390-virtio-ccw.c |  3 ++-
 hw/s390x/s390-virtio.c     | 41 +++++++++++++++++++++++----------------
 hw/s390x/s390-virtio.h     |  2 +-
 target-s390x/cpu.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++--
 target-s390x/cpu.h         |  2 ++
 5 files changed, 75 insertions(+), 21 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 s390x/cpu: Cleanup init in preparation for hotplug

Ensure a valid cpu_model is set upfront by setting the default value directly into the MachineState when none is specified. This is needed to ensure hotplugged CPUs share the same cpu_model.

---
 hw/s390x/s390-virtio-ccw.c |  2 +-
 hw/s390x/s390-virtio.c     | 10 +++++-----
 hw/s390x/s390-virtio.h     |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
hw/s390x/s390-virtio-ccw.c +1 -1
index 84221f4..7561e18 100644
@@ -136,7 +136,7 @@ static void ccw_init(MachineState *machine)
     virtio_ccw_register_hcalls();
 
     /* init CPUs */
-    s390_init_cpus(machine->cpu_model);
+    s390_init_cpus(machine);
 
     if (kvm_enabled()) {
         kvm_s390_enable_css_support(s390_cpu_addr2state(0));
hw/s390x/s390-virtio.c +5 -5
index cbde977..496898c 100644
@@ -168,12 +168,12 @@ void s390_init_ipl_dev(const char *kernel_filename,
     qdev_init_nofail(dev);
 }
 
-void s390_init_cpus(const char *cpu_model)
+void s390_init_cpus(MachineState *machine)
 {
     int i;
 
-    if (cpu_model == NULL) {
-        cpu_model = "host";
+    if (machine->cpu_model == NULL) {
+        machine->cpu_model = "host";
     }
 
     ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
@@ -182,7 +182,7 @@ void s390_init_cpus(const char *cpu_model)
         S390CPU *cpu;
         CPUState *cs;
 
-        cpu = cpu_s390x_init(cpu_model);
+        cpu = cpu_s390x_init(machine->cpu_model);
         cs = CPU(cpu);
 
         ipi_states[i] = cpu;
@@ -297,7 +297,7 @@ static void s390_init(MachineState *machine)
                               virtio_region_len);
 
     /* init CPUs */
-    s390_init_cpus(machine->cpu_model);
+    s390_init_cpus(machine);
 
     /* Create VirtIO network adapters */
     s390_create_virtio_net((BusState *)s390_bus, "virtio-net-s390");
hw/s390x/s390-virtio.h +1 -1
index eebce8e..ffd014c 100644
@@ -19,7 +19,7 @@
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
 
-void s390_init_cpus(const char *cpu_model);
+void s390_init_cpus(MachineState *machine);
 void s390_init_ipl_dev(const char *kernel_filename,
                        const char *kernel_cmdline,
                        const char *initrd_filename,
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 s390x/cpu: Set initial CPU state in common routine

In reply to Matthew Rosato

Both initial and hotplugged CPUs need to set the same initial state.

---
 hw/s390x/s390-virtio.c | 4 ----
 target-s390x/cpu.c     | 2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)
hw/s390x/s390-virtio.c +0 -4
index 496898c..b9cf058 100644
@@ -180,14 +180,10 @@ void s390_init_cpus(MachineState *machine)
 
     for (i = 0; i < smp_cpus; i++) {
         S390CPU *cpu;
-        CPUState *cs;
 
         cpu = cpu_s390x_init(machine->cpu_model);
-        cs = CPU(cpu);
 
         ipi_states[i] = cpu;
-        cs->halted = 1;
-        cs->exception_index = EXCP_HLT;
     }
 }
 
target-s390x/cpu.c +2 -0
index 189a2af..aafbbdc 100644
@@ -218,6 +218,8 @@ static void s390_cpu_initfn(Object *obj)
 #endif
 
     cs->env_ptr = env;
+    cs->halted = 1;
+    cs->exception_index = EXCP_HLT;
     cpu_exec_init(cs, &error_abort);
 #if !defined(CONFIG_USER_ONLY)
     qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/4 s390x/cpu: Add function to set CPU state

In reply to Matthew Rosato

Introduce s390_cpu_set_cpustate, which will set/update the machine/cpu[n] link with the current CPU state. Additionally, maintain an array of state pointers indexed by CPU id for fast lookup during interrupt handling.

---
 hw/s390x/s390-virtio.c | 29 ++++++++++++++++++++---------
 target-s390x/cpu.c     |  3 ++-
 target-s390x/cpu.h     |  1 +
 3 files changed, 23 insertions(+), 10 deletions(-)
hw/s390x/s390-virtio.c +20 -9
index b9cf058..ea867e0 100644
@@ -62,15 +62,30 @@
 #define S390_TOD_CLOCK_VALUE_PRESENT    0x01
 
 static VirtIOS390Bus *s390_bus;
-static S390CPU **ipi_states;
+static S390CPU **cpu_states;
 
 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
 {
-    if (cpu_addr >= smp_cpus) {
+    if (cpu_addr >= max_cpus) {
         return NULL;
     }
 
-    return ipi_states[cpu_addr];
+    /* Fast lookup via CPU ID */
+    return cpu_states[cpu_addr];
+}
+
+void s390_cpu_set_cpustate(uint16_t cpu_addr, S390CPU *state)
+{
+    gchar *name;
+
+    cpu_states[cpu_addr] = state;
+    name = g_strdup_printf("cpu[%i]", cpu_addr);
+    object_property_add_link(qdev_get_machine(), name, TYPE_S390_CPU,
+                             (Object **) &cpu_states[cpu_addr],
+                             object_property_allow_set_link,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
+                             &error_abort);
+    g_free(name);
 }
 
 static int s390_virtio_hcall_notify(const uint64_t *args)
@@ -176,14 +191,10 @@ void s390_init_cpus(MachineState *machine)
         machine->cpu_model = "host";
     }
 
-    ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
+    cpu_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
 
     for (i = 0; i < smp_cpus; i++) {
-        S390CPU *cpu;
-
-        cpu = cpu_s390x_init(machine->cpu_model);
-
-        ipi_states[i] = cpu;
+        cpu_s390x_init(machine->cpu_model);
     }
 }
 
target-s390x/cpu.c +2 -1
index aafbbdc..3228c3b 100644
@@ -221,6 +221,7 @@ static void s390_cpu_initfn(Object *obj)
     cs->halted = 1;
     cs->exception_index = EXCP_HLT;
     cpu_exec_init(cs, &error_abort);
+    env->cpu_num = cpu_num++;
 #if !defined(CONFIG_USER_ONLY)
     qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
@@ -230,8 +231,8 @@ static void s390_cpu_initfn(Object *obj)
     env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
     env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
     s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
+    s390_cpu_set_cpustate(env->cpu_num, cpu);
 #endif
-    env->cpu_num = cpu_num++;
 
     if (tcg_enabled() && !inited) {
         inited = true;
target-s390x/cpu.h +1 -0
index 658cd9d..803841b 100644
@@ -531,6 +531,7 @@ static inline int s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
 }
 
 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr);
+void s390_cpu_set_cpustate(uint16_t cpu_addr, S390CPU *state);
 unsigned int s390_cpu_halt(S390CPU *cpu);
 void s390_cpu_unhalt(S390CPU *cpu);
 unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu);
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/4 s390x/cpu: Allow hotplug of CPUs

In reply to Matthew Rosato

Implement cpu hotplug routine and add the machine hook.

---
 hw/s390x/s390-virtio-ccw.c |  1 +
 target-s390x/cpu.c         | 45 +++++++++++++++++++++++++++++++++++++++++++--
 target-s390x/cpu.h         |  1 +
 3 files changed, 45 insertions(+), 2 deletions(-)
hw/s390x/s390-virtio-ccw.c +1 -0
index 7561e18..cfcde8d 100644
@@ -163,6 +163,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data)
 
     mc->init = ccw_init;
     mc->reset = s390_machine_reset;
+    mc->hot_add_cpu = s390_hot_add_cpu;
     mc->block_default_type = IF_VIRTIO;
     mc->no_cdrom = 1;
     mc->no_floppy = 1;
target-s390x/cpu.c +43 -2

80 lines not on this page · raw message

target-s390x/cpu.h +1 -0
index 803841b..99daf79 100644
@@ -542,6 +542,7 @@ static inline uint8_t s390_cpu_get_state(S390CPU *cpu)
 
 void gtod_save(QEMUFile *f, void *opaque);
 int gtod_load(QEMUFile *f, void *opaque, int version_id);
+void s390_hot_add_cpu(const int64_t id, Error **errp);
 
 /* service interrupts are floating therefore we must not pass an cpustate */
 void s390_sclp_extint(uint32_t parm);
Signature · 1 line
1.9.1
#5 lore raw
In reply to Matthew Rosato

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

Regards,
Andreas

Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
#6 lore raw

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 5 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 2 lines

To subsequently hotplug a CPU:

Quoted 8 lines
Quoted 2 lines

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

#7 lore raw

Am 09.11.2015 um 16:35 schrieb Christian Borntraeger:

Quoted 9 lines

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 8 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

Quoted 8 lines
Quoted 5 lines

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

Sorry, hit send too early. I assume you want us to support device_add of a CPU in addition to that. Correct?

#8 lore raw

Am 09.11.2015 um 16:37 schrieb Christian Borntraeger:

Quoted 16 lines

Am 09.11.2015 um 16:35 schrieb Christian Borntraeger:

Quoted 15 lines

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 13 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

Quoted 5 lines
Quoted 2 lines

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

Sorry, hit send too early. I assume you want us to support device_add of a CPU in addition to that. Correct?

I just did a quick test with Matts patch.

after applying

qom/cpu.c +1 -1
index fb80d13..8152744 100644
@@ -360,7 +360,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
      * Reason: CPUs still need special care by board code: wiring up
      * IRQs, adding reset handlers, halting non-first CPUs, ...
      */
-    dc->cannot_instantiate_with_device_add_yet = true;
+//    dc->cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {

I was able to use

device_add s390-cpu

but no comprehensive testing was done.
I was even able to add more cpus than maxcpus, but the guest could not make use of it. Fix is probably easy. But in general it looks like that we _could_ enable device_add for CPUs as soon as others are ready as well.
Matt, do you agree?

Christian

#10 lore raw
In reply to Christian Borntraeger

Am 09.11.2015 um 16:37 schrieb Christian Borntraeger:

Quoted 16 lines

Am 09.11.2015 um 16:35 schrieb Christian Borntraeger:

Quoted 15 lines

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 13 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

Quoted 5 lines
Quoted 2 lines

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

Sorry, hit send too early. I assume you want us to support device_add of a CPU in addition to that. Correct?

No, I mean as I've always said: cpu-add was a short-term hack to make CPU hotplug work on x86. libvirt certainly needs to be fixed if it assumes this to work for s390.

If device_add works, we don't need cpu-add. If device_add does not work, we need to know which patches are missing. device_del is a separate beast and there were also patches around that seemed incomplete according to Eduardo.

Bharata did implement device_add for pseries, I thought.

Regards,
Andreas

Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
#9 lore raw
In reply to Christian Borntraeger
Quoted 43 lines · Christian Borntraeger

Am 09.11.2015 um 16:37 schrieb Christian Borntraeger:

Quoted 16 lines

Am 09.11.2015 um 16:35 schrieb Christian Borntraeger:

Quoted 15 lines

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 13 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

Quoted 5 lines
Quoted 2 lines

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

Sorry, hit send too early. I assume you want us to support device_add of a CPU in addition to that. Correct?

I just did a quick test with Matts patch.

after applying

qom/cpu.c +1 -1
index fb80d13..8152744 100644
@@ -360,7 +360,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
      * Reason: CPUs still need special care by board code: wiring up
      * IRQs, adding reset handlers, halting non-first CPUs, ...
      */
-    dc->cannot_instantiate_with_device_add_yet = true;
+//    dc->cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {

I was able to use

Quoted 9 lines

device_add s390-cpu

but no comprehensive testing was done.
I was even able to add more cpus than maxcpus, but the guest could not make use of it. Fix is probably easy. But in general it looks like that we _could_ enable device_add for CPUs as soon as others are ready as well.
Matt, do you agree?

Yes, I'm seeing the same behavior. We're just not checking max_cpus in device init, but the "extra" CPUs cannot be brought online.

Matt

#11 lore raw
In reply to Andreas Färber

Am 09.11.2015 um 16:56 schrieb Andreas Färber:

Quoted 23 lines

Am 09.11.2015 um 16:37 schrieb Christian Borntraeger:

Quoted 16 lines

Am 09.11.2015 um 16:35 schrieb Christian Borntraeger:

Quoted 15 lines

Am 09.11.2015 um 16:28 schrieb Andreas Färber:

Quoted 13 lines

Hi,

Am 09.11.2015 um 16:17 schrieb Matthew Rosato:

Quoted 4 lines

To subsequently hotplug a CPU:

Issue 'cpu-add <id>' from qemu monitor, or use virsh setvcpus --count <n> <domain>, where <n> is the total number of desired guest CPUs.

What exactly is still missing for you to use the standard device_add?

Last time I checked (a while ago...) some patches were stuck on the x86 side, and I don't recall hearing any feedback from the s390x side in my KVM Forum CPU hotplug session.

Quoted 5 lines
Quoted 2 lines

libvirt uses "cpu-add" unconditionally for hotplugging, so we certainly want to support that.

Sorry, hit send too early. I assume you want us to support device_add of a CPU in addition to that. Correct?

Quoted 8 lines

No, I mean as I've always said: cpu-add was a short-term hack to make CPU hotplug work on x86. libvirt certainly needs to be fixed if it assumes this to work for s390.

If device_add works, we don't need cpu-add. If device_add does not work, we need to know which patches are missing. device_del is a separate beast and there were also patches around that seemed incomplete according to Eduardo.

Given that s390 plugs CPUs without sockets, it would boild down to an opaque cpu, so
- Matt will remove the hot_add function from patch 4 (which makes it smaller)
- we provide a followup patch for libvirt
- Matt fixes the maxcpus overrun
- In addition we would need something like

target-s390x/cpu.c +1 -1
index 266575c..cfcff52 100644
@@ -377,7 +377,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
 
     scc->parent_realize = dc->realize;
     dc->realize = s390_cpu_realizefn;
-
+    dc->cannot_instantiate_with_device_add_yet = false;
     scc->parent_reset = cc->reset;
 #if !defined(CONFIG_USER_ONLY)
     scc->load_normal = s390_cpu_load_normal

With that device_add s390-cpu seems to work.

Quoted 1 line

Bharata did implement device_add for pseries, I thought.

Seems that the patches did not make it into upstream yet. Bharata, is cpu hotplug on pseries still missing?

Christian

#12 lore raw
Quoted 2 lines · Christian Borntraeger
Quoted 2 lines

Bharata did implement device_add for pseries, I thought.

Yes. For pseries, my patchset did CPU hotplug via device_add and device_del commands. And that's what I am planning to stick to going forward.

Quoted 3 lines

Seems that the patches did not make it into upstream yet. Bharata, is cpu hotplug on pseries still missing?

Yes, the last version I posted is at
https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg00650.html

Andreas mentioned that he would like to see some generic changes for supporting device_add for CPU, socket vs core level hotplug, defining the semantics etc. There was some discussion towards that and this is last I heard about it:

https://lists.nongnu.org/archive/html/qemu-devel/2015-10/msg05347.html

Regards,
Bharata.