Subject: Re: Proposed rc.d changes....
To: , <port-vax@netbsd.org>
From: David Brownlee <abs@netbsd.org>
List: port-vax
Date: 02/20/2001 12:12:20
	Apologies for crossposting, but this was probably the best
	way to catch people interested in Luke's changes to speed up rc.d
	processing :)

	PLEASE SEND ANY REPLIES TO tech-userlevel@netbsd.org - do not
	start threads on multiple maillists...

		David/absolute		-- www.netbsd.org: No hype required --


---------- Forwarded message ----------
Date: Tue, 20 Feb 2001 19:12:48 +1100
From: Luke Mewburn <lukem@wasabisystems.com>
To: Greywolf <greywolf@starwolf.com>
Cc: tech-userlevel@netbsd.org
Subject: Re: Proposed rc.d changes....

On Tue, Feb 20, 2001 at 02:36:04PM +1100, Luke Mewburn wrote:
> I've been meaning to ask for testing from users with much slower
> machines than my laptop (a PIII-700), because I didn't notice any
> difference with my laptop with the patch.
>
> Any takers? (Or should I just post it here and have people post their
> before & after results? :)

here's a work in progress. use at your own risk, etc ...

i'd be interested in the difference between:

	(a) the system as it stands now.

	(b) the following patch without rc_fast_and_loose set
	    (it only loads rc.conf once, and has other speedups)

	(c) the following patch WITH rc_fast_and_loose set.

the patch adds a call to `date' at the start of /etc/rc, so that could
be added to your /etc/rc before test (a) so you have an idea on when
it starts (date is already run at the end).

enjoy,
luke.

Index: rc
===================================================================
RCS file: /cvsroot/basesrc/etc/rc,v
retrieving revision 1.154
diff -p -r1.154 rc
*** rc	2000/12/15 00:00:09	1.154
--- rc	2001/02/20 08:06:28
*************** export PATH=/sbin:/bin:/usr/sbin:/usr/bi
*** 14,20 ****
--- 14,29 ----

  . /etc/rc.subr
  . /etc/rc.conf
+ _rc_conf_loaded=YES

+ #	Uncomment the following to execute each /etc/rc.d script in
+ #	the current shell rather than in a subshell.  This may be
+ #	faster on slow machines.
+ #	CAUTION: USE THIS AT YOUR OWN RISK; A BAD SCRIPT MAY
+ #	INADVERTENTLY PREVENT BOOT TO MULTIUSER.
+ #
+ #rc_fast_and_loose=YES
+
  if ! checkyesno rc_configured; then
  	echo "/etc/rc.conf is not configured.  Multiuser boot aborted."
  	exit 1
*************** trap : 2
*** 34,42 ****
  trap "echo 'Boot interrupted.'; exit 1" 3

  files=`rcorder -s nostart /etc/rc.d/*`

! for i in $files; do
! 	run_rc_script $i start
  done

  date
--- 43,53 ----
  trap "echo 'Boot interrupted.'; exit 1" 3

  files=`rcorder -s nostart /etc/rc.d/*`
+
+ date

! for _rc_elem in $files; do
! 	run_rc_script $_rc_elem start
  done

  date
Index: rc.subr
===================================================================
RCS file: /cvsroot/basesrc/etc/rc.subr,v
retrieving revision 1.29
diff -p -r1.29 rc.subr
*** rc.subr	2000/11/17 03:47:43	1.29
--- rc.subr	2001/02/20 08:06:29
*************** check_pidfile()
*** 117,132 ****
  	fi
  	_procnamebn=${_procname##*/}
  	ps -p $_pid -o 'pid,command' | while read _npid _arg0 _argv; do
! 		if [ "$_npid" = "PID" ]; then
! 			continue
! 		fi
! 		if [   "$_arg0" = "$_procname" \
! 		    -o "$_arg0" = "$_procnamebn" \
! 		    -o "$_arg0" = "${_procnamebn}:" \
! 		    -o "$_arg0" = "(${_procnamebn})" ]; then
  			echo $_npid
  			return
! 		fi
  	done
  }

--- 117,132 ----
  	fi
  	_procnamebn=${_procname##*/}
  	ps -p $_pid -o 'pid,command' | while read _npid _arg0 _argv; do
! 		case "$_npid" in
! 		    PID)
! 			continue ;;
! 		esac
! 		case "$_arg0" in
! 		    $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")
  			echo $_npid
  			return
! 			;;
! 		esac
  	done
  }

*************** check_process()
*** 144,159 ****
  	_procnamebn=${_procname##*/}
  	_pref=
  	ps -ax -o 'pid,command' | while read _npid _arg0 _argv; do
! 		if [ "$_npid" = "PID" ]; then
! 			continue
! 		fi
! 		if [   "$_arg0" = "$_procname" \
! 		    -o "$_arg0" = "$_procnamebn" \
! 		    -o "$_arg0" = "${_procnamebn}:" \
! 		    -o "$_arg0" = "(${_procnamebn})" ]; then
  			echo -n "$_pref$_npid"
  			_pref=" "
! 		fi
  	done
  }

