* This routine enforces a maximum limit on the amount of scheduling history * kept. It is called after either the slptime or runtime is adjusted. This * function is ugly due to integer math. */
| 1621 | * function is ugly due to integer math. |
| 1622 | */ |
| 1623 | static void |
| 1624 | sched_interact_update(struct thread *td) |
| 1625 | { |
| 1626 | struct td_sched *ts; |
| 1627 | u_int sum; |
| 1628 | |
| 1629 | ts = td_get_sched(td); |
| 1630 | sum = ts->ts_runtime + ts->ts_slptime; |
| 1631 | if (sum < SCHED_SLP_RUN_MAX) |
| 1632 | return; |
| 1633 | /* |
| 1634 | * This only happens from two places: |
| 1635 | * 1) We have added an unusual amount of run time from fork_exit. |
| 1636 | * 2) We have added an unusual amount of sleep time from sched_sleep(). |
| 1637 | */ |
| 1638 | if (sum > SCHED_SLP_RUN_MAX * 2) { |
| 1639 | if (ts->ts_runtime > ts->ts_slptime) { |
| 1640 | ts->ts_runtime = SCHED_SLP_RUN_MAX; |
| 1641 | ts->ts_slptime = 1; |
| 1642 | } else { |
| 1643 | ts->ts_slptime = SCHED_SLP_RUN_MAX; |
| 1644 | ts->ts_runtime = 1; |
| 1645 | } |
| 1646 | return; |
| 1647 | } |
| 1648 | /* |
| 1649 | * If we have exceeded by more than 1/5th then the algorithm below |
| 1650 | * will not bring us back into range. Dividing by two here forces |
| 1651 | * us into the range of [4/5 * SCHED_INTERACT_MAX, SCHED_INTERACT_MAX] |
| 1652 | */ |
| 1653 | if (sum > (SCHED_SLP_RUN_MAX / 5) * 6) { |
| 1654 | ts->ts_runtime /= 2; |
| 1655 | ts->ts_slptime /= 2; |
| 1656 | return; |
| 1657 | } |
| 1658 | ts->ts_runtime = (ts->ts_runtime / 5) * 4; |
| 1659 | ts->ts_slptime = (ts->ts_slptime / 5) * 4; |
| 1660 | } |
| 1661 | |
| 1662 | /* |
| 1663 | * Scale back the interactivity history when a child thread is created. The |
no test coverage detected