On Tuesday 19 October 2010 10:18:24 Luigi Rizzo wrote:
> On Tue, Oct 19, 2010 at 08:07:54AM +0200, David Naylor wrote:
> > Would there be any interest in having a rc.d/ script?  I would find it
> > conveniant to specify a single rc.conf line and get scheduling for all my
> > devices.  PC-BSD might find such functionality useful.
> > 
> > See attached for my first draft at such a script, I'm willing to hash it
> > into shape.
> 
> it would surely be useful but try to keep it simple and user-driven
> (this is a general comment on rc.d scripts).
> Some things i think you should simplify in your script:
> - remove support for guessing which devices should get the scheduler.
>   This is really a user decision and if the user names no devices then
>   i believe it is better/safer not to install any scheduler.

I agree but I do think there is a case for an 'ALL' command as the user may 
want scheduling on newly attached devices without knowning their device names 
(i.e. attached USB storage devices).  

I would also like to add a ``gsched_nodev'' that allows one to use 'ALL' 
without having to apply gsched to everything.  

See attached for a devd.conf file that add supports for that.  

> - use standard names such as gsched_flags or gsched_flags_${dev} to hold
>   generic and specific flags for the insert command.
>   It is neither useful nor flexible to have the script insert '-a'
>   in front of the algorithm;

I've changed the variable names.  See attached for the rc.d script.  

@Miroslav: thanks for the tip
notify 100 {
        match "system"          "DEVFS";
        match "subsystem"       "CDEV";
        match "type"            "CREATE";
        match "cdev"            "(ad|ada|cd|da)[0-9]+";
        action "/etc/rc.d/gsched start $cdev";
};
#!/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.  `ALL' may be used 
# to indicate all storage devices.  
#
# gsched_flags_$dev specifies storage device specific flags (i.e. ``-a rr'' to
# use rr scheduling, see gsched(8) insert command).  

# TODO:
# - add gsched profiles, such as `desktop' for kern.geom.sched.rr tunables
# - add rejected list

# 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_filter() {
        local _gsched_devs _devs _devs_recon _kern_disks

        _kern_disks=`sysctl -n kern.disks`

        _devs=$*
        if [ -z "${_devs}" ]; then
                _devs=${_kern_disks}
        fi

        _gsched_devs=${gsched_devs}
        case ${_gsched_devs} in
                [aA][lL][lL])
                        _gsched_devs=${_kern_disks}
                        ;;
        esac

        for _g in ${_devs}; do
                # Filter all devs that are part of gsched_devs
                case " ${_gsched_devs} " in
                    *\ ${_g}\ *)
                        # Filter all devs that exist
                        case " ${_kern_disks} " in
                            *\ ${_g}\ *)
                                # ${_g} is part of ${gsched_dev} and it exists
                                _devs_recon="${_devs_recon} ${_g}"
                                ;;
                        esac
                        ;;
                esac
        done

        echo ${_devs_recon}
}

gsched_start()
{
        local _devs _g _gsched_flags

        # Make sure only accepted (and existing) devices are used
        #
        _devs=`gsched_filter $*`

        echo -n "Starting gsched devices:"

        for _g in ${_devs}; do
                echo -n " $_g"
                eval _gsched_flags=\$gsched_flags_${_g}
                ${command} insert ${_gsched_flags} ${_g}
        done

        echo "."
}

gsched_stop() {
        local _devs _g

        # Make sure only accepted (and existing) devices are used
        #
        _devs=`gsched_filter $*`

        echo -n "Stopping gsched devices:"

        for _g in ${_devs}; do
                echo -n " $_g"
                ${command} destroy ${_g}.sched.
        done

        echo "."
}

load_rc_config $name
run_rc_command $*

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to