/* kern_synch.c 6.2 84/05/22 */
#include "../machine/pte.h"
#include "../vax/mtpr.h" /* XXX */
* Force switch among equal priority processes every 100ms.
timeout(roundrobin
, (caddr_t
)0, hz
/ 10);
/* constants to digital decay and forget 90% of usage in 5*loadav time */
#define ave(a,b) ((int)(((int)(a*b))/(b+1)))
double ccpu
= 0.95122942450071400909; /* exp(-1/20) */
* Recompute process priorities, once a second
for (p
= allproc
; p
!= NULL
; p
= p
->p_nxt
) {
if (p
->p_stat
==SSLEEP
|| p
->p_stat
==SSTOP
)
p
->p_pctcpu
= ccpu
* p
->p_pctcpu
+
(1.0 - ccpu
) * (p
->p_cpticks
/(float)hz
);
a
= ave((p
->p_cpu
& 0377), avenrun
[0]*nrscale
) +
s
= spl6(); /* prevent state changes */
if ((p
!= u
.u_procp
|| noproc
) &&
p
->p_pri
!= p
->p_usrpri
) {
wakeup((caddr_t
)&proc
[2]);
timeout(schedcpu
, (caddr_t
)0, hz
);
#define SQSIZE 0100 /* Must be power of 2 */
#define HASH(x) (( (int) x >> 5) & (SQSIZE-1))
struct proc
*slpque
[SQSIZE
];
* Give up the processor till a wakeup occurs
* on chan, at which time the process
* enters the scheduling queue at priority pri.
* The most important effect of pri is that when
* pri<=PZERO a signal cannot disturb the sleep;
* if pri>PZERO signals will be processed.
* Callers of this routine must be prepared for
* premature return, and check that the reason for
* sleeping has gone away.
register struct proc
*rp
, **hp
;
if (chan
==0 || rp
->p_stat
!= SRUN
|| rp
->p_rlink
)
hp
= &slpque
[HASH(chan
)];
* If priority was low (>PZERO) and
* there has been a signal, execute non-local goto through
* u.u_qsave, aborting the system call in progress (see trap.c)
* (or finishing a tsleep, see below)
* Remove a process from its wait queue
register struct proc
**hp
;
hp
= &slpque
[HASH(p
->p_wchan
)];
* Wake up all processes sleeping on chan.
register struct proc
*p
, **q
, **h
;
if (p
->p_rlink
|| p
->p_stat
!= SSLEEP
&& p
->p_stat
!= SSTOP
)
if (p
->p_stat
== SSLEEP
) {
/* OPTIMIZED INLINE EXPANSION OF setrun(p) */
if ((p
->p_flag
&SLOAD
) == 0) {
wakeup((caddr_t
)&runout
);
/* END INLINE EXPANSION */
* Initialize the (doubly-linked) run queues
for (i
= 0; i
< NQS
; i
++)
qs
[i
].ph_link
= qs
[i
].ph_rlink
= (struct proc
*)&qs
[i
];
* Set the process running;
* arrange for it to be swapped in if necessary.
unsleep(p
); /* e.g. when sending signals */
if ((p
->p_flag
&SLOAD
) == 0) {
wakeup((caddr_t
)&runout
);
* The rescheduling flag (runrun)
* is set if the priority is better
* than the currently running process.
register struct proc
*pp
;
p
= (pp
->p_cpu
& 0377)/4;
p
+= PUSER
+ 2*(pp
->p_nice
- NZERO
);
if (pp
->p_rssize
> pp
->p_maxrss
&& freemem
< desfree
)
p
+= 2*4; /* effectively, nice(4) */