cpuhotplug01.sh 3.3 KB

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