Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


Dequeue task

Set se.exec_start

pick_next_task_rt

sched_find_first_bit

Figure 2-24: Code flow diagram for
pick_next_task_rt.

sched_find_first_bitis a standard function that finds the first set bit inactive.bitmap— this means
that higher real-time priorities (which result in lower in-kernel priorities) are handled before lower real-
time priorities. The first task on the selected list is taken out, andse.exec_startis set to the current
real-time clock value of the run queue — that’s all that is required.

The implementation of the periodic tick is likewise simple.SCHED_FIFOtasks are easiest to handle: They
can run as long as they like and must pass control to another task explicitly by using theyieldsystem
call:

kernel/sched.c
static void task_tick_rt(struct rq *rq, struct task_struct *p)
{
update_curr_rt(rq);

/*
* RR tasks need a special form of timeslice management.
* FIFO tasks have no timeslices.
*/
if (p->policy != SCHED_RR)
return;
...

If the current process is a round robin process, its time slice is decremented. When the time quantum
is not yet exceeded, nothing more needs to be done — the process can keep running. Once the counter
reverts to 0, its value is renewed toDEF_TIMESLICE, which is set to100 * HZ / 1000, that is, 100 ms. If the
task is not the only task in its list, it is requeued to the end. Rescheduling is requested as usual by setting
theTIF_NEED_RESCHEDflag withset_tsk_need_resched:

kernel/sched-rt.c
if (--p->time_slice)
return;

p->time_slice = DEF_TIMESLICE;

/*
* Requeue to the end of queue if we are not the only element
* on the queue:
*/
if (p->run_list.prev != p->run_list.next) {
Free download pdf