Subject: kern/1969: Add control over autonice time and value
To: None <gnats-bugs@gnats.netbsd.org>
From: Michael Graff <explorer@flame.org>
List: netbsd-bugs
Date: 01/22/1996 16:31:13
>Number:         1969
>Category:       kern
>Synopsis:       Add control over autonice time and value
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 22 17:50:01 1996
>Last-Modified:
>Originator:     Michael Graff <explorer@iastate.edu>
>Organization:
flames 'r' us
>Release:        Jan 21 1996<NetBSD-current source date>
>Environment:
	
System: NetBSD packrat.flame.org 1.1A NetBSD 1.1A (PACKRAT) #3: Sun Jan 21 15:22:08 CST 1996 explorer@packrat.flame.org:/usr/src/sys/arch/i386/compile/PACKRAT i386


>Description:
After the discussion on current users about autonice time and such, I wrote
the following code to allow both compile-time defaults and run-time control.

The defaults (and sample kernel config file entries) are:
options AUTONICETIME=600 # in seconds
options AUTONICEVAL=4    # time niced to after AUTONICETIME seconds

The defaults are found in kern_sysctl.c, and if either of the AUTONICE*
options are set they will override the defaults.

	
>How-To-Repeat:
	
>Fix:

This patch is in ``cvs diff'' format.  If this is not acceptable,
please give me a hint on how to generate nice patches.  :)

The changes are in sysctl.8, sysctl.3, and of course the kernel files
to add the new sysctl options.

Index: lib/libc/gen/sysctl.3
===================================================================
RCS file: /local/source/netbsd/src/lib/libc/gen/sysctl.3,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 sysctl.3
*** 1.1.1.2	1996/01/19 23:15:33
--- sysctl.3	1996/01/22 21:56:04
***************
*** 228,233 ****
--- 228,235 ----
  .Bl -column "KERNXCHOWNXRESTRICTEDXXX" "struct clockrateXXX" -offset indent
  .It Sy Pa Second level name	Type	Changeable
  .It KERN\_ARGMAX	integer	no
+ .It KERN\_AUTONICETIME	integer	yes
+ .It KERN\_AUTONICEVAL	integer	yes
  .It KERN\_BOOTTIME	struct timeval	no
  .It KERN\_CHOWN\_RESTRICTED	integer	no
  .It KERN\_CLOCKRATE	struct clockinfo	no
***************
*** 266,271 ****
--- 268,280 ----
  .It Li KERN_ARGMAX
  The maximum bytes of argument to
  .Xr exec 2 .
+ .It Li KERN_AUTONICETIME
+ The number of seconds of cpu-time a non-root process may accumulate before
+ having its priority lowered from the default to the value of KERN_AUTONICEVAL.
+ If set to 0, automatic lowering of priority is not performed, and if set to -1
+ all non-root processes are immediately lowered.
+ .It Li KERN_AUTONICEVAL
+ The priority assigned for automatically niced processes.
  .It Li KERN_BOOTTIME
  A
  .Va struct timeval
Index: sys/kern/kern_synch.c
===================================================================
RCS file: /local/source/netbsd/src/sys/kern/kern_synch.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 kern_synch.c
*** 1.1.1.1	1996/01/02 22:54:34
--- kern_synch.c	1996/01/22 21:57:02
***************
*** 593,600 ****
  				rlim->rlim_cur += 5;
  		}
  	}
! 	if (s > 10 * 60 && p->p_ucred->cr_uid && p->p_nice == NZERO) {
! 		p->p_nice = NZERO + 4;
  		resetpriority(p);
  	}
  
--- 593,600 ----
  				rlim->rlim_cur += 5;
  		}
  	}
! 	if (autonicetime && s > autonicetime && p->p_ucred->cr_uid && p->p_nice == NZERO) {
! 		p->p_nice = autoniceval;
  		resetpriority(p);
  	}
  
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /local/source/netbsd/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 kern_sysctl.c
*** 1.1.1.1	1996/01/02 22:54:34
--- kern_sysctl.c	1996/01/22 21:57:02
***************
*** 191,196 ****
--- 191,209 ----
  int securelevel;
  #endif
  
