Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Mar 2004 23:11:34 +0100
From:      Michael Nottebrock <michaelnottebrock@gmx.net>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        Dmitry Morozovsky <marck@rinet.ru>
Subject:   Re: Urk, I take it back (was Re: Bug in p_estcpu handling onprocess exit in FBsd-4.x)
Message-ID:  <200403232311.45422.michaelnottebrock@gmx.net>
In-Reply-To: <200403232001.i2NK1MCx013480@apollo.backplane.com>
References:  <200403201941.i2KJf6Ml095658@apollo.backplane.com> <200403232026.51764.michaelnottebrock@gmx.net> <200403232001.i2NK1MCx013480@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Boundary-03=_gYLYARdRO22u8DV
Content-Type: multipart/mixed;
  boundary="Boundary-01=_WYLYAbHIVv4Rj7w"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--Boundary-01=_WYLYAbHIVv4Rj7w
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Tuesday 23 March 2004 21:01, Matthew Dillon wrote:
>     It looks like it was renamed in 4.x.  INVERSE_ESTCPU_WEIGHT is the
>     define in sys/proc.h

=46rom what I can tell by looking at your cvsweb, you nuked=20
INVERSE_ESTCPU_WEIGHT, invented ESTCPURAMP and renamed and redefined a numb=
er=20
of things as well (see rev 1.24 of sys/kern/kern_synch.c and rev 1.33 of=20
sys/sys/proc.h (dfbsd versioning).

I cobbled together something that actually compiles and didn't panic my=20
machine yet either.

=2D-=20
   ,_,   | Michael Nottebrock               | lofi@freebsd.org
 (/^ ^\) | FreeBSD - The Power to Serve     | http://www.freebsd.org
   \u/   | K Desktop Environment on FreeBSD | http://freebsd.kde.org



--Boundary-01=_WYLYAbHIVv4Rj7w
Content-Type: text/x-diff;
  charset="iso-8859-15";
  name="matt-kernexit-patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
	filename="matt-kernexit-patch"

# $Id: FreeBSD/Patches/contrib/matt-kernexit.patch,v 1.1 2004/03/23 11:00:4=
4 marck Exp $
#
#-DSC-# DFBSD patch for fork-exit-priority bug

Index: sys/sys/proc.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/sys/proc.h,v
retrieving revision 1.99.2.10
diff -u -r1.99.2.10 proc.h
=2D-- sys/sys/proc.h	6 Jul 2003 16:35:47 -0000	1.99.2.10
+++ sys/sys/proc.h	23 Mar 2004 10:49:12 -0000
@@ -165,6 +165,7 @@
=20
 	/* scheduling */
 	u_int	p_estcpu;	 /* Time averaged value of p_cpticks. */
+	u_int	p_estcpu_fork;
 	int	p_cpticks;	 /* Ticks of cpu time. */
 	fixpt_t	p_pctcpu;	 /* %cpu for this process during p_swtime */
 	void	*p_wchan;	 /* Sleep address. */
@@ -375,17 +375,26 @@ extern int	whichrtqs;	/* Bit mask summar
 extern int	whichidqs;	/* Bit mask summary of non-empty Q's. */
=20
 /*
=2D * XXX macros for scheduler.  Shouldn't be here, but currently needed for
=2D * bounding the dubious p_estcpu inheritance in wait1().
=2D * INVERSE_ESTCPU_WEIGHT is only suitable for statclock() frequencies in
=2D * the range 100-256 Hz (approximately).
+ * Scheduler estcpu macros.
+ *
+ * p_priority =3D NICE_ADJUST(p->p_nice - PRIO_MIN) +
+ *			p->p_estcpu / ESTCPURAMP;
+ *
+ * NICE_WEIGHT determines the p_estcpu overlap between nice levels.   It
+ * cannot exceed 3.0.  A value of 2.0 gives us a nice small overlap between
+ * nice -20 and nice +0.  A value of 3.0 reduces the overlap while a value
+ * of 1.0 increases the overlap.
+ *
+ * ESTCPURAMP determines how slowly estcpu effects the process priority.
+ * Higher numbers result in slower ramp-up times because estcpu is increme=
nted
+ * once per scheduler tick and maxes out at ESTCPULIM.
  */
=2D#define	ESTCPULIM(e) \
=2D    min((e), INVERSE_ESTCPU_WEIGHT * (NICE_WEIGHT * PRIO_MAX - PPQ) + \
=2D	     INVERSE_ESTCPU_WEIGHT - 1)
=2D#define	INVERSE_ESTCPU_WEIGHT	8	/* 1 / (priorities per estcpu level) */
=2D#define	NICE_WEIGHT	2		/* priorities per nice level */
=2D#define	PPQ		(128 / NQS)	/* priorities per queue */
+
+#define ESTCPURAMP	8			/* higher equals slower */
+#define NICE_ADJUST(value)	(((unsigned int)(NICE_WEIGHT * 128) * (value)) =
/ 128)
+#define ESTCPULIM(v)	min((v), (MAXPRI - NICE_ADJUST(PRIO_MAX - PRIO_MIN)) =
* ESTCPURAMP)
+#define	NICE_WEIGHT	2.0			/* priorities per nice level */
+#define	PPQ		((MAXPRI + 1) / NQS)	/* priorities per queue */
=20
 extern	u_long ps_arg_cache_limit;
 extern	int ps_argsopen;
