Para citar Robert Love:
The scheduler does not magically know whether a process is interactive. It requires some heuristic that is capable of accurately reflecting whether a task is I/O-bound or processor-bound. The most indicative metric is how long the task sleeps. If a task spends most of its time asleep it is I/O-bound. If a task spends more time runnable than sleeping, it is not interactive. This extends to the extreme; a task that spends nearly all the time sleeping is completely I/O-bound, whereas a task that spends nearly all its time runnable is completely processor-bound.
To implement this heuristic, Linux keeps a running tab on how much time a process is spent sleeping versus how much time the process spends in a runnable state. This value is stored in the
sleep_avg member
of thetask_struct
. It ranges from zero toMAX_SLEEP_AVG
, which defaults to 10 milliseconds. When a task becomes runnable after sleeping,sleep_avg
is incremented by how long it slept, until the value reachesMAX_SLEEP_AVG
. For every timer tick the task runs,sleep_avg
is decremented until it reaches zero.
Então, acredito que o kernel decida a política de programação com base nas heurísticas acima. Tanto quanto eu sei, para processos em tempo real, a política de agendamento pode ser SCHED_FIFO
ou SCHED_RR
. Ambas as políticas são semelhantes, exceto que SCHED_RR
tem um intervalo de tempo, enquanto SCHED_FIFO
não possui intervalo de tempo.
No entanto, podemos até alterar o agendamento do processo em tempo real também. Você pode consultar esta pergunta sobre como alterar o processo em tempo real agendamento.
Referências