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

Function sched_interact_score

freebsd/kern/sched_ule.c:1531–1565  ·  view source on GitHub ↗

* This is the core of the interactivity algorithm. Determines a score based * on past behavior. It is the ratio of sleep time to run time scaled to * a [0, 100] integer. This is the voluntary sleep time of a process, which * differs from the cpu usage because it does not account for time spent * waiting on a run-queue. Would be prettier if we had floating point. * * When a thread's sleep

Source from the content-addressed store, hash-verified

1529 * run time / sleep time
1530 */
1531static int
1532sched_interact_score(struct thread *td)
1533{
1534 struct td_sched *ts;
1535 int div;
1536
1537 ts = td_get_sched(td);
1538 /*
1539 * The score is only needed if this is likely to be an interactive
1540 * task. Don't go through the expense of computing it if there's
1541 * no chance.
1542 */
1543 if (sched_interact <= SCHED_INTERACT_HALF &&
1544 ts->ts_runtime >= ts->ts_slptime)
1545 return (SCHED_INTERACT_HALF);
1546
1547 if (ts->ts_runtime > ts->ts_slptime) {
1548 div = max(1, ts->ts_runtime / SCHED_INTERACT_HALF);
1549 return (SCHED_INTERACT_HALF +
1550 (SCHED_INTERACT_HALF - (ts->ts_slptime / div)));
1551 }
1552 if (ts->ts_slptime > ts->ts_runtime) {
1553 div = max(1, ts->ts_slptime / SCHED_INTERACT_HALF);
1554 return (ts->ts_runtime / div);
1555 }
1556 /* runtime == slptime */
1557 if (ts->ts_runtime)
1558 return (SCHED_INTERACT_HALF);
1559
1560 /*
1561 * This can happen if slptime and runtime are 0.
1562 */
1563 return (0);
1564
1565}
1566
1567/*
1568 * Scale the scheduling priority according to the "interactivity" of this

Callers 1

sched_priorityFunction · 0.85

Calls 2

td_get_schedFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected