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.
This commit is contained in:
ws 1996-10-02 18:04:56 +00:00
parent 31afb65969
commit 2da166f660
8 changed files with 30 additions and 26 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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) */

View File

@ -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. */

View File

@ -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;