| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Example system startup script for setting up presistent cpusets with the |
| 4 |
# cset tool from package cpuset. Copy this script to /etc/init.d/cset and |
| 5 |
# uncomment out the commands in start() and stop() below, or add your own. |
| 6 |
# Based on /etc/init.d/skeleton template. |
| 7 |
# |
| 8 |
# Copyright (C) 2009 Novell, Inc. |
| 9 |
# |
| 10 |
# This library is free software; you can redistribute it and/or modify it |
| 11 |
# under the terms of the GNU Lesser General Public License as published by |
| 12 |
# the Free Software Foundation; either version 2.1 of the License, or (at |
| 13 |
# your option) any later version. |
| 14 |
# |
| 15 |
# This library is distributed in the hope that it will be useful, but |
| 16 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 |
# Lesser General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU Lesser General Public |
| 21 |
# License along with this library; if not, write to the Free Software |
| 22 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, |
| 23 |
# USA. |
| 24 |
# |
| 25 |
# |
| 26 |
# LSB compatible service control script; see http://www.linuxbase.org/spec/ |
| 27 |
# |
| 28 |
# Note: This template uses functions rc_XXX defined in /etc/rc.status on |
| 29 |
# UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your |
| 30 |
# script on this template and ensure that it works on non UL based LSB |
| 31 |
# compliant Linux distributions, you either have to provide the rc.status |
| 32 |
# functions from UL or change the script to work without them. |
| 33 |
# See skeleton.compat for a template that works with other distros as well. |
| 34 |
# |
| 35 |
### BEGIN INIT INFO |
| 36 |
# Provides: cset |
| 37 |
# Required-Start: $local_fs $remote_fs |
| 38 |
# Required-Stop: $local_fs |
| 39 |
# Default-Start: 2 3 5 |
| 40 |
# Default-Stop: 0 1 6 |
| 41 |
# Short-Description: Make cpuset setup persistent across boots |
| 42 |
# Description: Configure desired cpuset setup with the |
| 43 |
# cset tool for persistent cpusets across boots. |
| 44 |
### END INIT INFO |
| 45 |
# |
| 46 |
|
| 47 |
# Check for missing binaries (stale symlinks should not happen) |
| 48 |
# Note: Special treatment of stop for LSB conformance |
| 49 |
CSET_BIN=/usr/bin/cset |
| 50 |
test -x $CSET_BIN || { echo "$CSET_BIN not installed"; |
| 51 |
if [ "$1" = "stop" ]; then exit 0; |
| 52 |
else exit 5; fi; } |
| 53 |
|
| 54 |
# cset variables (EDIT apropriately for your situation) |
| 55 |
CSET_SYSTEM=0 |
| 56 |
CSET_USER=1-7 |
| 57 |
|
| 58 |
# Check for existence of cset config file and read it |
| 59 |
# This is not used in this example, but you can create one for |
| 60 |
# your setup if you wish. |
| 61 |
#CSET_CONFIG=/etc/sysconfig/cset |
| 62 |
#test -r $CSET_CONFIG || { echo "$CSET_CONFIG not existing"; |
| 63 |
# if [ "$1" = "stop" ]; then exit 0; |
| 64 |
# else exit 6; fi; } |
| 65 |
|
| 66 |
# Read config |
| 67 |
#. $CSET_CONFIG |
| 68 |
|
| 69 |
# Source LSB init functions |
| 70 |
. /etc/rc.status |
| 71 |
|
| 72 |
# Reset status of this service |
| 73 |
rc_reset |
| 74 |
|
| 75 |
case "$1" in |
| 76 |
start) |
| 77 |
echo -n "Starting cpuset " |
| 78 |
|
| 79 |
# For a simple shield, we can use the shield subcommand as follows; |
| 80 |
# however, for any setup more comples it is not recommended to use |
| 81 |
# shield, but instead to use the set and proc subcommands. The reason |
| 82 |
# is that the shield command has certain side effects which may complicate |
| 83 |
# the setup. For example, shield marks the cpusets as exclusive. |
| 84 |
|
| 85 |
## |
| 86 |
#### Example 1: using the shield subcommand |
| 87 |
## |
| 88 |
|
| 89 |
#$CSET_BIN shield --cpu=1-3 |
| 90 |
|
| 91 |
# Note that this creates CPU 0 as the general processor that runs |
| 92 |
# everything and all other CPUs (assuming this is a 4-CPU system) are assigned |
| 93 |
# to the shield. This is a typical simple shielding setup. Adjust if your |
| 94 |
# needs are different. |
| 95 |
|
| 96 |
# For shielding kernel threads as well, use the -k switch below instead |
| 97 |
# of the shield command above. |
| 98 |
#$CSET_BIN shield --cpu=1-3 -k |
| 99 |
|
| 100 |
## |
| 101 |
#### Example 2: using the set and proc subcommands |
| 102 |
## |
| 103 |
|
| 104 |
# To set up the exact same with the set and proc commands, use the |
| 105 |
# following commands. |
| 106 |
|
| 107 |
# Note that the CPUs are defined in the CSET_SYSTEM and |
| 108 |
# CSET_USER variables defined at the begining of this file. |
| 109 |
# Also you are not limited to call these cpusets "system" and |
| 110 |
# "user", you can call them anything, just be sure to be |
| 111 |
# consistent with the names in this script. |
| 112 |
|
| 113 |
#$CSET_BIN set --set=system --cpu=$CSET_SYSTEM |
| 114 |
#$CSET_BIN set --set=user --cpu=$CSET_USER |
| 115 |
|
| 116 |
# And to shield kernel threads, add the following command. |
| 117 |
|
| 118 |
#$CSET_BIN proc --move --kthread --fromset=root --toset=system |
| 119 |
|
| 120 |
# Remember status and be verbose |
| 121 |
rc_status -v |
| 122 |
;; |
| 123 |
stop) |
| 124 |
echo -n "Shutting down cpuset " |
| 125 |
|
| 126 |
## |
| 127 |
#### Example 1: using the shield command |
| 128 |
## |
| 129 |
|
| 130 |
# To turn the shield off, we use the reset switch to shield. This |
| 131 |
# will move all tasks to the root cpuset and then remove both user |
| 132 |
# and system cpusets. |
| 133 |
|
| 134 |
#CSET_BIN shield --reset |
| 135 |
|
| 136 |
## |
| 137 |
#### Example 2: using the set and proc subcommands |
| 138 |
## |
| 139 |
|
| 140 |
# Note that we can simply remove the cpusets which will automatically |
| 141 |
# move the tasks in those cpusets to their parents; however, manually |
| 142 |
# moving tasks first gives more flexibility to more complex cpuset |
| 143 |
# configurations. |
| 144 |
|
| 145 |
#$CSET_BIN proc --move --kthread --force --fromset=system --toset=root |
| 146 |
#$CSET_BIN proc --move --kthread --force --fromset=user --toset=root |
| 147 |
|
| 148 |
# And now, destroy the cpusets |
| 149 |
|
| 150 |
#$CSET_BIN set --set=system --destroy |
| 151 |
#$CSET_BIN set --set=user --destroy |
| 152 |
|
| 153 |
# Remember status and be verbose |
| 154 |
rc_status -v |
| 155 |
;; |
| 156 |
status) |
| 157 |
echo -n "Checking for service cpuset " |
| 158 |
# This command simply shows which cpusets are set up and how many |
| 159 |
# tasks are running in them. |
| 160 |
$CSET_BIN set --recurse |
| 161 |
rc_status -v |
| 162 |
;; |
| 163 |
*) |
| 164 |
echo "Usage: $0 {start|stop|status}" |
| 165 |
exit 1 |
| 166 |
;; |
| 167 |
esac |
| 168 |
rc_exit |