1#!/bin/sh 2# 3# Test Case 3 4# 5 6export TCID="cpuhotplug03" 7export TST_TOTAL=1 8 9# Includes: 10. test.sh 11. cpuhotplug_testsuite.sh 12. cpuhotplug_hotplug.sh 13 14cat <<EOF 15Name: $TCID 16Date: `date` 17Desc: Do tasks get scheduled to a newly on-lined CPU? 18 19EOF 20 21usage() 22{ 23 cat << EOF 24 usage: $0 -c cpu -l loop 25 26 OPTIONS 27 -c cpu which is specified for testing 28 -l number of cycle test 29 30EOF 31 exit 1 32} 33 34# do_clean() 35# 36# Callback to be executed when script exits from a user interrupt 37# or regular program termination 38# 39do_clean() 40{ 41 # Kill all the processes we started up and get rid of their pid files 42 if [ -e "/var/run/hotplug4_$$.pid" ]; then 43 for i in `cat /var/run/hotplug4_$$.pid`; do 44 kill_pid $i 45 done 46 rm /var/run/hotplug4_$$.pid 47 fi 48 49 # Restore CPU states 50 set_all_cpu_states "$cpu_states" 51} 52 53while getopts c:l: OPTION; do 54case $OPTION in 55 c) 56 CPU_TO_TEST=$OPTARG;; 57 l) 58 HOTPLUG03_LOOPS=$OPTARG;; 59 ?) 60 usage;; 61 esac 62done 63 64LOOP_COUNT=1 65 66cpus_num=$(get_present_cpus_num) 67if [ $cpus_num -lt 2 ]; then 68 tst_brkm TCONF "system doesn't have required CPU hotplug support" 69fi 70 71if [ -z $CPU_TO_TEST ]; then 72 tst_brkm TBROK "usage: ${0##*} <CPU to online>" 73fi 74 75# Validate the specified CPU is available 76if ! cpu_is_valid "${CPU_TO_TEST}" ; then 77 tst_brkm TCONF "cpu${CPU_TO_TEST} doesn't support hotplug" 78fi 79 80TST_CLEANUP=do_clean 81 82cpu_states=$(get_all_cpu_states) 83 84until [ $LOOP_COUNT -gt $HOTPLUG03_LOOPS ]; do 85 86 # Turns on all CPUs 87 for i in $( get_hotplug_cpus ); do 88 if ! cpu_is_online $i; then 89 if ! online_cpu $i; then 90 tst_brkm TBROK "Could not online cpu $i" 91 fi 92 fi 93 done 94 95 if ! offline_cpu ${CPU_TO_TEST} ; then 96 tst_resm TBROK "CPU${CPU_TO_TEST} cannot be offlined" 97 fi 98 99 # Start up a number of processes equal to twice the number of 100 # CPUs we have. This is to help ensure we've got enough processes 101 # that at least one will migrate to the new CPU. Store the PIDs 102 # so we can kill them later. 103 number_of_procs=$((cpus_num*2)) 104 until [ $number_of_procs -eq 0 ]; do 105 cpuhotplug_do_spin_loop > /dev/null 2>&1 & 106 echo $! >> /var/run/hotplug4_$$.pid 107 number_of_procs=$((number_of_procs-1)) 108 done 109 110 ps aux | head -n 1 111 ps aux | grep cpuhotplug_do_spin_loop 112 113 # Online the CPU 114 tst_resm TINFO "Onlining CPU ${CPU_TO_TEST}" 115 if ! online_cpu ${CPU_TO_TEST}; then 116 tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined" 117 fi 118 119 sleep 1 120 121 # Verify at least one process has migrated to the new CPU 122 # Since procps v3.3.15, we need to accurately select command name 123 # by -C option, because procps cannot trucate normal command name 124 # to 15 characters by default). 125 ps -o psr -o command --no-headers -C cpuhotplug_do_s 126 if [ $? -ne 0 ]; then 127 tst_brkm TBROK "No cpuhotplug_do_spin_loop processes \ 128 found on any processor" 129 fi 130 NUM=`ps -o psr -o command --no-headers -C cpuhotplug_do_s \ 131 | sed -e "s/^ *//" | cut -d' ' -f 1 | grep "^${CPU_TO_TEST}$" \ 132 | wc -l` 133 if [ $NUM -lt 1 ]; then 134 tst_resm TFAIL "No cpuhotplug_do_spin_loop processes found on \ 135 CPU${CPU_TO_TEST}" 136 tst_exit 137 fi 138 139 do_clean 140 141 LOOP_COUNT=$((LOOP_COUNT+1)) 142done 143 144tst_resm TPASS "$NUM cpuhotplug_do_spin_loop processes found on \ 145 CPU${CPU_TO_TEST}" 146 147tst_exit 148