mpss 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/bash
  2. # Intel MIC Platform Software Stack (MPSS)
  3. #
  4. # Copyright(c) 2013 Intel Corporation.
  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, version 2, as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # The full GNU General Public License is included in this distribution in
  16. # the file called "COPYING".
  17. #
  18. # Intel MIC User Space Tools.
  19. #
  20. # mpss Start mpssd.
  21. #
  22. # chkconfig: 2345 95 05
  23. # description: start MPSS stack processing.
  24. #
  25. ### BEGIN INIT INFO
  26. # Provides: mpss
  27. # Required-Start:
  28. # Required-Stop:
  29. # Short-Description: MPSS stack control
  30. # Description: MPSS stack control
  31. ### END INIT INFO
  32. # Source function library.
  33. . /etc/init.d/functions
  34. exec=/usr/sbin/mpssd
  35. sysfs="/sys/class/mic"
  36. start()
  37. {
  38. [ -x $exec ] || exit 5
  39. if [ "`ps -e | awk '{print $4}' | grep mpssd | head -1`" = "mpssd" ]; then
  40. echo -e $"MPSSD already running! "
  41. success
  42. echo
  43. return 0
  44. fi
  45. echo -e $"Starting MPSS Stack"
  46. echo -e $"Loading MIC_HOST Module"
  47. # Ensure the driver is loaded
  48. if [ ! -d "$sysfs" ]; then
  49. modprobe mic_host
  50. RETVAL=$?
  51. if [ $RETVAL -ne 0 ]; then
  52. failure
  53. echo
  54. return $RETVAL
  55. fi
  56. fi
  57. # Start the daemon
  58. echo -n $"Starting MPSSD "
  59. $exec
  60. RETVAL=$?
  61. if [ $RETVAL -ne 0 ]; then
  62. failure
  63. echo
  64. return $RETVAL
  65. fi
  66. success
  67. echo
  68. sleep 5
  69. # Boot the cards
  70. micctrl -b
  71. # Wait till ping works
  72. for f in $sysfs/*
  73. do
  74. count=100
  75. ipaddr=`cat $f/cmdline`
  76. ipaddr=${ipaddr#*address,}
  77. ipaddr=`echo $ipaddr | cut -d, -f1 | cut -d\; -f1`
  78. while [ $count -ge 0 ]
  79. do
  80. echo -e "Pinging "`basename $f`" "
  81. ping -c 1 $ipaddr &> /dev/null
  82. RETVAL=$?
  83. if [ $RETVAL -eq 0 ]; then
  84. success
  85. break
  86. fi
  87. sleep 1
  88. count=`expr $count - 1`
  89. done
  90. [ $RETVAL -ne 0 ] && failure || success
  91. echo
  92. done
  93. return $RETVAL
  94. }
  95. stop()
  96. {
  97. echo -e $"Shutting down MPSS Stack: "
  98. # Bail out if module is unloaded
  99. if [ ! -d "$sysfs" ]; then
  100. echo -n $"Module unloaded "
  101. success
  102. echo
  103. return 0
  104. fi
  105. # Shut down the cards.
  106. micctrl -S
  107. # Wait for the cards to go offline
  108. for f in $sysfs/*
  109. do
  110. while [ "`cat $f/state`" != "offline" ]
  111. do
  112. sleep 1
  113. echo -e "Waiting for "`basename $f`" to go offline"
  114. done
  115. done
  116. # Display the status of the cards
  117. micctrl -s
  118. # Kill MPSSD now
  119. echo -n $"Killing MPSSD"
  120. killall -9 mpssd 2>/dev/null
  121. RETVAL=$?
  122. [ $RETVAL -ne 0 ] && failure || success
  123. echo
  124. return $RETVAL
  125. }
  126. restart()
  127. {
  128. stop
  129. sleep 5
  130. start
  131. }
  132. status()
  133. {
  134. micctrl -s
  135. if [ "`ps -e | awk '{print $4}' | grep mpssd | head -n 1`" = "mpssd" ]; then
  136. echo "mpssd is running"
  137. else
  138. echo "mpssd is stopped"
  139. fi
  140. return 0
  141. }
  142. unload()
  143. {
  144. if [ ! -d "$sysfs" ]; then
  145. echo -n $"No MIC_HOST Module: "
  146. success
  147. echo
  148. return
  149. fi
  150. stop
  151. sleep 5
  152. echo -n $"Removing MIC_HOST Module: "
  153. modprobe -r mic_host
  154. RETVAL=$?
  155. [ $RETVAL -ne 0 ] && failure || success
  156. echo
  157. return $RETVAL
  158. }
  159. case $1 in
  160. start)
  161. start
  162. ;;
  163. stop)
  164. stop
  165. ;;
  166. restart)
  167. restart
  168. ;;
  169. status)
  170. status
  171. ;;
  172. unload)
  173. unload
  174. ;;
  175. *)
  176. echo $"Usage: $0 {start|stop|restart|status|unload}"
  177. exit 2
  178. esac
  179. exit $?