Skip to contentSkip to conversation

KVM test: Add cpu_hotplug subtest

PATCH In review Lucas Meneghel Rodrigues 2 participants 4 messages Aug 24, 2011 – Aug 25, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM test: Add cpu_hotplug subtest

Tests the ability of adding virtual cpus on the fly to qemu using the monitor command cpu_set, then after everything is OK, run the cpu_hotplug testsuite on the guest through autotest.

Updates: As of the latest qemu-kvm (08-24-2011) HEAD, trying to online more CPUs than the ones already available leads to qemu hanging:

File /home/lmr/Code/autotest-git/client/virt/kvm_monitor.py, line 279, in cmd
raise MonitorProtocolError(msg)
MonitorProtocolError: Could not find (qemu) prompt after command cpu_set 2 online. Output so far: ""

---
 client/tests/kvm/tests/cpu_hotplug.py  |   99 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    7 ++
 2 files changed, 106 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/cpu_hotplug.py
client/tests/kvm/tests/cpu_hotplug.py new file +99 -0
new file mode 100644
index 0000000..fa75c9b
@@ -0,0 +1,99 @@
+import os, logging, re
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt import virt_test_utils
+
+
[email protected]_aware
+def run_cpu_hotplug(test, params, env):
+    """
+    Runs CPU hotplug test:
+
+    1) Pick up a living guest
+    2) Send the monitor command cpu_set [cpu id] for each cpu we wish to have
+    3) Verify if guest has the additional CPUs showing up under
+        /sys/devices/system/cpu
+    4) Try to bring them online by writing 1 to the 'online' file inside that dir
+    5) Run the CPU Hotplug test suite shipped with autotest inside guest
+
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = env.get_vm(params["main_vm"])
+    vm.verify_alive()
+    timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=timeout)
+
+    n_cpus_add = int(params.get("n_cpus_add", 1))
+    current_cpus = int(params.get("smp", 1))
+    total_cpus = current_cpus + n_cpus_add
+
+    error.context("getting guest dmesg before addition")
+    dmesg_before = session.cmd("dmesg -c")
+
+    error.context("Adding %d CPUs to guest" % n_cpus_add)
+    for i in range(total_cpus):
+        vm.monitor.cmd("cpu_set %s online" % i)
+
+    output = vm.monitor.cmd("info cpus")
+    logging.debug("Output of info cpus:\n%s", output)
+
+    cpu_regexp = re.compile("CPU #(\d+)")
+    total_cpus_monitor = len(cpu_regexp.findall(output))
+    if total_cpus_monitor != total_cpus:
+        raise error.TestFail("Monitor reports %s CPUs, when VM should have %s" %
+                             (total_cpus_monitor, total_cpus))
+
+    dmesg_after = session.cmd("dmesg -c")
+    logging.debug("Guest dmesg output after CPU add:\n%s" % dmesg_after)
+
+    # Verify whether the new cpus are showing up on /sys
+    error.context("verifying if new CPUs are showing on guest's /sys dir")
+    n_cmd = 'find /sys/devices/system/cpu/cpu[0-99] -maxdepth 0 -type d | wc -l'
+    output = session.cmd(n_cmd)
+    logging.debug("List of cpus on /sys:\n%s" % output)
+    try:
+        cpus_after_addition = int(output)
+    except ValueError:
+        logging.error("Output of '%s': %s", n_cmd, output)
+        raise error.TestFail("Unable to get CPU count after CPU addition")
+
+    if cpus_after_addition != total_cpus:
+        raise error.TestFail("%s CPUs are showing up under "
+                             "/sys/devices/system/cpu, was expecting %s" %
+                             (cpus_after_addition, total_cpus))
+
+    error.context("locating online files for guest's new CPUs")
+    r_cmd = 'find /sys/devices/system/cpu/cpu[0-99]/online -maxdepth 0 -type f'
+    online_files = session.cmd(r_cmd)
+    logging.debug("CPU online files detected: %s", online_files)
+    online_files = online_files.split().sort()
+
+    if not online_files:
+        raise error.TestFail("Could not find CPUs that can be "
+                             "enabled/disabled on guest")
+
+    for online_file in online_files:
+        cpu_regexp = re.compile("cpu(\d+)", re.IGNORECASE)
+        cpu_id = cpu_regexp.findall(online_file)[0]
+        error.context("changing online status for CPU %s" % cpu_id)
+        check_online_status = session.cmd("cat %s" % online_file)
+        try:
+            check_online_status = int(check_online_status)
+        except ValueError:
+            raise error.TestFail("Unable to get online status from CPU %s" %
+                                 cpu_id)
+        assert(check_online_status in [0, 1])
+        if check_online_status == 0:
+            error.context("Bringing CPU %s online" % cpu_id)
+            session.cmd("echo 1 > %s" % online_file)
+
+    # Now that all CPUs were onlined, let's execute the
+    # autotest CPU Hotplug test
+    control_path = os.path.join(test.bindir, "autotest_control",
+                                "cpu_hotplug.control")
+
+    timeout = int(params.get("cpu_hotplug_timeout"), 300)
+    error.context("running cpu_hotplug autotest after cpu addition")
+    virt_test_utils.run_autotest(vm, session, control_path, timeout,
+                                 test.outputdir, params)
client/tests/kvm/tests_base.cfg.sample +7 -0
index ca8a9c0..b22118b 100644
@@ -1104,6 +1104,13 @@ variants:
                 dd_timeout = 900
                 check_cmd_timeout = 900
 
+    - cpu_hotplug:
+        type = cpu_hotplug
+        cpu_hotplug_timeout = 600
+        n_cpus_add = 1
+        kill_vm = yes
+        iterations = 5
+
     # system_powerdown, system_reset and shutdown *must* be the last ones
     # defined (in this order), since the effect of such tests can leave
     # the VM on a bad state.
Signature · 1 line
1.7.6
#1 lore raw
Quoted 43 lines · On Wed, 24 Aug 2011 01:05:13 -0300 Lucas Meneghel Rodrigues <[email protected]>…

Tests the ability of adding virtual cpus on the fly to qemu using the monitor command cpu_set, then after everything is OK, run the cpu_hotplug testsuite on the guest through autotest.

Updates: As of the latest qemu-kvm (08-24-2011) HEAD, trying to online more CPUs than the ones already available leads to qemu hanging:

File /home/lmr/Code/autotest-git/client/virt/kvm_monitor.py, line 279, in cmd raise MonitorProtocolError(msg)
MonitorProtocolError: Could not find (qemu) prompt after command cpu_set 2 online. Output so far: ""

---
 client/tests/kvm/tests/cpu_hotplug.py  |   99

++++++++++++++++++++++++++++++++
client/tests/kvm/tests_base.cfg.sample | 7 ++ 2 files changed, 106
insertions(+), 0 deletions(-) create mode 100644
client/tests/kvm/tests/cpu_hotplug.py

(quoted diff) +0 -0

b/client/tests/kvm/tests/cpu_hotplug.py new file mode 100644 index 0000000..fa75c9b

client/tests/kvm/tests/cpu_hotplug.py new file +12 -0
@@ -0,0 +1,99 @@
+import os, logging, re
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt import virt_test_utils
+
+
[email protected]_aware
+def run_cpu_hotplug(test, params, env):
+    """
+    Runs CPU hotplug test:
+
+    1) Pick up a living guest
+    2) Send the monitor command cpu_set [cpu id] for each cpu we

