From owner-freebsd-bugs@FreeBSD.ORG Thu Jan 7 18:40:01 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 27515106566C for ; Thu, 7 Jan 2010 18:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0420A8FC17 for ; Thu, 7 Jan 2010 18:40:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o07Ie02m057564 for ; Thu, 7 Jan 2010 18:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o07Ie0al057563; Thu, 7 Jan 2010 18:40:00 GMT (envelope-from gnats) Resent-Date: Thu, 7 Jan 2010 18:40:00 GMT Resent-Message-Id: <201001071840.o07Ie0al057563@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Miroslav Lachman <000.fbsd@quip.cz> Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 947301065676 for ; Thu, 7 Jan 2010 18:30:35 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 837068FC0C for ; Thu, 7 Jan 2010 18:30:35 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o07IUZTe050896 for ; Thu, 7 Jan 2010 18:30:35 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o07IUY5n050895; Thu, 7 Jan 2010 18:30:34 GMT (envelope-from nobody) Message-Id: <201001071830.o07IUY5n050895@www.freebsd.org> Date: Thu, 7 Jan 2010 18:30:34 GMT From: Miroslav Lachman <000.fbsd@quip.cz> To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: conf/142434: [patch] Add cpuset(1) support to rc.subr X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jan 2010 18:40:01 -0000 >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: