run_cpuctl_latency_test.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/bin/bash
  2. # usage ./runcpuctl_latency_test.sh
  3. ###############################################################################
  4. # Copyright (c) International Business Machines Corp., 2008 #
  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, #
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See #
  14. # the GNU General Public License 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. ###############################################################################
  21. # Name Of File: run_cpuctl_test.sh #
  22. # #
  23. # Description: This file runs the setup for testing latency under heavy load #
  24. # when group scheduling is enabled #
  25. # After setup it runs diff test cases in diff setup. #
  26. # #
  27. # Test 01: Tests latency when no cgroup is mounted #
  28. # Test 02: Tests latency when cgroup is mounted #
  29. # #
  30. # #
  31. # Author: Sudhir Kumar <skumar@linux.vnet.ibm.com> #
  32. # #
  33. # History: #
  34. # #
  35. # DATE NAME EMAIL DESC #
  36. # #
  37. # 26/11/08 Sudhir Kumar <skumar@linux.vnet.ibm.com> Created this test #
  38. # #
  39. ###############################################################################
  40. NUM_TASKS=100;
  41. NUM_GROUPS=2; #for default
  42. check_task="";
  43. declare -a pid;
  44. allowed_latency=10;
  45. export TCID="cpuctl_latency_test";
  46. export TST_COUNT=1;
  47. export TST_TOTAL=2;
  48. . parameters.sh
  49. latency_cleanup()
  50. {
  51. local i;
  52. if [ -n "${pid[1]}" ]; then
  53. for i in $(seq 1 $NUM_TASKS)
  54. do
  55. kill -s SIGUSR1 ${pid[$i]} 2>/dev/null;
  56. done
  57. fi
  58. sleep 2;
  59. if [ $TEST_NUM -eq 2 ]; then
  60. # move any remaining task
  61. sleep 2;
  62. for task in `cat /dev/cpuctl/group*/tasks`; do
  63. echo $task > /dev/cpuctl/tasks #2>/dev/null 1>&2;
  64. done
  65. rmdir /dev/cpuctl/group* #2> /dev/null
  66. umount /dev/cpuctl #2> /dev/null
  67. rmdir /dev/cpuctl #2> /dev/null
  68. rm -f myfifo;
  69. fi;
  70. echo "Cleanup done for latency test $TEST_NUM"
  71. echo
  72. }
  73. log2()
  74. {
  75. local x=$1 n=2 l=-1;
  76. while((x));do
  77. let l+=1
  78. let x/=n;
  79. done;
  80. return $l;
  81. }
  82. # There is no single criterion for max latency, so pass or fail is only
  83. # intuitive. Here we use the same logic as by the kernel
  84. calc_allowed_latency()
  85. {
  86. # default sched granularity=5ms if not exported by kernel
  87. def_gran=5000 #in microseconds
  88. if [ -f /proc/sys/kernel/sched_wakeup_granularity_ns ]; then
  89. sys_latency=`cat /proc/sys/kernel/sched_wakeup_granularity_ns`
  90. allowed_latency=`expr $sys_latency / 1000` # in microseconds
  91. else
  92. num_cpus=`tst_ncpus`
  93. log2 $num_cpus;
  94. ln_num_cpus=$?
  95. ln_num_cpus=`expr $ln_num_cpus + 1`
  96. allowed_latency=`expr $ln_num_cpus \* $def_gran`
  97. fi
  98. # To be more practical we will take our criterio as double of this value
  99. allowed_latency=`expr $allowed_latency \* 2`
  100. }
  101. PWD=`pwd`
  102. ################################
  103. # Start
  104. ################################
  105. TEST_NUM=$1;
  106. if [ -z $TEST_NUM ]; then
  107. echo "Invalid test no passed to test script"
  108. echo "Exiting the test..."
  109. exit 1;
  110. fi;
  111. cd $LTPROOT/testcases/bin/ #Bad idea????????
  112. # Check if sources are compiled
  113. if [ ! -f $cpuctl_latency_test ] || [ ! -f $cpuctl_latency_check_task ]
  114. then
  115. echo "TBROK The sources are not compiled...."
  116. cd $PWD;
  117. exit 1;
  118. fi
  119. # Keep the signal handler ready
  120. trap 'echo "Doing cleanup"; latency_cleanup;' 0;
  121. # Calculate the alowed latency value
  122. calc_allowed_latency;
  123. case $TEST_NUM in
  124. "1") #without creating any groups
  125. # Run the load creating tasks
  126. echo TINFO "Running cpuctl Latency Test 1"
  127. for i in $(seq 1 $NUM_TASKS)
  128. do
  129. # Execute the load tasks
  130. ./cpuctl_latency_test $TEST_NUM &
  131. if [ $? -ne 0 ]
  132. then
  133. echo "TBROK Failed to execute binary"
  134. exit;
  135. else
  136. pid[$i]=$!;
  137. fi
  138. done
  139. # Run the latency checking task
  140. ./cpuctl_latency_check_task $TEST_NUM $$ $allowed_latency &
  141. if [ $? -ne 0 ]
  142. then
  143. echo "TBROK Failed to execute main binary"
  144. exit;
  145. else
  146. check_task=$!;
  147. fi;
  148. ;;
  149. "2") # With group scheduling
  150. echo TINFO "Running cpuctl Latency Test 2"
  151. NUM_CPUS=`tst_ncpus`
  152. get_num_groups; # NUM_GROUPS is set now
  153. do_setup;
  154. for num in $(seq 1 $NUM_TASKS)
  155. do
  156. group=/dev/cpuctl/group_`expr $num % $NUM_GROUPS + 1`;
  157. ./cpuctl_latency_test $TEST_NUM $group &
  158. if [ $? -ne 0 ]
  159. then
  160. echo "TBROK Failed to execute binary"
  161. exit;
  162. else
  163. pid[$num]=$!;
  164. fi;
  165. done;
  166. # Calculate the alowed latency value
  167. ./cpuctl_latency_check_task $TEST_NUM $$ $allowed_latency $group &
  168. if [ $? -ne 0 ]
  169. then
  170. echo "TBROK Failed to execute main binary";
  171. exit;
  172. else
  173. check_task=$!;
  174. fi;
  175. ;;
  176. * ) # wrong test num
  177. echo TBROK "Invalid test number passed to the script"
  178. exit;
  179. ;;
  180. esac;
  181. wait $check_task;
  182. RC=$?; # Return status of the task being waited
  183. if [ $RC -ne 0 ]
  184. then
  185. echo "Task $check_task exited abnormaly with return value: $RC";
  186. echo TBROK "Test could'nt execute for expected duration";
  187. fi
  188. cd $PWD;