wish to have

client/tests/kvm/tests/cpu_hotplug.py new file +3 -0
+    3) Verify if guest has the additional CPUs showing up under
+        /sys/devices/system/cpu
+    4) Try to bring them online by writing 1 to the 'online' file
Quoted 2 lines

inside that dir
+ 5) Run the CPU Hotplug test suite shipped with autotest inside

It looks good to me. How about adding
1) off-lining of vcpu.
2) Frequent offline-online of vcpus. some thing like below.

#!/bin/sh

SYS_CPU_DIR=/sys/devices/system/cpu

VICTIM_IRQ=15
IRQ_MASK=f0

iteration=0
while true; do
echo $iteration
echo $IRQ_MASK > /proc/irq/$VICTIM_IRQ/smp_affinity for cpudir in $SYS_CPU_DIR/cpu[1-9]; do
echo 0 > $cpudir/online
done
for cpudir in $SYS_CPU_DIR/cpu[1-9]; do
echo 1 > $cpudir/online
done
iteration=expr $iteration + 1
done

Quoted 107 lines

guest +

client/tests/kvm/tests/cpu_hotplug.py new file +27 -0
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = env.get_vm(params["main_vm"])
+    vm.verify_alive()
+    timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=timeout)
+
+    n_cpus_add = int(params.get("n_cpus_add", 1))
+    current_cpus = int(params.get("smp", 1))
+    total_cpus = current_cpus + n_cpus_add
+
+    error.context("getting guest dmesg before addition")
+    dmesg_before = session.cmd("dmesg -c")
+
+    error.context("Adding %d CPUs to guest" % n_cpus_add)
+    for i in range(total_cpus):
+        vm.monitor.cmd("cpu_set %s online" % i)
+
+    output = vm.monitor.cmd("info cpus")
+    logging.debug("Output of info cpus:\n%s", output)
+
+    cpu_regexp = re.compile("CPU #(\d+)")
+    total_cpus_monitor = len(cpu_regexp.findall(output))
+    if total_cpus_monitor != total_cpus:
+        raise error.TestFail("Monitor reports %s CPUs, when VM

should have %s" %

client/tests/kvm/tests/cpu_hotplug.py new file +4 -0
+                             (total_cpus_monitor, total_cpus))
+
+    dmesg_after = session.cmd("dmesg -c")
+    logging.debug("Guest dmesg output after CPU add:\n%s" %

dmesg_after) +

