#!/bin/sh # # $FreeBSD$ # # Specify gsched_enable="YES" in /etc/rc.conf(.local) to activate scheduling on # storage devices. # # gsched_devs is a space separated list of accepted devices. If empty all # storage devices are used # # gsched_$dev specifies the sheduling algorithm to use (e.g. `rr') # TODO: # - add gsched profiles, such as `desktop' for kern.geom.sched.rr tunables # PROVIDE: gsched # KEYWORD: nojail . /etc/rc.subr gsched_enable=${gsched_enable:-NO} name="gsched" rcvar=`set_rcvar` command="/sbin/${name}" start_cmd="gsched_start" stop_cmd="gsched_stop" gsched_start_dev() { local _gsched_dev _gsched_profile _gsched_args _gsched_dev=$1 # Check if sched algo was specified # eval _gsched_profile=\$gsched_${_gsched_dev} if [ -n "${_gsched_profile}" ]; then _gsched_args="-a ${_gsched_profile}" fi # Start gsched for ${_gsched_dev} ${command} insert ${_gsched_args} ${_gsched_dev} } gsched_all_devs() { local _dev # Only supports upto 100 devices per device class # XXX: what other storage devices are there? for _dev in `cd /dev; echo *`; do case ${_dev} in ad[0-9]|ad[0-9][0-9]) echo ${_dev} ;; ada[0-9]|ada[0-9][0-9]) echo ${_dev} ;; da[0-9]|da[0-9][0-9]) echo ${_dev} ;; esac done } gsched_start() { local _gsched_devs _g _gsched_devs_recon _gsched_devs=$* if [ -z "${_gsched_devs}" ]; then # Use devices specified by gsched_devs _gsched_devs=${gsched_devs} # If no devices are specified then use all we can find if [ -z "${_gsched_devs}" ]; then _gsched_devs=`gsched_all_devs` fi elif [ -n "${gsched_devs}" ]; then # Make sure the custom device is one of the accepted for _g in ${_gsched_devs}; do case ${gsched_devs} in # _g is either by itself, at the start, middle # or the end of gsched_devs ${_g}|${_g}\ *|*\ ${_g}\ *|*\ ${_g}) _gsched_devs_recon="${_gsched_devs_recon} ${_g}" ;; esac done _gsched_devs=${_gsched_devs_recon} fi echo -n "Starting gsched devices:" for _g in ${_gsched_devs}; do echo -n " $_g" gsched_start_dev $_g done echo "." } gsched_stop_dev() { local _gsched_dev _gsched_dev=$1 ${command} destroy ${_gsched_dev}.sched. } gsched_stop() { local _gsched_devs _g _gsched_devs=$* if [ -z "${_gsched_devs}" ]; then # Use devices specified by gsched_devs _gsched_devs=${gsched_devs} # If no devices are specified then use all we can find if [ -z "${_gsched_devs}" ]; then _gsched_devs=`gsched_all_devs` fi fi echo -n "Stopping gsched devices:" for _g in ${_gsched_devs}; do echo -n " $_g" gsched_stop_dev $_g done echo "." } load_rc_config $name run_rc_command $*