summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorws <ws@NetBSD.org>1996-10-02 18:04:56 +0000
committerws <ws@NetBSD.org>1996-10-02 18:04:56 +0000
commit2da166f6609eaba44bb4ab92cdd6bc1a8a3c24ff (patch)
tree425e947eee47fc5cd828b7854952d7bb0c9171c6 /sys
parent31afb659695829b0c11f9fca7597d424f08cf56d (diff)
Fix p_nice vs. NZERO code.
Change NZERO to 20 to always make p_nice positive. On Christos' suggestion make p_nice explicitly u_char.
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/hpux/hpux_compat.c12
-rw-r--r--sys/compat/ibcs2/ibcs2_misc.c6
-rw-r--r--sys/conf/param.c7
-rw-r--r--sys/kern/kern_resource.c9
-rw-r--r--sys/kern/kern_synch.c9
-rw-r--r--sys/sys/param.h4
-rw-r--r--sys/sys/proc.h4
-rw-r--r--sys/vm/vm_glue.c5
8 files changed, 30 insertions, 26 deletions
diff --git a/sys/compat/hpux/hpux_compat.c b/sys/compat/hpux/hpux_compat.c
index 548691e5ea2..5df8f5635ec 100644
--- a/sys/compat/hpux/hpux_compat.c
+++ b/sys/compat/hpux/hpux_compat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hpux_compat.c,v 1.25 1996/06/23 11:10:01 mycroft Exp $ */
+/* $NetBSD: hpux_compat.c,v 1.26 1996/10/02 18:04:56 ws Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -548,8 +548,8 @@ hpux_sys_rtprio(cp, v, retval)
p = cp;
else if ((p = pfind(SCARG(uap, pid))) == 0)
return (ESRCH);
- nice = p->p_nice;
- if (nice < NZERO)
+ nice = p->p_nice - NZERO;
+ if (nice < 0)
*retval = (nice + 16) << 3;
else
*retval = RTPRIO_RTOFF;
@@ -559,9 +559,9 @@ hpux_sys_rtprio(cp, v, retval)
return (0);
case RTPRIO_RTOFF:
- if (nice >= NZERO)
+ if (nice >= 0)
return (0);
- nice = NZERO;
+ nice = 0;
break;
default:
@@ -1321,7 +1321,7 @@ hpux_sys_nice_6x(p, v, retval)
} */ *uap = v;
int error;
- error = donice(p, p, (p->p_nice-NZERO)+SCARG(uap, nval));
+ error = donice(p, p, (p->p_nice - NZERO) + SCARG(uap, nval));
if (error == 0)
*retval = p->p_nice - NZERO;
return (error);
diff --git a/sys/compat/ibcs2/ibcs2_misc.c b/sys/compat/ibcs2/ibcs2_misc.c
index 9cb8c8917ba..c7e624413ac 100644
--- a/sys/compat/ibcs2/ibcs2_misc.c
+++ b/sys/compat/ibcs2/ibcs2_misc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ibcs2_misc.c,v 1.20 1996/09/07 12:40:43 mycroft Exp $ */
+/* $NetBSD: ibcs2_misc.c,v 1.21 1996/10/02 18:04:59 ws Exp $ */
/*
* Copyright (c) 1994, 1995 Scott Bartram
@@ -1027,10 +1027,10 @@ ibcs2_sys_nice(p, v, retval)
SCARG(&sa, which) = PRIO_PROCESS;
SCARG(&sa, who) = 0;
- SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr);
+ SCARG(&sa, prio) = p->p_nice - NZERO + SCARG(uap, incr);
if ((error = sys_setpriority(p, &sa, retval)) != 0)
return EPERM;
- *retval = p->p_nice;
+ *retval = p->p_nice - NZERO;
return 0;
}
diff --git a/sys/conf/param.c b/sys/conf/param.c
index a4d9f133a11..094628439cf 100644
--- a/sys/conf/param.c
+++ b/sys/conf/param.c
@@ -1,4 +1,4 @@
-/* $NetBSD: param.c,v 1.17 1996/07/17 21:52:18 explorer Exp $ */
+/* $NetBSD: param.c,v 1.18 1996/10/02 18:05:02 ws Exp $ */
/*
* Copyright (c) 1980, 1986, 1989 Regents of the University of California.
@@ -174,16 +174,17 @@ struct utsname utsname;
/*
* These control when and to what priority a process gets after a certain
* amount of CPU time expires. AUTONICETIME is in seconds.
+ * AUTONICEVAL is NOT offset by NZERO, i.e. it's between PRIO_MIN and PRIO_MAX.
*/
#ifdef AUTONICETIME
int autonicetime = AUTONICETIME;
#else
-int autonicetime = (60 * 10); /* 10 minutes */
+int autonicetime = (60 * 10); /* 10 minutes */
#endif
#ifdef AUTONICEVAL
int autoniceval = AUTONICEVAL;
#else
-int autoniceval = NZERO + 4; /* default + 4 (usually 0 + 4) */
+int autoniceval = 4; /* default + 4 */
#endif
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index f37468345e7..fe9df229e4a 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_resource.c,v 1.36 1996/07/11 00:09:29 jtc Exp $ */
+/* $NetBSD: kern_resource.c,v 1.37 1996/10/02 18:05:03 ws Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
@@ -69,7 +69,7 @@ sys_getpriority(curp, v, retval)
syscallarg(int) who;
} */ *uap = v;
register struct proc *p;
- register int low = PRIO_MAX + 1;
+ register int low = NZERO + PRIO_MAX + 1;
switch (SCARG(uap, which)) {
@@ -109,9 +109,9 @@ sys_getpriority(curp, v, retval)
default:
return (EINVAL);
}
- if (low == PRIO_MAX + 1)
+ if (low == NZERO + PRIO_MAX + 1)
return (ESRCH);
- *retval = low;
+ *retval = low - NZERO;
return (0);
}
@@ -191,6 +191,7 @@ donice(curp, chgp, n)
n = PRIO_MAX;
if (n < PRIO_MIN)
n = PRIO_MIN;
+ n += NZERO;
if (n < chgp->p_nice && suser(pcred->pc_ucred, &curp->p_acflag))
return (EACCES);
chgp->p_nice = n;
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 88544472806..90e80e1fbea 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_synch.c,v 1.38 1996/07/17 21:54:06 explorer Exp $ */
+/* $NetBSD: kern_synch.c,v 1.39 1996/10/02 18:05:05 ws Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1991, 1993
@@ -204,7 +204,8 @@ schedcpu(arg)
(p->p_cpticks * FSCALE / hz)) >> FSHIFT;
#endif
p->p_cpticks = 0;
- newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu) + p->p_nice;
+ newcpu = (u_int)decay_cpu(loadfac, p->p_estcpu)
+ + p->p_nice - NZERO;
p->p_estcpu = min(newcpu, UCHAR_MAX);
resetpriority(p);
if (p->p_priority >= PUSER) {
@@ -599,7 +600,7 @@ mi_switch()
}
}
if (autonicetime && s > autonicetime && p->p_ucred->cr_uid && p->p_nice == NZERO) {
- p->p_nice = autoniceval;
+ p->p_nice = autoniceval + NZERO;
resetpriority(p);
}
@@ -680,7 +681,7 @@ resetpriority(p)
{
register unsigned int newpriority;
- newpriority = PUSER + p->p_estcpu / 4 + 2 * p->p_nice;
+ newpriority = PUSER + p->p_estcpu / 4 + 2 * (p->p_nice - NZERO);
newpriority = min(newpriority, MAXPRI);
p->p_usrpri = newpriority;
if (newpriority < curpriority)
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 34b60fe1fbb..c7b1b823d56 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.24 1996/05/25 22:07:35 jtc Exp $ */
+/* $NetBSD: param.h,v 1.25 1996/10/02 18:05:07 ws Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -111,7 +111,7 @@
#define PRIMASK 0x0ff
#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
-#define NZERO 0 /* default "nice" */
+#define NZERO 20 /* default "nice" */
#define NBPW sizeof(int) /* number of bytes per word (integer) */
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index f9d836c8ced..7930fae19e0 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.45 1996/09/07 12:41:33 mycroft Exp $ */
+/* $NetBSD: proc.h,v 1.46 1996/10/02 18:05:09 ws Exp $ */
/*-
* Copyright (c) 1986, 1989, 1991, 1993
@@ -179,7 +179,7 @@ struct proc {
u_char p_priority; /* Process priority. */
u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
- char p_nice; /* Process "nice" value. */
+ u_char p_nice; /* Process "nice" value. */
char p_comm[MAXCOMLEN+1];
struct pgrp *p_pgrp; /* Pointer to process group. */
diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c
index 8de68070d7a..5e0d1271951 100644
--- a/sys/vm/vm_glue.c
+++ b/sys/vm/vm_glue.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_glue.c,v 1.56 1996/05/29 21:20:11 pk Exp $ */
+/* $NetBSD: vm_glue.c,v 1.57 1996/10/02 18:05:10 ws Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -379,7 +379,8 @@ loop:
ppri = INT_MIN;
for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
if (p->p_stat == SRUN && (p->p_flag & P_INMEM) == 0) {
- pri = p->p_swtime + p->p_slptime - p->p_nice * 8;
+ pri = p->p_swtime + p->p_slptime
+ - (p->p_nice - NZERO) * 8;
if (pri > ppri) {
pp = p;
ppri = pri;