1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# 3f08c3bdfSopenharmony_ci# Test Case 1 4f08c3bdfSopenharmony_ci# 5f08c3bdfSopenharmony_ci# Based on script by Ashok Raj <ashok.raj@intel.com> 6f08c3bdfSopenharmony_ci# Modified by Mark D and Bryce, Aug '05. 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ciexport TCID="cpuhotplug01" 9f08c3bdfSopenharmony_ciexport TST_TOTAL=1 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ci# Includes: 12f08c3bdfSopenharmony_ci. test.sh 13f08c3bdfSopenharmony_ci. cpuhotplug_testsuite.sh 14f08c3bdfSopenharmony_ci. cpuhotplug_hotplug.sh 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_cicat <<EOF 17f08c3bdfSopenharmony_ciName: $TCID 18f08c3bdfSopenharmony_ciDate: `date` 19f08c3bdfSopenharmony_ciDesc: What happens to disk controller interrupts when offlining CPUs? 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ciEOF 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ciusage() 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci cat << EOF 26f08c3bdfSopenharmony_ci usage: $0 -c cpu -l loop -n timeon -f timeoff -e timed 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci OPTIONS 29f08c3bdfSopenharmony_ci -c cpu which is specified for testing 30f08c3bdfSopenharmony_ci -l number of cycle test 31f08c3bdfSopenharmony_ci -n time delay after an online of cpu 32f08c3bdfSopenharmony_ci -f time delay after offline of cpu 33f08c3bdfSopenharmony_ci -e time delay before start of entire new cycle 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ciEOF 36f08c3bdfSopenharmony_ci exit 1 37f08c3bdfSopenharmony_ci} 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci# do_clean() 40f08c3bdfSopenharmony_ci# 41f08c3bdfSopenharmony_ci# Callback to be executed when script exits from a user interrupt 42f08c3bdfSopenharmony_ci# or regular program termination 43f08c3bdfSopenharmony_ci# 44f08c3bdfSopenharmony_cido_clean() 45f08c3bdfSopenharmony_ci{ 46f08c3bdfSopenharmony_ci kill_pid ${WRL_ID} 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci # Restore CPU states 49f08c3bdfSopenharmony_ci set_all_cpu_states "$cpu_states" 50f08c3bdfSopenharmony_ci} 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci# do_offline(CPU) 54f08c3bdfSopenharmony_ci# 55f08c3bdfSopenharmony_ci# Migrates some irq's onto the CPU, then offlines it 56f08c3bdfSopenharmony_ci# 57f08c3bdfSopenharmony_cido_offline() 58f08c3bdfSopenharmony_ci{ 59f08c3bdfSopenharmony_ci CPU=${1#cpu} 60f08c3bdfSopenharmony_ci # Migrate some irq's this way first. 61f08c3bdfSopenharmony_ci IRQS=`get_all_irqs` 62f08c3bdfSopenharmony_ci migrate_irq "${CPU}" "${IRQS}" 63f08c3bdfSopenharmony_ci offline_cpu ${CPU} 64f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 65f08c3bdfSopenharmony_ci if [ "$CPU" -ne 0 ]; then 66f08c3bdfSopenharmony_ci CPU_COUNT=$((CPU_COUNT+1)) 67f08c3bdfSopenharmony_ci eval "OFFLINE_CPU_${CPU_COUNT}=$1" 68f08c3bdfSopenharmony_ci fi 69f08c3bdfSopenharmony_ci return 1 70f08c3bdfSopenharmony_ci fi 71f08c3bdfSopenharmony_ci return 0 72f08c3bdfSopenharmony_ci} 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci# do_online(CPU) 76f08c3bdfSopenharmony_ci# 77f08c3bdfSopenharmony_ci# Onlines the CPU and then sets the smp_affinity of all IRQs to 78f08c3bdfSopenharmony_ci# this CPU. 79f08c3bdfSopenharmony_ci# 80f08c3bdfSopenharmony_cido_online() 81f08c3bdfSopenharmony_ci{ 82f08c3bdfSopenharmony_ci CPU=${1#cpu} 83f08c3bdfSopenharmony_ci online_cpu ${CPU} 84f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 85f08c3bdfSopenharmony_ci return 1 86f08c3bdfSopenharmony_ci fi 87f08c3bdfSopenharmony_ci migrate_irq ${CPU} 88f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 89f08c3bdfSopenharmony_ci return 1 90f08c3bdfSopenharmony_ci fi 91f08c3bdfSopenharmony_ci} 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ciwhile getopts c:l:n:f:e: OPTION; do 94f08c3bdfSopenharmony_ci case $OPTION in 95f08c3bdfSopenharmony_ci c) 96f08c3bdfSopenharmony_ci CPU_TO_TEST=$OPTARG;; 97f08c3bdfSopenharmony_ci l) 98f08c3bdfSopenharmony_ci HOTPLUG01_LOOPS=$OPTARG;; 99f08c3bdfSopenharmony_ci n) 100f08c3bdfSopenharmony_ci TM_ONLINE=$OPTARG;; 101f08c3bdfSopenharmony_ci f) 102f08c3bdfSopenharmony_ci TM_OFFLINE=$OPTARG;; 103f08c3bdfSopenharmony_ci e) 104f08c3bdfSopenharmony_ci TM_DLY=$OPTARG;; 105f08c3bdfSopenharmony_ci ?) 106f08c3bdfSopenharmony_ci usage;; 107f08c3bdfSopenharmony_ci esac 108f08c3bdfSopenharmony_cidone 109f08c3bdfSopenharmony_ci 110f08c3bdfSopenharmony_ciLOOP_COUNT=1 111f08c3bdfSopenharmony_ci 112f08c3bdfSopenharmony_citst_require_cmds perl 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ciif tst_virt_hyperv; then 115f08c3bdfSopenharmony_ci tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug" 116f08c3bdfSopenharmony_cifi 117f08c3bdfSopenharmony_ci 118f08c3bdfSopenharmony_ciif [ $(get_present_cpus_num) -lt 2 ]; then 119f08c3bdfSopenharmony_ci tst_brkm TCONF "system doesn't have required CPU hotplug support" 120f08c3bdfSopenharmony_cifi 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ciif [ -z "${CPU_TO_TEST}" ]; then 123f08c3bdfSopenharmony_ci tst_brkm TBROK "usage: ${0##*/} <CPU to online>" 124f08c3bdfSopenharmony_cifi 125f08c3bdfSopenharmony_ci 126f08c3bdfSopenharmony_ci# Validate the specified CPU is available 127f08c3bdfSopenharmony_ciif ! cpu_is_valid "${CPU_TO_TEST}" ; then 128f08c3bdfSopenharmony_ci tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 129f08c3bdfSopenharmony_cifi 130f08c3bdfSopenharmony_ci 131f08c3bdfSopenharmony_ciif ! cpu_is_online "${CPU_TO_TEST}" ; then 132f08c3bdfSopenharmony_ci if ! online_cpu ${CPU_TO_TEST} ; then 133f08c3bdfSopenharmony_ci tst_brkm TBROK "Could not online cpu $CPU_TO_TEST" 134f08c3bdfSopenharmony_ci fi 135f08c3bdfSopenharmony_cifi 136f08c3bdfSopenharmony_ci 137f08c3bdfSopenharmony_ciTST_CLEANUP=do_clean 138f08c3bdfSopenharmony_ci 139f08c3bdfSopenharmony_cicpu_states=$(get_all_cpu_states) 140f08c3bdfSopenharmony_ci 141f08c3bdfSopenharmony_ciCPU_COUNT=0 142f08c3bdfSopenharmony_ci 143f08c3bdfSopenharmony_ci# Start up a process that writes to disk; keep track of its PID 144f08c3bdfSopenharmony_cicpuhotplug_do_disk_write_loop > /dev/null 2>&1 & 145f08c3bdfSopenharmony_ciWRL_ID=$! 146f08c3bdfSopenharmony_ci 147f08c3bdfSopenharmony_ciuntil [ $LOOP_COUNT -gt $HOTPLUG01_LOOPS ] 148f08c3bdfSopenharmony_cido 149f08c3bdfSopenharmony_ci 150f08c3bdfSopenharmony_ci tst_resm TINFO "Starting loop" 151f08c3bdfSopenharmony_ci IRQ_START=$(cat /proc/interrupts) 152f08c3bdfSopenharmony_ci 153f08c3bdfSopenharmony_ci # Attempt to offline all CPUs 154f08c3bdfSopenharmony_ci for cpu in $( get_hotplug_cpus ); do 155f08c3bdfSopenharmony_ci if [ "$cpu" = "cpu0" ]; then 156f08c3bdfSopenharmony_ci continue 157f08c3bdfSopenharmony_ci fi 158f08c3bdfSopenharmony_ci do_offline $cpu 159f08c3bdfSopenharmony_ci err=$? 160f08c3bdfSopenharmony_ci if [ $err -ne 0 ]; then 161f08c3bdfSopenharmony_ci tst_brkm TBROK "offlining $cpu failed: $err" 162f08c3bdfSopenharmony_ci else 163f08c3bdfSopenharmony_ci tst_resm TINFO "offlining $cpu was ok" 164f08c3bdfSopenharmony_ci fi 165f08c3bdfSopenharmony_ci sleep $TM_OFFLINE 166f08c3bdfSopenharmony_ci done 167f08c3bdfSopenharmony_ci 168f08c3bdfSopenharmony_ci # Attempt to online all CPUs 169f08c3bdfSopenharmony_ci for cpu in $( get_hotplug_cpus ); do 170f08c3bdfSopenharmony_ci if [ "$cpu" = "cpu0" ]; then 171f08c3bdfSopenharmony_ci continue 172f08c3bdfSopenharmony_ci fi 173f08c3bdfSopenharmony_ci do_online $cpu 174f08c3bdfSopenharmony_ci err=$? 175f08c3bdfSopenharmony_ci if [ $err -ne 0 ]; then 176f08c3bdfSopenharmony_ci tst_brkm TBROK "onlining $cpu failed: $err" 177f08c3bdfSopenharmony_ci else 178f08c3bdfSopenharmony_ci tst_resm TINFO "onlining $cpu was ok" 179f08c3bdfSopenharmony_ci fi 180f08c3bdfSopenharmony_ci sleep $TM_ONLINE 181f08c3bdfSopenharmony_ci done 182f08c3bdfSopenharmony_ci 183f08c3bdfSopenharmony_ci IRQ_END=`cat /proc/interrupts` 184f08c3bdfSopenharmony_ci 185f08c3bdfSopenharmony_ci # Print out a report showing the changes in IRQs 186f08c3bdfSopenharmony_ci echo 187f08c3bdfSopenharmony_ci echo 188f08c3bdfSopenharmony_ci cpuhotplug_report_proc_interrupts "$IRQ_START" "$IRQ_END" 189f08c3bdfSopenharmony_ci echo 190f08c3bdfSopenharmony_ci 191f08c3bdfSopenharmony_ci sleep $TM_DLY 192f08c3bdfSopenharmony_ci LOOP_COUNT=$((LOOP_COUNT+1)) 193f08c3bdfSopenharmony_ci 194f08c3bdfSopenharmony_cidone 195f08c3bdfSopenharmony_ci 196f08c3bdfSopenharmony_citst_resm TPASS "online and offline cpu${CPU} when writing disk" 197f08c3bdfSopenharmony_ci 198f08c3bdfSopenharmony_citst_exit 199