MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sched_interact_update

Function sched_interact_update

freebsd/kern/sched_ule.c:1623–1660  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1621 * function is ugly due to integer math.
1622 */
1623static void
1624sched_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

Callers 4

sched_wakeupFunction · 0.85
sched_forkFunction · 0.85
sched_exit_threadFunction · 0.85
sched_clockFunction · 0.85

Calls 1

td_get_schedFunction · 0.85

Tested by

no test coverage detected