--- 144,159 ----
  	_procnamebn=${_procname##*/}
  	_pref=
  	ps -ax -o 'pid,command' | while read _npid _arg0 _argv; do
! 		case "$_npid" in
! 		    PID)
! 			continue ;;
! 		esac
! 		case "$_arg0" in
! 		    $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")
  			echo -n "$_pref$_npid"
  			_pref=" "
! 			;;
! 		esac
  	done
  }

*************** run_rc_command()
*** 256,262 ****
  {
  	_arg=$1
  	if [ -z "$name" ]; then
! 		err 3 '$name is not set.'
  	fi

  	case "$_arg" in
--- 256,262 ----
  {
  	_arg=$1
  	if [ -z "$name" ]; then
! 		err 3 'run_rc_command: $name is not set.'
  	fi

  	case "$_arg" in
*************** run_rc_command()
*** 297,314 ****
  	else
  		eval _flags=\$${name}_flags
  	fi
! 	eval _chdir=\$${name}_chdir
! 	eval _chroot=\$${name}_chroot
! 	eval _nice=\$${name}_nice
! 	eval _user=\$${name}_user
! 	eval _group=\$${name}_group
! 	eval _groups=\$${name}_groups

  					# if ${rcvar} is set, and $1 is not
  					# "rcvar" or "status", then run
  					#	checkyesno ${rcvar}
  					# and return if that failed
  					#
  	if [ -n "${rcvar}" -a "$_arg" != "rcvar" -a "$_arg" != "status" ]; then
  		if ! checkyesno ${rcvar}; then
  			return 0
--- 297,312 ----
  	else
  		eval _flags=\$${name}_flags
  	fi
! 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
! 	    _nice=\$${name}_nice	_user=\$${name}_user \
! 	    _group=\$${name}_group	_groups=\$${name}_groups

  					# if ${rcvar} is set, and $1 is not
  					# "rcvar" or "status", then run
  					#	checkyesno ${rcvar}
  					# and return if that failed
  					#
+ 	# XXXX use case?
  	if [ -n "${rcvar}" -a "$_arg" != "rcvar" -a "$_arg" != "status" ]; then
  		if ! checkyesno ${rcvar}; then
  			return 0
*************** run_rc_command()
*** 325,332 ****
  					# if there's a custom ${XXX_cmd},
  					# run that instead of the default
  					#
! 		eval _cmd=\$${_arg}_cmd
! 		eval _precmd=\$${_arg}_precmd
  		if [ -n "$_cmd" ]; then
  					# if the precmd failed and force
  					# isn't set, exit
--- 323,329 ----
  					# if there's a custom ${XXX_cmd},
  					# run that instead of the default
  					#
! 		eval _cmd=\$${_arg}_cmd _precmd=\$${_arg}_precmd
  		if [ -n "$_cmd" ]; then
  					# if the precmd failed and force
  					# isn't set, exit
*************** run_rc_script()
*** 515,528 ****
  		err 3 'USAGE: run_rc_script file arg'
  	fi

! 	case "$_file" in
! 	*.sh)				# run in current shell
  		set $_arg ; . $_file
! 		;;
! 	*)				# run in subshell
! 		( set $_arg ; . $_file )
! 		;;
! 	esac
  }

  #
--- 512,532 ----
  		err 3 'USAGE: run_rc_script file arg'
  	fi

! 	if [ -n "$rc_fast_and_loose" ]; then
! 		unset name command command_args extra_commands pidfile rcvar
! 		unset required_dirs required_files required_vars
! 		eval unset ${_arg}_cmd ${_arg}_precmd
  		set $_arg ; . $_file
! 	else
! 		case "$_file" in
! 		*.sh)				# run in current shell
! 			set $_arg ; . $_file
! 			;;
! 		*)				# run in subshell
! 			( set $_arg ; . $_file )
! 			;;
! 		esac
! 	fi
  }

  #
*************** load_rc_config()
*** 536,542 ****
  		err 3 'USAGE: load_rc_config command'
  	fi

! 	. /etc/rc.conf
  	if [ -f /etc/rc.conf.d/"$_command" ]; then
  		. /etc/rc.conf.d/"$_command"
  	fi
--- 540,549 ----
  		err 3 'USAGE: load_rc_config command'
  	fi

! 	if [ -z "$_rc_conf_loaded" ]; then
! 		. /etc/rc.conf
! 		_rc_conf_loaded=YES
! 	fi
  	if [ -f /etc/rc.conf.d/"$_command" ]; then
  		. /etc/rc.conf.d/"$_command"
  	fi