]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
block: add CPU hotplug test
authorOmar Sandoval <osandov@fb.com>
Thu, 11 May 2017 22:39:16 +0000 (15:39 -0700)
committerOmar Sandoval <osandov@fb.com>
Fri, 12 May 2017 17:46:30 +0000 (10:46 -0700)
Signed-off-by: Omar Sandoval <osandov@fb.com>
check
common/cpuhotplug [new file with mode: 0644]
tests/block/008 [new file with mode: 0755]
tests/block/008.out [new file with mode: 0644]

diff --git a/check b/check
index f406fd54a53b44c4264fc280e2584db2b6997405..26c5189b6e274e779fda69386fd1e29110a4ef1d 100755 (executable)
--- a/check
+++ b/check
@@ -265,6 +265,14 @@ _cleanup() {
                echo "$value" >"${TEST_DEV_SYSFS}/queue/${key}"
                unset TEST_DEV_QUEUE_SAVED["$key"]
        done
+
+       if [[ -v RESTORE_CPUS_ONLINE ]]; then
+               local cpu
+               for cpu in "${!CPUS_ONLINE_SAVED[@]}"; do
+                       echo "${CPUS_ONLINE_SAVED["$cpu"]}" >"/sys/devices/system/cpu/cpu$cpu/online"
+               done
+               unset RESTORE_CPUS_ONLINE
+       fi
 }
 
 _call_test() {
diff --git a/common/cpuhotplug b/common/cpuhotplug
new file mode 100644 (file)
index 0000000..18baa18
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# CPU hotplug helper functions.
+#
+# Copyright (C) 2017 Omar Sandoval
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Also initializes the HOTPLUGGABLE_CPUS array.
+_have_cpu_hotplug() {
+       HOTPLUGGABLE_CPUS=()
+       CPUS_ONLINE_SAVED=()
+
+       local cpu_dir cpu
+       for cpu_dir in /sys/devices/system/cpu/cpu+([0-9]); do
+               if [[ -w ${cpu_dir}/online ]]; then
+                       cpu="${cpu_dir#/sys/devices/system/cpu/cpu}"
+                       HOTPLUGGABLE_CPUS=("$cpu")
+                       CPUS_ONLINE_SAVED["$cpu"]="$(cat "${cpu_dir}/online")"
+               fi
+       done
+
+       if [[ ${#HOTPLUGGABLE_CPUS[@]} -eq 0 ]]; then
+               SKIP_REASON="CPU hotplugging is not supported"
+               return 1
+       fi
+       return 0
+}
+
+_online_cpu() {
+       RESTORE_CPUS_ONLINE=1
+       echo 1 >"/sys/devices/system/cpu/cpu$1/online"
+}
+
+_offline_cpu() {
+       RESTORE_CPUS_ONLINE=1
+       echo 0 >"/sys/devices/system/cpu/cpu$1/online"
+}
diff --git a/tests/block/008 b/tests/block/008
new file mode 100755 (executable)
index 0000000..84bf6c2
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/bash
+#
+# Hotplug CPUs online and offline while we do IO.
+#
+# Copyright (C) 2017 Omar Sandoval
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. common/cpuhotplug
+
+DESCRIPTION="do IO while hotplugging CPUs"
+TIMED=1
+
+requires() {
+       _have_cpu_hotplug
+}
+
+test_device() {
+       echo "Running ${TEST_NAME}"
+
+       if _test_dev_is_rotational; then
+               size="32m"
+       else
+               size="1g"
+       fi
+
+       # start fio job
+       _run_fio --bs=4k --rw=randread --norandommap \
+               --name=reads --filename="$TEST_DEV" --size="$size" \
+               --numjobs=8 --direct=1 &
+
+       # while job is running, hotplug CPUs randomly
+       while kill -0 $! 2>/dev/null; do
+               idx=$(($RANDOM % ${#HOTPLUGGABLE_CPUS[@]}))
+               if (( $RANDOM % 2 )); then
+                       _online_cpu "${HOTPLUGGABLE_CPUS[$idx]}"
+               else
+                       _offline_cpu "${HOTPLUGGABLE_CPUS[$idx]}"
+               fi
+               sleep .2
+       done
+
+       FIO_PERF_FIELDS=("read iops")
+       _fio_perf_report
+
+       echo "Test complete"
+}
diff --git a/tests/block/008.out b/tests/block/008.out
new file mode 100644 (file)
index 0000000..b40a812
--- /dev/null
@@ -0,0 +1,2 @@
+Running block/008
+Test complete