Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 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 | |
| 33 | # Source function library. |
| 34 | . /etc/init.d/functions |
| 35 | |
| 36 | exec=/usr/sbin/mpssd |
| 37 | sysfs="/sys/class/mic" |
Sudeep Dutt | c74c931 | 2016-02-08 15:48:18 -0800 | [diff] [blame] | 38 | mic_modules="mic_host mic_x100_dma scif vop" |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 39 | |
| 40 | start() |
| 41 | { |
| 42 | [ -x $exec ] || exit 5 |
| 43 | |
| 44 | if [ "`ps -e | awk '{print $4}' | grep mpssd | head -1`" = "mpssd" ]; then |
| 45 | echo -e $"MPSSD already running! " |
| 46 | success |
| 47 | echo |
| 48 | return 0 |
| 49 | fi |
| 50 | |
| 51 | echo -e $"Starting MPSS Stack" |
Sudeep Dutt | f5c4814 | 2015-04-29 05:32:40 -0700 | [diff] [blame] | 52 | echo -e $"Loading MIC drivers:" $mic_modules |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 53 | |
Sudeep Dutt | f5c4814 | 2015-04-29 05:32:40 -0700 | [diff] [blame] | 54 | modprobe -a $mic_modules |
| 55 | RETVAL=$? |
| 56 | if [ $RETVAL -ne 0 ]; then |
| 57 | failure |
| 58 | echo |
| 59 | return $RETVAL |
| 60 | fi |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 61 | |
| 62 | # Start the daemon |
| 63 | echo -n $"Starting MPSSD " |
| 64 | $exec |
| 65 | RETVAL=$? |
| 66 | if [ $RETVAL -ne 0 ]; then |
| 67 | failure |
| 68 | echo |
| 69 | return $RETVAL |
| 70 | fi |
| 71 | success |
| 72 | echo |
| 73 | |
| 74 | sleep 5 |
| 75 | |
| 76 | # Boot the cards |
| 77 | micctrl -b |
| 78 | |
| 79 | # Wait till ping works |
| 80 | for f in $sysfs/* |
| 81 | do |
| 82 | count=100 |
| 83 | ipaddr=`cat $f/cmdline` |
| 84 | ipaddr=${ipaddr#*address,} |
| 85 | ipaddr=`echo $ipaddr | cut -d, -f1 | cut -d\; -f1` |
| 86 | while [ $count -ge 0 ] |
| 87 | do |
| 88 | echo -e "Pinging "`basename $f`" " |
| 89 | ping -c 1 $ipaddr &> /dev/null |
| 90 | RETVAL=$? |
| 91 | if [ $RETVAL -eq 0 ]; then |
| 92 | success |
| 93 | break |
| 94 | fi |
| 95 | sleep 1 |
| 96 | count=`expr $count - 1` |
| 97 | done |
| 98 | [ $RETVAL -ne 0 ] && failure || success |
| 99 | echo |
| 100 | done |
| 101 | return $RETVAL |
| 102 | } |
| 103 | |
| 104 | stop() |
| 105 | { |
| 106 | echo -e $"Shutting down MPSS Stack: " |
| 107 | |
| 108 | # Bail out if module is unloaded |
| 109 | if [ ! -d "$sysfs" ]; then |
| 110 | echo -n $"Module unloaded " |
| 111 | success |
| 112 | echo |
| 113 | return 0 |
| 114 | fi |
| 115 | |
| 116 | # Shut down the cards. |
| 117 | micctrl -S |
| 118 | |
| 119 | # Wait for the cards to go offline |
| 120 | for f in $sysfs/* |
| 121 | do |
Ashutosh Dixit | f4a66c2 | 2015-09-29 18:14:30 -0700 | [diff] [blame] | 122 | while [ "`cat $f/state`" != "ready" ] |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 123 | do |
| 124 | sleep 1 |
Ashutosh Dixit | f4a66c2 | 2015-09-29 18:14:30 -0700 | [diff] [blame] | 125 | echo -e "Waiting for "`basename $f`" to become ready" |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 126 | done |
| 127 | done |
| 128 | |
| 129 | # Display the status of the cards |
| 130 | micctrl -s |
| 131 | |
| 132 | # Kill MPSSD now |
| 133 | echo -n $"Killing MPSSD" |
| 134 | killall -9 mpssd 2>/dev/null |
| 135 | RETVAL=$? |
| 136 | [ $RETVAL -ne 0 ] && failure || success |
| 137 | echo |
| 138 | return $RETVAL |
| 139 | } |
| 140 | |
| 141 | restart() |
| 142 | { |
| 143 | stop |
| 144 | sleep 5 |
| 145 | start |
| 146 | } |
| 147 | |
| 148 | status() |
| 149 | { |
| 150 | micctrl -s |
| 151 | if [ "`ps -e | awk '{print $4}' | grep mpssd | head -n 1`" = "mpssd" ]; then |
| 152 | echo "mpssd is running" |
| 153 | else |
| 154 | echo "mpssd is stopped" |
| 155 | fi |
| 156 | return 0 |
| 157 | } |
| 158 | |
| 159 | unload() |
| 160 | { |
| 161 | if [ ! -d "$sysfs" ]; then |
| 162 | echo -n $"No MIC_HOST Module: " |
| 163 | success |
| 164 | echo |
| 165 | return |
| 166 | fi |
| 167 | |
| 168 | stop |
| 169 | |
| 170 | sleep 5 |
Sudeep Dutt | f5c4814 | 2015-04-29 05:32:40 -0700 | [diff] [blame] | 171 | echo -n $"Removing MIC drivers:" $mic_modules |
| 172 | modprobe -r $mic_modules |
Caz Yokoyama | 8d49751 | 2013-09-05 16:42:39 -0700 | [diff] [blame] | 173 | RETVAL=$? |
| 174 | [ $RETVAL -ne 0 ] && failure || success |
| 175 | echo |
| 176 | return $RETVAL |
| 177 | } |
| 178 | |
| 179 | case $1 in |
| 180 | start) |
| 181 | start |
| 182 | ;; |
| 183 | stop) |
| 184 | stop |
| 185 | ;; |
| 186 | restart) |
| 187 | restart |
| 188 | ;; |
| 189 | status) |
| 190 | status |
| 191 | ;; |
| 192 | unload) |
| 193 | unload |
| 194 | ;; |
| 195 | *) |
| 196 | echo $"Usage: $0 {start|stop|restart|status|unload}" |
| 197 | exit 2 |
| 198 | esac |
| 199 | |
| 200 | exit $? |