cpuhotplug03.sh 3.1 KB

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