+ /* Should this be int or long?  [MLG XXX] */
+ #ifdef AUTONICETIME
+ int autonicetime = AUTONICETIME;
+ #else
+ int autonicetime = (60 * 10);  /* 10 minutes */
+ #endif
+ 
+ #ifdef AUTONICEVAL
+ int autoniceval = AUTONICEVAL;
+ #else
+ int autoniceval = NZERO + 4;   /* default + 4 (usually 0 + 4) */
+ #endif
+ 
  /*
   * kernel related system variables.
   */
***************
*** 285,290 ****
--- 298,312 ----
  		return (sysctl_rdint(oldp, oldlenp, newp, MAXPARTITIONS));
  	case KERN_RAWPARTITION:
  		return (sysctl_rdint(oldp, oldlenp, newp, RAW_PART));
+ 	case KERN_AUTONICETIME:
+ 		return (sysctl_int(oldp, oldlenp, newp, newlen, &autonicetime));
+ 	case KERN_AUTONICEVAL:
+ 		error = sysctl_int(oldp, oldlenp, newp, newlen, &autoniceval);
+ 		if (autoniceval < PRIO_MIN)
+ 			autoniceval = PRIO_MIN;
+ 		if (autoniceval > PRIO_MAX)
+ 			autoniceval = PRIO_MAX;
+ 		return (error);
  	default:
  		return (EOPNOTSUPP);
  	}
Index: sys/sys/sysctl.h
===================================================================
RCS file: /local/source/netbsd/src/sys/sys/sysctl.h,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 sysctl.h
*** 1.1.1.1	1996/01/02 22:55:23
--- sysctl.h	1996/01/22 21:57:08
***************
*** 132,138 ****
  #define	KERN_DOMAINNAME		22	/* string: (YP) domainname */
  #define	KERN_MAXPARTITIONS	23	/* int: number of partitions/disk */
  #define KERN_RAWPARTITION	24	/* int: raw partition number */
! #define	KERN_MAXID		25	/* number of valid kern ids */
  
  #define CTL_KERN_NAMES { \
  	{ 0, 0 }, \
--- 132,140 ----
  #define	KERN_DOMAINNAME		22	/* string: (YP) domainname */
  #define	KERN_MAXPARTITIONS	23	/* int: number of partitions/disk */
  #define KERN_RAWPARTITION	24	/* int: raw partition number */
! #define KERN_AUTONICETIME       25      /* int: proc time before autonice */
! #define KERN_AUTONICEVAL        26      /* int: auto nice value */
! #define	KERN_MAXID		27	/* number of valid kern ids */
  
  #define CTL_KERN_NAMES { \
  	{ 0, 0 }, \
***************
*** 160,165 ****
--- 162,169 ----
  	{ "domainname", CTLTYPE_STRING }, \
  	{ "maxpartitions", CTLTYPE_INT }, \
  	{ "rawpartition", CTLTYPE_INT }, \
+ 	{ "autonicetime", CTLTYPE_INT }, \
+ 	{ "autoniceval", CTLTYPE_INT }, \
  }
  
  /* 
Index: sys/sys/systm.h
===================================================================
RCS file: /local/source/netbsd/src/sys/sys/systm.h,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 systm.h
*** 1.1.1.1	1996/01/02 22:55:23
--- systm.h	1996/01/22 21:57:09
***************
*** 72,77 ****
--- 72,80 ----
  extern char version[];		/* system version */
  extern char copyright[];	/* system copyright */
  
+ extern int autonicetime;        /* time (in seconds) before autoniceval */
+ extern int autoniceval;         /* proc priority after autonicetime */
+ 
  extern int nblkdev;		/* number of entries in bdevsw */
  extern int nchrdev;		/* number of entries in cdevsw */
  extern int nswdev;		/* number of swap devices */
Index: usr.sbin/sysctl/sysctl.8
===================================================================
RCS file: /local/source/netbsd/src/usr.sbin/sysctl/sysctl.8,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 sysctl.8
*** 1.1.1.2	1996/01/19 23:09:56
--- sysctl.8	1996/01/22 21:58:13
***************
*** 130,135 ****
--- 130,137 ----
  .It kern.no_trunc	integer	no
  .It kern.vdisable	integer	no
  .It kern.boottime	struct	no
+ .It kern.autonicetime	integer	yes
+ .It kern.autoniceval	integer	yes
  .It vm.loadavg	struct	no
  .It machdep.console_device	dev_t	no
  .It net.inet.ip.forwarding	integer	yes
	
>Audit-Trail:
>Unformatted: