cpuset_load_balance_test.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #!/bin/sh
  2. ################################################################################
  3. # #
  4. # Copyright (c) 2009 FUJITSU LIMITED #
  5. # #
  6. # This program is free software; you can redistribute it and#or modify #
  7. # it under the terms of the GNU General Public License as published by #
  8. # the Free Software Foundation; either version 2 of the License, or #
  9. # (at your option) any later version. #
  10. # #
  11. # This program is distributed in the hope that it will be useful, but #
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
  13. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License #
  14. # for more details. #
  15. # #
  16. # You should have received a copy of the GNU General Public License #
  17. # along with this program; if not, write to the Free Software #
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
  19. # #
  20. # Author: Miao Xie <miaox@cn.fujitsu.com> #
  21. # #
  22. ################################################################################
  23. export TCID="cpuset_load_balance"
  24. export TST_TOTAL=13
  25. export TST_COUNT=1
  26. . cpuset_funcs.sh
  27. check 4 2
  28. exit_status=0
  29. nr_cpus=$NR_CPUS
  30. nr_mems=$N_NODES
  31. cpus_all="$(seq -s, 0 $((nr_cpus-1)))"
  32. mems_all="$(seq -s, 0 $((nr_mems-1)))"
  33. runtime=30
  34. #cpuset_set_opt <path> <cfile> <value>
  35. cpuset_set_opt()
  36. {
  37. local path=$1
  38. local cfile=$2
  39. local value=$3
  40. /bin/echo $value > $path/$cfile
  41. return $?
  42. }
  43. # general_load_balance_test1 <g_cpus> <g_balance> <r_balance>
  44. general_load_balance_test1()
  45. {
  46. local g_cpus="$1"
  47. local g_balance="$2"
  48. local r_balance="$3"
  49. local g_path="$CPUSET/1"
  50. local fifo=
  51. local ret=
  52. cpuset_log "general group load balance test"
  53. cpuset_log "root group info:"
  54. cpuset_log " sched load balance:" $r_balance
  55. cpuset_log "general group info:"
  56. cpuset_log " cpus:" $g_cpus
  57. cpuset_log " sched load balance:" $g_balance
  58. cpuset_set "$CPUSET" "-" "$mems_all" "$r_balance" 2> $CPUSET_TMP/stderr
  59. if [ $? -ne 0 ]; then
  60. cpuset_log_error $CPUSET_TMP/stderr
  61. tst_resm TFAIL "set root group parameter failed."
  62. return 1
  63. fi
  64. cpuset_set "$g_path" "$g_cpus" "$mems_all" "$g_balance" 2> $CPUSET_TMP/stderr
  65. if [ $? -ne 0 ]; then
  66. cpuset_log_error $CPUSET_TMP/stderr
  67. tst_resm TFAIL "set general group parameter failed."
  68. return 1
  69. fi
  70. cpuset_cpu_hog 2> $CPUSET_TMP/cpu-hog_stderr &
  71. pid=$!
  72. read fifo < ./myfifo
  73. if [ $fifo -ne 0 ]; then
  74. cpuset_log_error $CPUSET_TMP/stderr
  75. tst_resm TFAIL "There is something wrong with test tasks"
  76. return 1
  77. fi
  78. if [ "$g_cpus" != "-" ]; then
  79. cpuset_set_opt "$g_path" "tasks" "$pid" 2> $CPUSET_TMP/stderr
  80. if [ $? -ne 0 ]; then
  81. cpuset_log_error $CPUSET_TMP/stderr
  82. tst_resm TFAIL "attach test tasks to group "\
  83. "failed."
  84. /bin/kill -s SIGKILL $pid
  85. return 1
  86. fi
  87. fi
  88. # start to fork the child processes
  89. /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr
  90. if [ $? -ne 0 ]; then
  91. cpuset_log_error $CPUSET_TMP/stderr
  92. tst_resm TFAIL "send the signal to fork the child tasks " \
  93. "failed."
  94. /bin/kill -s SIGKILL $pid
  95. return 1
  96. fi
  97. read fifo < ./myfifo
  98. if [ $fifo -ne 0 ]; then
  99. cpuset_log_error $CPUSET_TMP/cpu-hog_stderr
  100. tst_resm TFAIL "forking test tasks failed"
  101. return 1
  102. fi
  103. # start to run the child processes
  104. /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr
  105. if [ $? -ne 0 ]; then
  106. cpuset_log_error $CPUSET_TMP/stderr
  107. tst_resm TFAIL "send the signal to run the child tasks " \
  108. "failed."
  109. /bin/kill -s SIGUSR2 $pid
  110. return 1
  111. fi
  112. sleep $runtime
  113. /bin/kill -s SIGUSR2 $pid 2> $CPUSET_TMP/stderr
  114. if [ $? -ne 0 ]; then
  115. cpuset_log_error $CPUSET_TMP/stderr
  116. tst_resm TFAIL "send the signal to stop the child tasks " \
  117. "failed."
  118. return 1
  119. fi
  120. wait $pid
  121. if [ $? -ne 0 ]; then
  122. cpuset_log_error $CPUSET_TMP/cpu-hog_stderr
  123. tst_resm TFAIL "load balance test failed."
  124. return 1
  125. fi
  126. tst_resm TPASS "load balance test succeeded."
  127. }
  128. # general_load_balance_test2 <g1_cpus> <g1_balance>
  129. # <g2_cpus> <g2_balance>
  130. # <cpuoffline>
  131. general_load_balance_test2()
  132. {
  133. local g1_cpus=$1
  134. local g1_balance=$2
  135. local g1_path="$CPUSET/1"
  136. local g2_cpus=$3
  137. local g2_balance=$4
  138. local g2_path="$CPUSET/2"
  139. local cpuoffline=$5
  140. local pid=
  141. local ret=
  142. cpuset_log "general group load balance test"
  143. cpuset_log "root group info:"
  144. cpuset_log " sched load balance:" 0
  145. cpuset_log "general group1 info:"
  146. cpuset_log " cpus:" $g1_cpus
  147. cpuset_log " sched load balance:" $g1_balance
  148. cpuset_log "general group2 info:"
  149. cpuset_log " cpus:" $g2_cpus
  150. cpuset_log " sched load balance:" $g2_balance
  151. cpuset_log "CPU hotplug:" $cpuoffline
  152. cpuset_set "$CPUSET" "-" "$mems_all" "0" 2> $CPUSET_TMP/stderr
  153. if [ $? -ne 0 ]; then
  154. cpuset_log_error $CPUSET_TMP/stderr
  155. tst_resm TFAIL "set root group parameter failed."
  156. return 1
  157. fi
  158. cpuset_set "$g1_path" "$g1_cpus" "$mems_all" "$g1_balance" 2> $CPUSET_TMP/stderr
  159. if [ $? -ne 0 ]; then
  160. cpuset_log_error $CPUSET_TMP/stderr
  161. tst_resm TFAIL "set general group1 parameter failed."
  162. return 1
  163. fi
  164. cpuset_set "$g2_path" "$g2_cpus" "$mems_all" "$g2_balance" 2> $CPUSET_TMP/stderr
  165. if [ $? -ne 0 ]; then
  166. cpuset_log_error $CPUSET_TMP/stderr
  167. tst_resm TFAIL "set general group2 parameter failed."
  168. return 1
  169. fi
  170. # setup test environment
  171. setup_test_environment $cpuoffline 2> $CPUSET_TMP/stderr
  172. if [ $? -ne 0 ]; then
  173. cpuset_log_error $CPUSET_TMP/stderr
  174. tst_resm TFAIL "setup test environment(offline CPU#$HOTPLUG_CPU) failed"
  175. return 1
  176. fi
  177. cpuset_cpu_hog 2> $CPUSET_TMP/cpu-hog_stderr &
  178. pid=$!
  179. # wait for the parent to do prepare
  180. read fifo < ./myfifo
  181. if [ $fifo -ne 0 ]; then
  182. cpuset_log_error $CPUSET_TMP/stderr
  183. tst_resm TFAIL "There is something wrong with test tasks"
  184. return 1
  185. fi
  186. if [ "$g1_cpus" != "-" ]; then
  187. cpuset_set_opt "$g1_path" "tasks" "$pid" 2> $CPUSET_TMP/stderr
  188. if [ $? -ne 0 ]; then
  189. cpuset_log_error $CPUSET_TMP/stderr
  190. tst_resm TFAIL "attach test tasks to group "\
  191. "failed."
  192. /bin/kill -s SIGKILL $pid
  193. return 1
  194. fi
  195. fi
  196. # start to fork the child processes
  197. /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr
  198. if [ $? -ne 0 ]; then
  199. cpuset_log_error $CPUSET_TMP/stderr
  200. tst_resm TFAIL "send the signal to fork the child tasks " \
  201. "failed."
  202. /bin/kill -s SIGKILL $pid
  203. return 1
  204. fi
  205. # wait for the end of forking
  206. read fifo < ./myfifo
  207. if [ $fifo -ne 0 ]; then
  208. cpuset_log_error $CPUSET_TMP/cpu-hog_stderr
  209. tst_resm TFAIL "forking test tasks failed"
  210. return 1
  211. fi
  212. sleep 1
  213. cpu_hotplug $HOTPLUG_CPU $cpuoffline 2> $CPUSET_TMP/stderr
  214. if [ $? -ne 0 ]; then
  215. cpuset_log_error $CPUSET_TMP/stderr
  216. tst_resm TFAIL "$cpuoffline CPU#$HOTPLUG_CPU failed."
  217. /bin/kill -s SIGUSR2 $pid
  218. wait $pid
  219. return 1
  220. fi
  221. # start to run the child processes
  222. /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr
  223. if [ $? -ne 0 ]; then
  224. cpuset_log_error $CPUSET_TMP/stderr
  225. tst_resm TFAIL "send the signal to run the child tasks " \
  226. "failed."
  227. /bin/kill -s SIGUSR2 $pid
  228. wait $pid
  229. return 1
  230. fi
  231. sleep $runtime
  232. /bin/kill -s SIGUSR2 $pid 2> $CPUSET_TMP/stderr
  233. if [ $? -ne 0 ]; then
  234. cpuset_log_error $CPUSET_TMP/stderr
  235. tst_resm TFAIL "send the signal to stop the child tasks " \
  236. "failed."
  237. return 1
  238. fi
  239. wait $pid
  240. if [ $? -ne 0 ]; then
  241. cpuset_log_error $CPUSET_TMP/cpu-hog_stderr
  242. tst_resm TFAIL "load balance test failed."
  243. return 1
  244. fi
  245. tst_resm TPASS "load balance test succeeded."
  246. }
  247. base_test()
  248. {
  249. setup
  250. if [ $? -ne 0 ]; then
  251. exit_status=1
  252. else
  253. $test_pro "$@"
  254. if [ $? -ne 0 ]; then
  255. exit_status=1
  256. fi
  257. cleanup
  258. if [ $? -ne 0 ]; then
  259. exit_status=1
  260. fi
  261. cpu_hotplug_cleanup
  262. fi
  263. TST_COUNT=$(($TST_COUNT + 1))
  264. }
  265. test_general_load_balance1()
  266. {
  267. test_pro="general_load_balance_test1"
  268. local g_cpus=
  269. local g_isbalance=
  270. local r_isbalance=
  271. while read g_cpus g_isbalance r_isbalance
  272. do
  273. base_test $g_cpus $g_isbalance $r_isbalance
  274. done <<- EOF
  275. - 1 0
  276. 1 0 0
  277. - 1 1
  278. 1 1 1
  279. 1,2 0 0
  280. 1,2 1 0
  281. $cpus_all 1 0
  282. EOF
  283. # while read g_cpus g_isbalance r_isbalance
  284. }
  285. test_general_load_balance2()
  286. {
  287. test_pro="general_load_balance_test2"
  288. local g1_cpus=
  289. local g1_isbalance=
  290. local g2_cpus=
  291. local g2_isbalance=
  292. local hotplug=
  293. while read g1_cpus g1_isbalance g2_cpus g2_isbalance hotplug
  294. do
  295. base_test $g1_cpus $g1_isbalance $g2_cpus $g2_isbalance $hotplug
  296. done <<- EOF
  297. 1 1 0 1 none
  298. 1,2 1 0-3 0 none
  299. 1,2 1 0,3 1 none
  300. 1,2 1 1,3 1 none
  301. 1,2 1 1,3 1 offline
  302. 1,2 1 1,3 1 online
  303. EOF
  304. # while read g1_cpus g1_isbalance g2_cpus g2_isbalance hotplug
  305. }
  306. mkfifo myfifo
  307. test_general_load_balance1
  308. test_general_load_balance2
  309. rm -f myfifo
  310. exit $exit_status