Date: Thu, 7 Jan 2010 18:30:34 GMT From: Miroslav Lachman <000.fbsd@quip.cz> To: freebsd-gnats-submit@FreeBSD.org Subject: conf/142434: [patch] Add cpuset(1) support to rc.subr Message-ID: <201001071830.o07IUY5n050895@www.freebsd.org> Resent-Message-ID: <201001071840.o07Ie0al057563@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 142434 >Category: conf >Synopsis: [patch] Add cpuset(1) support to rc.subr >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Jan 07 18:40:00 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Miroslav Lachman >Release: 7.2-RELEASE >Organization: codeLab.cz >Environment: tested on: 7.2-RELEASE-p4 GENERIC amd64 9.0-CURRENT-200912 GENERIC i386 >Description: Add support for cpuset(1) to rc.subr If ${name}_cpuset is specified, command will be runned on specified CPUs. cpuset is available in STABLE branch for more than one year (7.1+), but is still not widely known / used and there is no general support to use cpuset in rc scripts. FreeBSD can benefit from feature like this compared to other OSes. >How-To-Repeat: >Fix: Apply attached patch and try something like this in /etc/rc.conf sshd_enable="YES" sshd_cpuset="0" mysql_enable="YES" mysql_cpuset="1-3" lighttpd_enable="YES" lighttpd_cpuset="2" proftpd_enable="YES" proftpd_cpuset="1,2" Then after boot or restart of services, you will have services assigned to defined CPUs like this: # /usr/local/etc/rc.d/mysql-server status mysql is running as pid 11952. on CPU(s) 1,2,3 # /usr/local/etc/rc.d/lighttpd status lighttpd is running as pid 12011. on CPU(s) 2 # /usr/local/etc/rc.d/proftpd status proftpd is running as pid 11882. on CPU(s) 1,2 The patch is not fully tested, but allows most currently available services to be assigned to CPUs without modification of existing rc scripts. Note: some complex rc scripts can not use cpuset, for example rc.d/jail patch is for 9-CURRENT but should work on older releases too Patch attached with submission follows: --- /etc/rc.subr.orig 2009-12-10 07:01:55.000000000 +0100 +++ /etc/rc.subr 2010-01-07 18:43:15.000000000 +0100 @@ -58,6 +58,7 @@ IDCMD="if [ -x $ID ]; then $ID -un; fi" PS="/bin/ps -ww" JID=`$PS -p $$ -o jid=` +CPUSET="/usr/bin/cpuset" case ${OSTYPE} in FreeBSD) @@ -464,6 +465,9 @@ # ${name}_chdir n Directory to cd to before running ${command} # (if not using ${name}_chroot). # +# ${name}_cpuset n A list of CPUs to run ${command} on. +# Requires /usr to be mounted. +# # ${name}_flags n Arguments to call ${command} with. # NOTE: $flags from the parent environment # can be used to override this. @@ -623,6 +627,17 @@ _pidcmd= _procname=${procname:-${command}} + eval _cpuset=\$${name}_cpuset + # fix for background-fsck problem / check if value start with number + case "$_cpuset" in + [0-9]*) ;; + *) _cpuset="" ;; + esac + _cpusetcmd= + if [ -n "$_cpuset" -a -x $CPUSET ]; then + _cpusetcmd="$CPUSET -l $_cpuset" + fi + # setup pid check command if [ -n "$_procname" ]; then if [ -n "$pidfile" ]; then @@ -686,7 +701,7 @@ if [ -n "$_cmd" ]; then _run_rc_precmd || return 1 - _run_rc_doit "$_cmd $rc_extra_args" || return 1 + _run_rc_doit "$_cpusetcmd $_cmd $rc_extra_args" || return 1 _run_rc_postcmd return $_return fi @@ -697,6 +712,11 @@ _run_rc_precmd || return 1 if [ -n "$rc_pid" ]; then echo "${name} is running as pid $rc_pid." + # for cpuset debug only, not committable (cut) + if [ -n "$_cpuset" -a -x $CPUSET ]; then + echo -n "on CPU(s)" + $CPUSET -g -p "$rc_pid" | cut -s -d: -f 2 + fi else echo "${name} is not running." return 1 @@ -725,13 +745,13 @@ check_startmsgs && echo "Starting ${name}." if [ -n "$_chroot" ]; then _doit="\ -${_nice:+nice -n $_nice }\ +${_nice:+nice -n $_nice } $_cpusetcmd\ chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\ $_chroot $command $rc_flags $command_args" else _doit="\ ${_chdir:+cd $_chdir && }\ -$command $rc_flags $command_args" +$_cpusetcmd $command $rc_flags $command_args" if [ -n "$_user" ]; then _doit="su -m $_user -c 'sh -c \"$_doit\"'" fi >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001071830.o07IUY5n050895>