client/tests/kvm/tests/cpu_hotplug.py new file +2 -0
+    # Verify whether the new cpus are showing up on /sys
+    error.context("verifying if new CPUs are showing on guest's /sys

dir")

client/tests/kvm/tests/cpu_hotplug.py new file +8 -1
+    n_cmd = 'find /sys/devices/system/cpu/cpu[0-99] -maxdepth 0
-type d | wc -l'
+    output = session.cmd(n_cmd)
+    logging.debug("List of cpus on /sys:\n%s" % output)
+    try:
+        cpus_after_addition = int(output)
+    except ValueError:
+        logging.error("Output of '%s': %s", n_cmd, output)
+        raise error.TestFail("Unable to get CPU count after CPU

addition") +

client/tests/kvm/tests/cpu_hotplug.py new file +3 -0
+    if cpus_after_addition != total_cpus:
+        raise error.TestFail("%s CPUs are showing up under "
+                             "/sys/devices/system/cpu, was expecting

%s" %

client/tests/kvm/tests/cpu_hotplug.py new file +4 -0
+                             (cpus_after_addition, total_cpus))
+
+    error.context("locating online files for guest's new CPUs")
+    r_cmd = 'find /sys/devices/system/cpu/cpu[0-99]/online -maxdepth

0 -type f'

client/tests/kvm/tests/cpu_hotplug.py new file +17 -0
+    online_files = session.cmd(r_cmd)
+    logging.debug("CPU online files detected: %s", online_files)
+    online_files = online_files.split().sort()
+
+    if not online_files:
+        raise error.TestFail("Could not find CPUs that can be "
+                             "enabled/disabled on guest")
+
+    for online_file in online_files:
+        cpu_regexp = re.compile("cpu(\d+)", re.IGNORECASE)
+        cpu_id = cpu_regexp.findall(online_file)[0]
+        error.context("changing online status for CPU %s" % cpu_id)
+        check_online_status = session.cmd("cat %s" % online_file)
+        try:
+            check_online_status = int(check_online_status)
+        except ValueError:
+            raise error.TestFail("Unable to get online status from

CPU %s" %

client/tests/kvm/tests/cpu_hotplug.py new file +15 -0
+                                 cpu_id)
+        assert(check_online_status in [0, 1])
+        if check_online_status == 0:
+            error.context("Bringing CPU %s online" % cpu_id)
+            session.cmd("echo 1 > %s" % online_file)
+
+    # Now that all CPUs were onlined, let's execute the
+    # autotest CPU Hotplug test
+    control_path = os.path.join(test.bindir, "autotest_control",
+                                "cpu_hotplug.control")
+
+    timeout = int(params.get("cpu_hotplug_timeout"), 300)
+    error.context("running cpu_hotplug autotest after cpu addition")
+    virt_test_utils.run_autotest(vm, session, control_path, timeout,
+                                 test.outputdir, params)
(quoted diff) +0 -0

b/client/tests/kvm/tests_base.cfg.sample index ca8a9c0..b22118b 100644

client/tests/kvm/tests_base.cfg.sample +7 -0
@@ -1104,6 +1104,13 @@ variants:
                 dd_timeout = 900
                 check_cmd_timeout = 900
 
+    - cpu_hotplug:
+        type = cpu_hotplug
+        cpu_hotplug_timeout = 600
+        n_cpus_add = 1
+        kill_vm = yes
+        iterations = 5
+
     # system_powerdown, system_reset and shutdown *must* be the last

ones # defined (in this order), since the effect of such tests can leave # the VM on a bad state.

#2 lore raw
Quoted 60 lines · pradeep
Quoted 39 lines · On Wed, 24 Aug 2011 01:05:13 -0300 Lucas Meneghel Rodrigues <[email protected]>…

Tests the ability of adding virtual cpus on the fly to qemu using the monitor command cpu_set, then after everything is OK, run the cpu_hotplug testsuite on the guest through autotest.

Updates: As of the latest qemu-kvm (08-24-2011) HEAD, trying to online more CPUs than the ones already available leads to qemu hanging:

File /home/lmr/Code/autotest-git/client/virt/kvm_monitor.py, line 279, in cmd raise MonitorProtocolError(msg)
MonitorProtocolError: Could not find (qemu) prompt after command cpu_set 2 online. Output so far: ""

---
 client/tests/kvm/tests/cpu_hotplug.py  |   99
++++++++++++++++++++++++++++++++
client/tests/kvm/tests_base.cfg.sample |    7 ++ 2 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/cpu_hotplug.py

(quoted diff) +0 -0

b/client/tests/kvm/tests/cpu_hotplug.py new file mode 100644 index 0000000..fa75c9b

client/tests/kvm/tests/cpu_hotplug.py new file +12 -0
@@ -0,0 +1,99 @@
+import os, logging, re
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt import virt_test_utils
+
+
[email protected]_aware
+def run_cpu_hotplug(test, params, env):
+    """
+    Runs CPU hotplug test:
+
+    1) Pick up a living guest
+    2) Send the monitor command cpu_set [cpu id] for each cpu we
Quoted 6 lines

wish to have
+    3) Verify if guest has the additional CPUs showing up under
+        /sys/devices/system/cpu
+    4) Try to bring them online by writing 1 to the 'online' file inside that dir
+    5) Run the CPU Hotplug test suite shipped with autotest inside

It looks good to me.  How about adding
       1) off-lining of vcpu.
       2) Frequent offline-online of vcpus.  some thing like below.

#!/bin/sh

SYS_CPU_DIR=/sys/devices/system/cpu

VICTIM_IRQ=15
IRQ_MASK=f0

Quoted 12 lines

iteration=0
while true; do
 echo $iteration
 echo $IRQ_MASK > /proc/irq/$VICTIM_IRQ/smp_affinity for cpudir in $SYS_CPU_DIR/cpu[1-9]; do echo 0 > $cpudir/online
 done
 for cpudir in $SYS_CPU_DIR/cpu[1-9]; do echo 1 > $cpudir/online
 done
 iteration=expr $iteration + 1
done

Ok, I'll look into implementing your suggestion as well, thanks!

#3 lore raw
In reply to pradeep
Quoted 60 lines · pradeep
Quoted 39 lines · On Wed, 24 Aug 2011 01:05:13 -0300 Lucas Meneghel Rodrigues <[email protected]>…

Tests the ability of adding virtual cpus on the fly to qemu using the monitor command cpu_set, then after everything is OK, run the cpu_hotplug testsuite on the guest through autotest.

Updates: As of the latest qemu-kvm (08-24-2011) HEAD, trying to online more CPUs than the ones already available leads to qemu hanging:

File /home/lmr/Code/autotest-git/client/virt/kvm_monitor.py, line 279, in cmd raise MonitorProtocolError(msg)
MonitorProtocolError: Could not find (qemu) prompt after command cpu_set 2 online. Output so far: ""

---
 client/tests/kvm/tests/cpu_hotplug.py  |   99
++++++++++++++++++++++++++++++++
client/tests/kvm/tests_base.cfg.sample |    7 ++ 2 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/cpu_hotplug.py

(quoted diff) +0 -0

b/client/tests/kvm/tests/cpu_hotplug.py new file mode 100644 index 0000000..fa75c9b

client/tests/kvm/tests/cpu_hotplug.py new file +12 -0
@@ -0,0 +1,99 @@
+import os, logging, re
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt import virt_test_utils
+
+
[email protected]_aware
+def run_cpu_hotplug(test, params, env):
+    """
+    Runs CPU hotplug test:
+
+    1) Pick up a living guest
+    2) Send the monitor command cpu_set [cpu id] for each cpu we
Quoted 6 lines

wish to have
+    3) Verify if guest has the additional CPUs showing up under
+        /sys/devices/system/cpu
+    4) Try to bring them online by writing 1 to the 'online' file inside that dir
+    5) Run the CPU Hotplug test suite shipped with autotest inside

It looks good to me.  How about adding
       1) off-lining of vcpu.
       2) Frequent offline-online of vcpus.  some thing like below.

#!/bin/sh

SYS_CPU_DIR=/sys/devices/system/cpu

VICTIM_IRQ=15
IRQ_MASK=f0

Quoted 13 lines

iteration=0
while true; do
 echo $iteration
 echo $IRQ_MASK > /proc/irq/$VICTIM_IRQ/smp_affinity for cpudir in $SYS_CPU_DIR/cpu[1-9]; do echo 0 > $cpudir/online
 done
 for cpudir in $SYS_CPU_DIR/cpu[1-9]; do echo 1 > $cpudir/online
 done
 iteration=expr $iteration + 1
done

Implemented your suggestion, see:

http://patchwork.test.kernel.org/patch/3613/