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