From: Omar Sandoval Date: Thu, 11 May 2017 22:39:16 +0000 (-0700) Subject: block: add CPU hotplug test X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=974960cd844b732f8c3a6145c1106f4c07d75bed;p=users%2Fsagi%2Fblktests.git block: add CPU hotplug test Signed-off-by: Omar Sandoval --- diff --git a/check b/check index f406fd5..26c5189 100755 --- 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 index 0000000..18baa18 --- /dev/null +++ b/common/cpuhotplug @@ -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 . + +# 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 index 0000000..84bf6c2 --- /dev/null +++ b/tests/block/008 @@ -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 . + +. 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 index 0000000..b40a812 --- /dev/null +++ b/tests/block/008.out @@ -0,0 +1,2 @@ +Running block/008 +Test complete