From nork@FreeBSD.org  Tue Apr 29 16:58:30 2008
Return-Path: <nork@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 855D81065674
	for <FreeBSD-gnats-submit@FreeBSD.org>; Tue, 29 Apr 2008 16:58:30 +0000 (UTC)
	(envelope-from nork@FreeBSD.org)
Received: from sakura.ninth-nine.com (unknown [IPv6:2001:2f0:104:80a0:230:48ff:fe41:2455])
	by mx1.freebsd.org (Postfix) with ESMTP id E80588FC14
	for <FreeBSD-gnats-submit@FreeBSD.org>; Tue, 29 Apr 2008 16:58:29 +0000 (UTC)
	(envelope-from nork@FreeBSD.org)
Received: from nadesico.ninth-nine.com (nadesico.ninth-nine.com [219.127.74.122]) by sakura.ninth-nine.com (8.14.1/8.14.1/NinthNine) with SMTP id m3TGwRCw060005 for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Apr 2008 01:58:28 +0900 (JST) (envelope-from Message-Id: <20080430015827.878969aa.nork@FreeBSD.org>
Date: Wed, 30 Apr 2008 01:58:27 +0900
From: Norikatsu Shigemura <nork@FreeBSD.org>
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: Add rtprio(1)/idprio(1) support to rc.subr(8).

>Number:         123222
>Category:       conf
>Synopsis:       [patch] Add rtprio(1)/idprio(1) support to rc.subr(8).
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-rc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 29 17:00:06 UTC 2008
>Closed-Date:    
>Last-Modified:  Wed Apr 30 08:20:04 UTC 2008
>Originator:     Norikatsu Shigemura
>Release:        FreeBSD 8.0-CURRENT i386
>Organization:
FreeBSD
>Environment:
System: FreeBSD melfina.ninth-nine.com 8.0-CURRENT FreeBSD 8.0-CURRENT #33: Mon Apr 28 06:03:33 JST 2008 nork@melfina.ninth-nine.com:/usr/obj/usr/src/sys/MELFINA i386
>Description:
	I want to run some daemons with rtprio(1)/idprio(1) like nice(1).
	So I made patches to support rtprio(1)/idprio(1) to rc.subr(8).

	Ex.
	# /etc/rc.conf
	canna_enable="YES"
	canna_rtprio="31"

	As a result, I got more interactive performance than before. 

>How-To-Repeat:
	N/A
>Fix:
	I made 4 patches for FreeBSD 4 major versions.

	rc.subr-8current.diff
		src/etc/rc.subr
		src/share/man/man8/rc.subr.8
	rc.subr-7stable.diff
		src/etc/rc.subr
	rc.subr-6stable.diff
		src/etc/rc.subr
	rc.subr-5stable.diff
		src/etc/rc.subr

--- rc.subr-8current.diff begins here ---
Index: src/etc/rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.80
diff -u -r1.80 rc.subr
--- src/etc/rc.subr	26 Jan 2008 11:22:11 -0000	1.80
+++ src/etc/rc.subr	29 Apr 2008 16:09:07 -0000
@@ -424,6 +424,10 @@
 #
 #	${name}_nice	n	Nice level to run ${command} at.
 #
+#	${name}_rtprio	n	Realtime scheduling priority to run ${command} at.
+#
+#	${name}_idprio	n	Idletime scheduling priority to run ${command} at.
+#
 #	${name}_user	n	User to run ${command} as, using su(1) if not
 #				using ${name}_chroot.
 #				Requires /usr to be mounted.
@@ -600,7 +604,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _rtprio=\$${name}_rtprio	_idprio=\$${name}_idprio
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -677,6 +682,8 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+${_rtprio:+rtprio $_rtprio }\
+${_idprio:+idprio $_idprio }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
@@ -686,12 +693,20 @@
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
 				fi
-				if [ -n "$_nice" ]; then
+				if [ -n "$_nice$_rtprio$_idprio" ]; then
 					if [ -z "$_user" ]; then
 						_doit="sh -c \"$_doit\""
-					fi	
+					fi
+				fi
+				if [ -n "$_nice" ]; then
 					_doit="nice -n $_nice $_doit"
 				fi
+				if [ -n "$_rtprio" ]; then
+					_doit="rtprio $_rtprio $_doit"
+				fi
+				if [ -n "$_idprio" ]; then
+					_doit="idprio $_idprio $_doit"
+				fi
 			fi
 
 					# run the full command
Index: src/share/man/man8/rc.subr.8
===================================================================
RCS file: /home/ncvs/src/share/man/man8/rc.subr.8,v
retrieving revision 1.20
diff -u -r1.20 rc.subr.8
--- src/share/man/man8/rc.subr.8	31 Mar 2008 14:11:37 -0000	1.20
+++ src/share/man/man8/rc.subr.8	29 Apr 2008 16:30:21 -0000
@@ -607,6 +607,22 @@
 Only supported after
 .Pa /usr
 is mounted.
+.It Va ${name}_rtprio
+.Xr rtprio 1
+priority to run
+.Va command
+as.
+Only supported after
+.Pa /usr
+is mounted.
+.It Va ${name}_idprio
+.Xr idprio 1
+priority to run
+.Va command
+as.
+Only supported after
+.Pa /usr
+is mounted.
 .It Va ${name}_program
 Full path to the command.
 Overrides
--- rc.subr-8current.diff ends here ---

--- rc.subr-7stable.diff begins here ---
Index: rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.77
diff -u -r1.77 rc.subr
--- rc.subr	9 Oct 2007 07:20:44 -0000	1.77
+++ rc.subr	29 Apr 2008 16:11:13 -0000
@@ -423,6 +423,10 @@
 #
 #	${name}_nice	n	Nice level to run ${command} at.
 #
+#	${name}_rtprio	n	Realtime scheduling priority to run ${command} at.
+#
+#	${name}_idprio	n	Idletime scheduling priority to run ${command} at.
+#
 #	${name}_user	n	User to run ${command} as, using su(1) if not
 #				using ${name}_chroot.
 #				Requires /usr to be mounted.
@@ -591,7 +595,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _rtprio=\$${name}_rtprio	_idprio=\$${name}_idprio
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -662,6 +667,8 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+${_rtprio:+rtprio $_rtprio }\
+${_idprio:+idprio $_idprio }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
@@ -671,12 +678,20 @@
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
 				fi
-				if [ -n "$_nice" ]; then
+				if [ -n "$_nice$_rtprio$_idprio" ]; then
 					if [ -z "$_user" ]; then
 						_doit="sh -c \"$_doit\""
-					fi	
+					fi
+				fi
+				if [ -n "$_nice" ]; then
 					_doit="nice -n $_nice $_doit"
 				fi
+				if [ -n "$_rtprio" ]; then
+					_doit="rtprio $_rtprio $_doit"
+				fi
+				if [ -n "$_idprio" ]; then
+					_doit="idprio $_idprio $_doit"
+				fi
 			fi
 
 					# run the full command
--- rc.subr-7stable.diff ends here ---

--- rc.subr-6stable.diff begins here ---
Index: rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.34.2.23
diff -u -r1.34.2.23 rc.subr
--- rc.subr	25 Oct 2007 14:04:18 -0000	1.34.2.23
+++ rc.subr	29 Apr 2008 16:12:51 -0000
@@ -423,6 +423,10 @@
 #
 #	${name}_nice	n	Nice level to run ${command} at.
 #
+#	${name}_rtprio	n	Realtime scheduling priority to run ${command} at.
+#
+#	${name}_idprio	n	Idletime scheduling priority to run ${command} at.
+#
 #	${name}_user	n	User to run ${command} as, using su(1) if not
 #				using ${name}_chroot.
 #				Requires /usr to be mounted.
@@ -591,7 +595,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _rtprio=\$${name}_rtprio	_idprio=\$${name}_idprio
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -662,6 +667,8 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+${_rtprio:+rtprio $_rtprio }\
+${_idprio:+idprio $_idprio }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
@@ -671,12 +678,20 @@
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
 				fi
-				if [ -n "$_nice" ]; then
+				if [ -n "$_nice$_rtprio$_idprio" ]; then
 					if [ -z "$_user" ]; then
 						_doit="sh -c \"$_doit\""
-					fi	
+					fi
+				fi
+				if [ -n "$_nice" ]; then
 					_doit="nice -n $_nice $_doit"
 				fi
+				if [ -n "$_rtprio" ]; then
+					_doit="rtprio $_rtprio $_doit"
+				fi
+				if [ -n "$_idprio" ]; then
+					_doit="idprio $_idprio $_doit"
+				fi
 			fi
 
 					# run the full command
--- rc.subr-6stable.diff ends here ---

--- rc.subr-5stable.diff begins here ---
Index: rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.31.2.5
diff -u -r1.31.2.5 rc.subr
--- rc.subr	19 Feb 2006 18:36:20 -0000	1.31.2.5
+++ rc.subr	29 Apr 2008 16:19:49 -0000
@@ -371,6 +371,10 @@
 #
 #	${name}_nice	n	Nice level to run ${command} at.
 #
+#	${name}_rtprio	n	Realtime scheduling priority to run ${command} at.
+#
+#	${name}_idprio	n	Idletime scheduling priority to run ${command} at.
+#
 #	${name}_user	n	User to run ${command} as, using su(1) if not
 #				using ${name}_chroot.
 #				Requires /usr to be mounted.
@@ -526,7 +530,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _rtprio=\$${name}_rtprio	_idprio=\$${name}_idprio
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -652,12 +657,16 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+${_rtprio:+rtprio $_rtprio }\
+${_idprio:+idprio $_idprio }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
 				_doit="\
 ${_chdir:+cd $_chdir; }\
 ${_nice:+nice -n $_nice }\
+${_rtprio:+rtprio $_rtprio }\
+${_idprio:+idprio $_idprio }\
 $command $rc_flags $command_args"
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
--- rc.subr-5stable.diff ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: nork 
Responsible-Changed-When: Tue Apr 29 17:07:25 UTC 2008 
Responsible-Changed-Why:  
Over to rc.subr(8) maintainers. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123222 

From: Kris Kennaway <kris@FreeBSD.org>
To: Norikatsu Shigemura <nork@FreeBSD.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/123222: Add rtprio(1)/idprio(1) support to rc.subr(8).
Date: Wed, 30 Apr 2008 10:14:59 +0200

 Norikatsu Shigemura wrote:
 
 >> Description:
 > 	I want to run some daemons with rtprio(1)/idprio(1) like nice(1).
 > 	So I made patches to support rtprio(1)/idprio(1) to rc.subr(8).
 
 idprio is dangerous and should not be used unless you are sure you know 
 what you're doing (it can cause deadlocks from priority inversion). 
 There might be similar issues with rtprio.
 
 Kris
 
>Unformatted:
