kern_synch.c revision 25164
1/*- 2 * Copyright (c) 1982, 1986, 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 39 * $Id: kern_synch.c,v 1.30 1997/02/27 18:03:48 bde Exp $ 40 */ 41 42#include "opt_ktrace.h" 43#include "opt_smp.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/proc.h> 48#include <sys/kernel.h> 49#include <sys/buf.h> 50#include <sys/signalvar.h> 51#include <sys/resourcevar.h> 52#include <sys/signalvar.h> 53#include <sys/vmmeter.h> 54#include <vm/vm.h> 55#include <vm/vm_param.h> 56#include <vm/vm_extern.h> 57#ifdef KTRACE 58#include <sys/ktrace.h> 59#endif 60 61#include <machine/cpu.h> 62 63static void rqinit __P((void *)); 64SYSINIT(runqueue, SI_SUB_RUN_QUEUE, SI_ORDER_FIRST, rqinit, NULL) 65 66u_char curpriority; /* usrpri of curproc */ 67int lbolt; /* once a second sleep address */ 68 69extern void endtsleep __P((void *)); 70extern void updatepri __P((struct proc *p)); 71 72/* 73 * Force switch among equal priority processes every 100ms. 74 */ 75/* ARGSUSED */ 76void 77roundrobin(arg) 78 void *arg; 79{ 80 81 need_resched(); 82 timeout(roundrobin, NULL, hz / 10); 83} 84 85/* 86 * Constants for digital decay and forget: 87 * 90% of (p_estcpu) usage in 5 * loadav time 88 * 95% of (p_pctcpu) usage in 60 seconds (load insensitive) 89 * Note that, as ps(1) mentions, this can let percentages 90 * total over 100% (I've seen 137.9% for 3 processes). 91 * 92 * Note that statclock updates p_estcpu and p_cpticks independently. 93 * 94 * We wish to decay away 90% of p_estcpu in (5 * loadavg) seconds. 95 * That is, the system wants to compute a value of decay such 96 * that the following for loop: 97 * for (i = 0; i < (5 * loadavg); i++) 98 * p_estcpu *= decay; 99 * will compute 100 * p_estcpu *= 0.1; 101 * for all values of loadavg: 102 * 103 * Mathematically this loop can be expressed by saying: 104 * decay ** (5 * loadavg) ~= .1 105 * 106 * The system computes decay as: 107 * decay = (2 * loadavg) / (2 * loadavg + 1) 108 * 109 * We wish to prove that the system's computation of decay 110 * will always fulfill the equation: 111 * decay ** (5 * loadavg) ~= .1 112 * 113 * If we compute b as: 114 * b = 2 * loadavg 115 * then 116 * decay = b / (b + 1) 117 * 118 * We now need to prove two things: 119 * 1) Given factor ** (5 * loadavg) ~= .1, prove factor == b/(b+1) 120 * 2) Given b/(b+1) ** power ~= .1, prove power == (5 * loadavg) 121 * 122 * Facts: 123 * For x close to zero, exp(x) =~ 1 + x, since 124 * exp(x) = 0! + x**1/1! + x**2/2! + ... . 125 * therefore exp(-1/b) =~ 1 - (1/b) = (b-1)/b. 126 * For x close to zero, ln(1+x) =~ x, since 127 * ln(1+x) = x - x**2/2 + x**3/3 - ... -1 < x < 1 128 * therefore ln(b/(b+1)) = ln(1 - 1/(b+1)) =~ -1/(b+1). 129 * ln(.1) =~ -2.30 130 * 131 * Proof of (1): 132 * Solve (factor)**(power) =~ .1 given power (5*loadav): 133 * solving for factor, 134 * ln(factor) =~ (-2.30/5*loadav), or 135 * factor =~ exp(-1/((5/2.30)*loadav)) =~ exp(-1/(2*loadav)) = 136 * exp(-1/b) =~ (b-1)/b =~ b/(b+1). QED 137 * 138 * Proof of (2): 139 * Solve (factor)**(power) =~ .1 given factor == (b/(b+1)): 140 * solving for power, 141 * power*ln(b/(b+1)) =~ -2.30, or 142 * power =~ 2.3 * (b + 1) = 4.6*loadav + 2.3 =~ 5*loadav. QED 143 * 144 * Actual power values for the implemented algorithm are as follows: 145 * loadav: 1 2 3 4 146 * power: 5.68 10.32 14.94 19.55 147 */ 148 149/* calculations for digital decay to forget 90% of usage in 5*loadav sec */ 150#define loadfactor(loadav) (2 * (loadav)) 151#define decay_cpu(loadfac, cpu) (((loadfac) * (cpu)) / ((loadfac) + FSCALE)) 152 153/* decay 95% of `p_pctcpu' in 60 seconds; see CCPU_SHIFT before changing */ 154fixpt_t ccpu = 0.95122942450071400909 * FSCALE; /* exp(-1/20) */ 155 156/* 157 * If `ccpu' is not equal to `exp(-1/20)' and you still want to use the 158 * faster/more-accurate formula, you'll have to estimate CCPU_SHIFT below 159 * and possibly adjust FSHIFT in "param.h" so that (FSHIFT >= CCPU_SHIFT). 160 * 161 * To estimate CCPU_SHIFT for exp(-1/20), the following formula was used: 162 * 1 - exp(-1/20) ~= 0.0487 ~= 0.0488 == 1 (fixed pt, *11* bits). 163 * 164 * If you dont want to bother with the faster/more-accurate formula, you 165 * can set CCPU_SHIFT to (FSHIFT + 1) which will use a slower/less-accurate 166 * (more general) method of calculating the %age of CPU used by a process. 167 */ 168#define CCPU_SHIFT 11 169 170/* 171 * Recompute process priorities, every hz ticks. 172 */ 173/* ARGSUSED */ 174void 175schedcpu(arg) 176 void *arg; 177{ 178 register fixpt_t loadfac = loadfactor(averunnable.ldavg[0]); 179 register struct proc *p; 180 register int s, i, j; 181 register unsigned int newcpu; 182 183 wakeup((caddr_t)&lbolt); 184 for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) { 185 /* 186 * Increment time in/out of memory and sleep time 187 * (if sleeping). We ignore overflow; with 16-bit int's 188 * (remember them?) overflow takes 45 days. 189 */ 190 p->p_swtime++; 191 if (p->p_stat == SSLEEP || p->p_stat == SSTOP) 192 p->p_slptime++; 193 p->p_pctcpu = (p->p_pctcpu * ccpu) >> FSHIFT; 194 /* 195 * If the process has slept the entire second, 196 * stop recalculating its priority until it wakes up. 197 */ 198 if (p->p_slptime > 1) 199 continue; 200 s = splhigh(); /* prevent state changes and protect run queue */ 201 /* 202 * p_pctcpu is only for ps. 203 */ 204#if (FSHIFT >= CCPU_SHIFT) 205 p->p_pctcpu += (hz == 100)? 206 ((fixpt_t) p->p_cpticks) << (FSHIFT - CCPU_SHIFT): 207 100 * (((fixpt_t) p->p_cpticks) 208 << (FSHIFT - CCPU_SHIFT)) / hz; 209#else 210 p->p_pctcpu += ((FSCALE - ccpu) * 211 (p->p_cpticks * FSCALE / hz)) >> FSHIFT; 212#endif 213 p->p_cpticks = 0; 214 newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu) + p->p_nice; 215 p->p_estcpu = min(newcpu, UCHAR_MAX); 216 resetpriority(p); 217 if (p->p_priority >= PUSER) { 218#define PPQ (128 / NQS) /* priorities per queue */ 219#ifdef SMP 220 for (j = i = 0; i < NCPU; i++) { 221 if (p == SMPcurproc[i]) 222 j++; 223 } 224 if (!j && 225 226#else 227 if ((p != curproc) && 228#endif 229 p->p_stat == SRUN && 230 (p->p_flag & P_INMEM) && 231 (p->p_priority / PPQ) != (p->p_usrpri / PPQ)) { 232 remrq(p); 233 p->p_priority = p->p_usrpri; 234 setrunqueue(p); 235 } else 236 p->p_priority = p->p_usrpri; 237 } 238 splx(s); 239 not_mine: 240 } 241 vmmeter(); 242 timeout(schedcpu, (void *)0, hz); 243} 244 245/* 246 * Recalculate the priority of a process after it has slept for a while. 247 * For all load averages >= 1 and max p_estcpu of 255, sleeping for at 248 * least six times the loadfactor will decay p_estcpu to zero. 249 */ 250void 251updatepri(p) 252 register struct proc *p; 253{ 254 register unsigned int newcpu = p->p_estcpu; 255 register fixpt_t loadfac = loadfactor(averunnable.ldavg[0]); 256 257 if (p->p_slptime > 5 * loadfac) 258 p->p_estcpu = 0; 259 else { 260 p->p_slptime--; /* the first time was done in schedcpu */ 261 while (newcpu && --p->p_slptime) 262 newcpu = (int) decay_cpu(loadfac, newcpu); 263 p->p_estcpu = min(newcpu, UCHAR_MAX); 264 } 265 resetpriority(p); 266} 267 268/* 269 * We're only looking at 7 bits of the address; everything is 270 * aligned to 4, lots of things are aligned to greater powers 271 * of 2. Shift right by 8, i.e. drop the bottom 256 worth. 272 */ 273#define TABLESIZE 128 274TAILQ_HEAD(slpquehead, proc) slpque[TABLESIZE]; 275#define LOOKUP(x) (((long)(x) >> 8) & (TABLESIZE - 1)) 276 277/* 278 * During autoconfiguration or after a panic, a sleep will simply 279 * lower the priority briefly to allow interrupts, then return. 280 * The priority to be used (safepri) is machine-dependent, thus this 281 * value is initialized and maintained in the machine-dependent layers. 282 * This priority will typically be 0, or the lowest priority 283 * that is safe for use on the interrupt stack; it can be made 284 * higher to block network software interrupts after panics. 285 */ 286int safepri; 287 288void 289sleepinit() 290{ 291 int i; 292 293 for (i = 0; i < TABLESIZE; i++) 294 TAILQ_INIT(&slpque[i]); 295} 296 297/* 298 * General sleep call. Suspends the current process until a wakeup is 299 * performed on the specified identifier. The process will then be made 300 * runnable with the specified priority. Sleeps at most timo/hz seconds 301 * (0 means no timeout). If pri includes PCATCH flag, signals are checked 302 * before and after sleeping, else signals are not checked. Returns 0 if 303 * awakened, EWOULDBLOCK if the timeout expires. If PCATCH is set and a 304 * signal needs to be delivered, ERESTART is returned if the current system 305 * call should be restarted if possible, and EINTR is returned if the system 306 * call should be interrupted by the signal (return EINTR). 307 */ 308int 309tsleep(ident, priority, wmesg, timo) 310 void *ident; 311 int priority, timo; 312 char *wmesg; 313{ 314 struct proc *p = curproc; 315 int s, sig, catch = priority & PCATCH; 316 317#ifdef KTRACE 318 if (KTRPOINT(p, KTR_CSW)) 319 ktrcsw(p->p_tracep, 1, 0); 320#endif 321 s = splhigh(); 322 if (cold || panicstr) { 323 /* 324 * After a panic, or during autoconfiguration, 325 * just give interrupts a chance, then just return; 326 * don't run any other procs or panic below, 327 * in case this is the idle process and already asleep. 328 */ 329 splx(safepri); 330 splx(s); 331 return (0); 332 } 333#ifdef DIAGNOSTIC 334 if (ident == NULL || p->p_stat != SRUN) 335 panic("tsleep"); 336#endif 337 p->p_wchan = ident; 338 p->p_wmesg = wmesg; 339 p->p_slptime = 0; 340 p->p_priority = priority & PRIMASK; 341 TAILQ_INSERT_TAIL(&slpque[LOOKUP(ident)], p, p_procq); 342 if (timo) 343 timeout(endtsleep, (void *)p, timo); 344 /* 345 * We put ourselves on the sleep queue and start our timeout 346 * before calling CURSIG, as we could stop there, and a wakeup 347 * or a SIGCONT (or both) could occur while we were stopped. 348 * A SIGCONT would cause us to be marked as SSLEEP 349 * without resuming us, thus we must be ready for sleep 350 * when CURSIG is called. If the wakeup happens while we're 351 * stopped, p->p_wchan will be 0 upon return from CURSIG. 352 */ 353 if (catch) { 354 p->p_flag |= P_SINTR; 355 if ((sig = CURSIG(p))) { 356 if (p->p_wchan) 357 unsleep(p); 358 p->p_stat = SRUN; 359 goto resume; 360 } 361 if (p->p_wchan == 0) { 362 catch = 0; 363 goto resume; 364 } 365 } else 366 sig = 0; 367 p->p_stat = SSLEEP; 368 p->p_stats->p_ru.ru_nvcsw++; 369 mi_switch(); 370resume: 371 curpriority = p->p_usrpri; 372 splx(s); 373 p->p_flag &= ~P_SINTR; 374 if (p->p_flag & P_TIMEOUT) { 375 p->p_flag &= ~P_TIMEOUT; 376 if (sig == 0) { 377#ifdef KTRACE 378 if (KTRPOINT(p, KTR_CSW)) 379 ktrcsw(p->p_tracep, 0, 0); 380#endif 381 return (EWOULDBLOCK); 382 } 383 } else if (timo) 384 untimeout(endtsleep, (void *)p); 385 if (catch && (sig != 0 || (sig = CURSIG(p)))) { 386#ifdef KTRACE 387 if (KTRPOINT(p, KTR_CSW)) 388 ktrcsw(p->p_tracep, 0, 0); 389#endif 390 if (p->p_sigacts->ps_sigintr & sigmask(sig)) 391 return (EINTR); 392 return (ERESTART); 393 } 394#ifdef KTRACE 395 if (KTRPOINT(p, KTR_CSW)) 396 ktrcsw(p->p_tracep, 0, 0); 397#endif 398 return (0); 399} 400 401/* 402 * Implement timeout for tsleep. 403 * If process hasn't been awakened (wchan non-zero), 404 * set timeout flag and undo the sleep. If proc 405 * is stopped, just unsleep so it will remain stopped. 406 */ 407void 408endtsleep(arg) 409 void *arg; 410{ 411 register struct proc *p; 412 int s; 413 414 p = (struct proc *)arg; 415 s = splhigh(); 416 if (p->p_wchan) { 417 if (p->p_stat == SSLEEP) 418 setrunnable(p); 419 else 420 unsleep(p); 421 p->p_flag |= P_TIMEOUT; 422 } 423 splx(s); 424} 425 426/* 427 * Remove a process from its wait queue 428 */ 429void 430unsleep(p) 431 register struct proc *p; 432{ 433 int s; 434 435 s = splhigh(); 436 if (p->p_wchan) { 437 TAILQ_REMOVE(&slpque[LOOKUP(p->p_wchan)], p, p_procq); 438 p->p_wchan = 0; 439 } 440 splx(s); 441} 442 443/* 444 * Make all processes sleeping on the specified identifier runnable. 445 */ 446void 447wakeup(ident) 448 register void *ident; 449{ 450 register struct slpquehead *qp; 451 register struct proc *p; 452 int s; 453 454 s = splhigh(); 455 qp = &slpque[LOOKUP(ident)]; 456restart: 457 for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) { 458#ifdef DIAGNOSTIC 459 if (p->p_stat != SSLEEP && p->p_stat != SSTOP) 460 panic("wakeup"); 461#endif 462 if (p->p_wchan == ident) { 463 TAILQ_REMOVE(qp, p, p_procq); 464 p->p_wchan = 0; 465 if (p->p_stat == SSLEEP) { 466 /* OPTIMIZED EXPANSION OF setrunnable(p); */ 467 if (p->p_slptime > 1) 468 updatepri(p); 469 p->p_slptime = 0; 470 p->p_stat = SRUN; 471 if (p->p_flag & P_INMEM) { 472 setrunqueue(p); 473 need_resched(); 474 } else { 475 p->p_flag |= P_SWAPINREQ; 476 wakeup((caddr_t)&proc0); 477 } 478 /* END INLINE EXPANSION */ 479 goto restart; 480 } 481 } 482 } 483 splx(s); 484} 485 486/* 487 * Make a process sleeping on the specified identifier runnable. 488 * May wake more than one process if a target prcoess is currently 489 * swapped out. 490 */ 491void 492wakeup_one(ident) 493 register void *ident; 494{ 495 register struct slpquehead *qp; 496 register struct proc *p; 497 int s; 498 499 s = splhigh(); 500 qp = &slpque[LOOKUP(ident)]; 501 502 for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) { 503#ifdef DIAGNOSTIC 504 if (p->p_stat != SSLEEP && p->p_stat != SSTOP) 505 panic("wakeup_one"); 506#endif 507 if (p->p_wchan == ident) { 508 TAILQ_REMOVE(qp, p, p_procq); 509 p->p_wchan = 0; 510 if (p->p_stat == SSLEEP) { 511 /* OPTIMIZED EXPANSION OF setrunnable(p); */ 512 if (p->p_slptime > 1) 513 updatepri(p); 514 p->p_slptime = 0; 515 p->p_stat = SRUN; 516 if (p->p_flag & P_INMEM) { 517 setrunqueue(p); 518 need_resched(); 519 break; 520 } else { 521 p->p_flag |= P_SWAPINREQ; 522 wakeup((caddr_t)&proc0); 523 } 524 /* END INLINE EXPANSION */ 525 } 526 } 527 } 528 splx(s); 529} 530 531/* 532 * The machine independent parts of mi_switch(). 533 * Must be called at splstatclock() or higher. 534 */ 535void 536mi_switch() 537{ 538 register struct proc *p = curproc; /* XXX */ 539 register struct rlimit *rlim; 540 register long s, u; 541 int x; 542 struct timeval tv; 543 544 /* 545 * XXX this spl is almost unnecessary. It is partly to allow for 546 * sloppy callers that don't do it (issignal() via CURSIG() is the 547 * main offender). It is partly to work around a bug in the i386 548 * cpu_switch() (the ipl is not preserved). We ran for years 549 * without it. I think there was only a interrupt latency problem. 550 * The main caller, tsleep(), does an splx() a couple of instructions 551 * after calling here. The buggy caller, issignal(), usually calls 552 * here at spl0() and sometimes returns at splhigh(). The process 553 * then runs for a little too long at splhigh(). The ipl gets fixed 554 * when the process returns to user mode (or earlier). 555 * 556 * It would probably be better to always call here at spl0(). Callers 557 * are prepared to give up control to another process, so they must 558 * be prepared to be interrupted. The clock stuff here may not 559 * actually need splstatclock(). 560 */ 561 x = splstatclock(); 562 563#ifdef SIMPLELOCK_DEBUG 564 if (p->p_simple_locks) 565 printf("sleep: holding simple lock"); 566#endif 567 /* 568 * Compute the amount of time during which the current 569 * process was running, and add that to its total so far. 570 */ 571 microtime(&tv); 572 u = p->p_rtime.tv_usec + (tv.tv_usec - runtime.tv_usec); 573 s = p->p_rtime.tv_sec + (tv.tv_sec - runtime.tv_sec); 574 if (u < 0) { 575 u += 1000000; 576 s--; 577 } else if (u >= 1000000) { 578 u -= 1000000; 579 s++; 580 } 581#ifdef SMP 582 if (s < 0) 583 s = u = 0; 584#endif 585 p->p_rtime.tv_usec = u; 586 p->p_rtime.tv_sec = s; 587 588 /* 589 * Check if the process exceeds its cpu resource allocation. 590 * If over max, kill it. 591 */ 592 if (p->p_stat != SZOMB) { 593 rlim = &p->p_rlimit[RLIMIT_CPU]; 594 if (s >= rlim->rlim_cur) { 595 if (s >= rlim->rlim_max) 596 killproc(p, "exceeded maximum CPU limit"); 597 else { 598 psignal(p, SIGXCPU); 599 if (rlim->rlim_cur < rlim->rlim_max) 600 rlim->rlim_cur += 5; 601 } 602 } 603 } 604 605 /* 606 * Pick a new current process and record its start time. 607 */ 608 cnt.v_swtch++; 609 cpu_switch(p); 610 microtime(&runtime); 611 splx(x); 612} 613 614/* 615 * Initialize the (doubly-linked) run queues 616 * to be empty. 617 */ 618/* ARGSUSED*/ 619static void 620rqinit(dummy) 621 void *dummy; 622{ 623 register int i; 624 625 for (i = 0; i < NQS; i++) { 626 qs[i].ph_link = qs[i].ph_rlink = (struct proc *)&qs[i]; 627 rtqs[i].ph_link = rtqs[i].ph_rlink = (struct proc *)&rtqs[i]; 628 idqs[i].ph_link = idqs[i].ph_rlink = (struct proc *)&idqs[i]; 629 } 630} 631 632/* 633 * Change process state to be runnable, 634 * placing it on the run queue if it is in memory, 635 * and awakening the swapper if it isn't in memory. 636 */ 637void 638setrunnable(p) 639 register struct proc *p; 640{ 641 register int s; 642 643 s = splhigh(); 644 switch (p->p_stat) { 645 case 0: 646 case SRUN: 647 case SZOMB: 648 default: 649 panic("setrunnable"); 650 case SSTOP: 651 case SSLEEP: 652 unsleep(p); /* e.g. when sending signals */ 653 break; 654 655 case SIDL: 656 break; 657 } 658 p->p_stat = SRUN; 659 if (p->p_flag & P_INMEM) 660 setrunqueue(p); 661 splx(s); 662 if (p->p_slptime > 1) 663 updatepri(p); 664 p->p_slptime = 0; 665 if ((p->p_flag & P_INMEM) == 0) { 666 p->p_flag |= P_SWAPINREQ; 667 wakeup((caddr_t)&proc0); 668 } 669 else if (p->p_priority < curpriority) 670 need_resched(); 671} 672 673/* 674 * Compute the priority of a process when running in user mode. 675 * Arrange to reschedule if the resulting priority is better 676 * than that of the current process. 677 */ 678void 679resetpriority(p) 680 register struct proc *p; 681{ 682 register unsigned int newpriority; 683 684 if (p->p_rtprio.type == RTP_PRIO_NORMAL) { 685 newpriority = PUSER + p->p_estcpu / 4 + 2 * p->p_nice; 686 newpriority = min(newpriority, MAXPRI); 687 p->p_usrpri = newpriority; 688 if (newpriority < curpriority) 689 need_resched(); 690 } else { 691 need_resched(); 692 } 693} 694