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() {
--- /dev/null
+#!/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"
+}
--- /dev/null
+#!/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"
+}
--- /dev/null
+Running block/008
+Test complete