* Scale the scheduling priority according to the "interactivity" of this * process. */
| 1569 | * process. |
| 1570 | */ |
| 1571 | static void |
| 1572 | sched_priority(struct thread *td) |
| 1573 | { |
| 1574 | int score; |
| 1575 | int pri; |
| 1576 | |
| 1577 | if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE) |
| 1578 | return; |
| 1579 | /* |
| 1580 | * If the score is interactive we place the thread in the realtime |
| 1581 | * queue with a priority that is less than kernel and interrupt |
| 1582 | * priorities. These threads are not subject to nice restrictions. |
| 1583 | * |
| 1584 | * Scores greater than this are placed on the normal timeshare queue |
| 1585 | * where the priority is partially decided by the most recent cpu |
| 1586 | * utilization and the rest is decided by nice value. |
| 1587 | * |
| 1588 | * The nice value of the process has a linear effect on the calculated |
| 1589 | * score. Negative nice values make it easier for a thread to be |
| 1590 | * considered interactive. |
| 1591 | */ |
| 1592 | score = imax(0, sched_interact_score(td) + td->td_proc->p_nice); |
| 1593 | if (score < sched_interact) { |
| 1594 | pri = PRI_MIN_INTERACT; |
| 1595 | pri += ((PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) / |
| 1596 | sched_interact) * score; |
| 1597 | KASSERT(pri >= PRI_MIN_INTERACT && pri <= PRI_MAX_INTERACT, |
| 1598 | ("sched_priority: invalid interactive priority %d score %d", |
| 1599 | pri, score)); |
| 1600 | } else { |
| 1601 | pri = SCHED_PRI_MIN; |
| 1602 | if (td_get_sched(td)->ts_ticks) |
| 1603 | pri += min(SCHED_PRI_TICKS(td_get_sched(td)), |
| 1604 | SCHED_PRI_RANGE - 1); |
| 1605 | pri += SCHED_PRI_NICE(td->td_proc->p_nice); |
| 1606 | KASSERT(pri >= PRI_MIN_BATCH && pri <= PRI_MAX_BATCH, |
| 1607 | ("sched_priority: invalid priority %d: nice %d, " |
| 1608 | "ticks %d ftick %d ltick %d tick pri %d", |
| 1609 | pri, td->td_proc->p_nice, td_get_sched(td)->ts_ticks, |
| 1610 | td_get_sched(td)->ts_ftick, td_get_sched(td)->ts_ltick, |
| 1611 | SCHED_PRI_TICKS(td_get_sched(td)))); |
| 1612 | } |
| 1613 | sched_user_prio(td, pri); |
| 1614 | |
| 1615 | return; |
| 1616 | } |
| 1617 | |
| 1618 | /* |
| 1619 | * This routine enforces a maximum limit on the amount of scheduling history |
no test coverage detected