Index: sys/kern/kern_exit.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.92.2.13
diff -u -r1.92.2.13 kern_exit.c
=2D-- sys/kern/kern_exit.c	3 Mar 2004 09:21:14 -0000	1.92.2.13
+++ sys/kern/kern_exit.c	23 Mar 2004 10:49:12 -0000
@@ -452,10 +452,16 @@
=20
 		nfound++;
 		if (p->p_stat =3D=3D SZOMB) {
=2D			/* charge childs scheduling cpu usage to parent */
=2D			if (curproc->p_pid !=3D 1) {
=2D				curproc->p_estcpu =3D
=2D				    ESTCPULIM(curproc->p_estcpu + p->p_estcpu);
+			/*
+			 * Charge the parent for the child's change in
+			 * estimated cpu as of when the child exits to
+			 * account for batch scripts, large make's, etc.
+			 */
+			if (q->p_pid !=3D 1) {
+				if (p->p_estcpu > p->p_estcpu_fork) {
+					q->p_estcpu =3D ESTCPULIM(q->p_estcpu +
+					    p->p_estcpu - p->p_estcpu_fork);
+				}                                               =20
 			}
=20
 			q->p_retval[0] =3D p->p_pid;
Index: sys/kern/kern_fork.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.72.2.16
diff -u -r1.72.2.16 kern_fork.c
=2D-- sys/kern/kern_fork.c	11 Nov 2003 07:26:44 -0000	1.72.2.16
+++ sys/kern/kern_fork.c	23 Mar 2004 10:49:12 -0000
@@ -506,7 +506,8 @@
 	/*
 	 * set priority of child to be that of parent
 	 */
=2D	p2->p_estcpu =3D p1->p_estcpu;
+	p2->p_estcpu_fork =3D p2->p_estcpu =3D=20
+		ESTCPULIM(p1->p_estcpu + ESTCPURAMP);
=20
 	/*
 	 * This begins the section where we must prevent the parent
=2D-- sys/kern/kern_synch.c	Tue Mar 23 21:14:24 2004
+++ sys/kern/kern_synch.c	Tue Mar 23 21:17:22 2004
@@ -933,8 +933,8 @@
 	register unsigned int newpriority;
=20
 	if (p->p_rtprio.type =3D=3D RTP_PRIO_NORMAL) {
=2D		newpriority =3D PUSER + p->p_estcpu / INVERSE_ESTCPU_WEIGHT +
=2D		    NICE_WEIGHT * p->p_nice;
+		newpriority =3D NICE_ADJUST(p->p_nice - PRIO_MIN) +
+			p->p_estcpu / ESTCPURAMP;
 		newpriority =3D min(newpriority, MAXPRI);
 		p->p_usrpri =3D newpriority;
 	}
@@ -1009,7 +1009,7 @@
=20
 	p->p_cpticks++;
 	p->p_estcpu =3D ESTCPULIM(p->p_estcpu + 1);
=2D	if ((p->p_estcpu % INVERSE_ESTCPU_WEIGHT) =3D=3D 0) {
+	if ((p->p_estcpu % PPQ) =3D=3D 0)
 		resetpriority(p);
 		if (p->p_priority >=3D PUSER)
 			p->p_priority =3D p->p_usrpri;

--Boundary-01=_WYLYAbHIVv4Rj7w--

--Boundary-03=_gYLYARdRO22u8DV
Content-Type: application/pgp-signature
Content-Description: signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQBAYLYgXhc68WspdLARAkNAAJ9uc2WbPbk4wZlQsV4n6giD8lB06ACdEXFu
/J+pP8513f519fK1EtTVTYQ=
=7mJ6
-----END PGP SIGNATURE-----

--Boundary-03=_gYLYARdRO22u8DV--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403232311.45422.michaelnottebrock>