parameters.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # usage ./parameters.sh
  3. #################################################################################
  4. # Copyright (c) International Business Machines Corp., 2007 #
  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: parameters.sh #
  22. # #
  23. # Description: This file has functions for the setup for testing cpucontroller #
  24. # setup includes creating controller device, mounting it with #
  25. # cgroup filesystem with option cpu and creating groups in it. #
  26. # #
  27. # Functions: get_num_groups(): decides number of groups based on num of cpus #
  28. # setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates #
  29. # groups in that, creates fifo to fire tasks at one time. #
  30. # cleanup(): Does full system cleanup #
  31. # #
  32. # Author: Sudhir Kumar <skumar@linux.vnet.ibm.com> #
  33. # #
  34. # History: #
  35. # #
  36. # DATE NAME EMAIL DESC #
  37. # #
  38. # 20/12/07 Sudhir Kumar <skumar@linux.vnet.ibm.com> Created this test #
  39. # #
  40. #################################################################################
  41. set_def_group() #default group spinning a task to create ideal scenario
  42. {
  43. [ -d /dev/cpuctl/group_def ] || mkdir /dev/cpuctl/group_def;
  44. if [ $? -ne 0 ]
  45. then
  46. echo "ERROR: Can't create default group... "
  47. "Check your permissions..Exiting test";
  48. cleanup;
  49. exit -1;
  50. fi
  51. # Migrate all the running tasks to this group
  52. # rt tasks require a finite value to cpu.rt_runtime_us
  53. echo 10000 > /dev/cpuctl/group_def/cpu.rt_runtime_us;
  54. for task in `cat /dev/cpuctl/tasks`; do
  55. echo $task > /dev/cpuctl/group_def/tasks 2>/dev/null 1>&2;
  56. done
  57. }
  58. get_num_groups() # Number of tasks should be >= number of cpu's (to check scheduling fairness)
  59. {
  60. NUM_GROUPS=$(( (NUM_CPUS*3 + 1)/2 ))
  61. }
  62. # Write the cleanup function
  63. cleanup ()
  64. {
  65. echo "Cleanup called";
  66. killall cpuctl_def_task01 1>/dev/null 2>&1;
  67. killall cpuctl_def_task02 1>/dev/null 2>&1;
  68. killall cpuctl_task_* 1>/dev/null 2>&1;
  69. sleep 1
  70. rm -f cpuctl_task_* 2>/dev/null
  71. for task in `cat /dev/cpuctl/group_def/tasks`; do
  72. echo $task > /dev/cpuctl/tasks 2>/dev/null 1>&2;
  73. done
  74. rmdir /dev/cpuctl/group* 2> /dev/null
  75. umount /dev/cpuctl 2> /dev/null
  76. rmdir /dev/cpuctl 2> /dev/null
  77. rm -f myfifo 2>/dev/null
  78. }
  79. # Create /dev/cpuctl & mount the cgroup file system with cpu controller
  80. #clean any group created eralier (if any)
  81. do_setup ()
  82. {
  83. if [ -e /dev/cpuctl ]
  84. then
  85. echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ?
  86. cleanup;
  87. mkdir /dev/cpuctl;
  88. else
  89. mkdir /dev/cpuctl
  90. fi
  91. mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null
  92. if [ $? -ne 0 ]
  93. then
  94. echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test";
  95. cleanup;
  96. exit -1;
  97. fi
  98. # Group created earlier may again be visible if not cleaned properly...so clean them
  99. groups=/dev/cpuctl/group*
  100. if [ -z "$groups" ]
  101. then
  102. rmdir /dev/cpuctl/group*
  103. echo "WARN: Earlier groups found and removed...";
  104. fi
  105. #Create a fifo to make all tasks wait on it
  106. mkfifo myfifo 2> /dev/null;
  107. if [ $? -ne 0 ]
  108. then
  109. echo "ERROR: Can't create fifo...Check your permissions..Exiting test";
  110. cleanup;
  111. exit -1;
  112. fi
  113. # Create different groups
  114. for i in $(seq 1 $NUM_GROUPS)
  115. do
  116. group=group_$i;
  117. mkdir /dev/cpuctl/$group;# 2>/dev/null
  118. if [ $? -ne 0 ]
  119. then
  120. echo "ERROR: Can't create $group...Check your permissions..Exiting test";
  121. cleanup;
  122. exit -1;
  123. fi
  124. done
  125. }