Thursday, September 6, 2012

scheduler

struct task_struct
{

prio -> It is the priority considered by the scheduler.
normal prio ->
static prio -> assigned during fork , changed only by nice , sched_setscheduler
rt priority -> lowest rt priority 0 , highest rt priority 99

sched_class -> scheduler class(CFS , RT..)
se -> scheduler schedules entities(process is an entity)
run_list -> Needed only for RR scheduler

policy -> cfs(SCHED_NORMAL(normal process) , SCHED_BATCH(wont preempt other process) , SCHED_IDLE)
rt(SCHED_RR , SCHED_FIFO)
cpus_allowed -> Cpus on which the process can execute
time_slice -> Needed only for RR scheduler
}




Priority
              RT Normal
0----------------------------------100---------139
Nice
                                   -20   19




p->prio = effective_prio(task);

Returns the normal priority.
If we are RT or boosted up gives the boosted priority.












p->normal_prio = p->static_prio | MAX_RT_PRIO-1-p->rt_priority (RT tasks)
p->prio = p->normal_prio | p->prio(if boosted previously or if RT keep priority unchanged)

when RT Mutexes are used , normal process boost priority to real time tasks.

generic scheduler + scheduling methods provided by sched_class

__schedule
{
disable premption
get processor id -> run queue
get curr process
check for hr timer , signals
update statistics (prempt count..)
deactivate prev task
preschedule of the scheduler class of the prev process
if no process in rq then do idle balance on rq
put prev task
pick next task
update clocks...
update context switch count
change the current process of the run queue to current
do the arch specific context switch
postschedule of the scheduler class of the curr process
update statistics
TIF_NEED_RESCHED -> do scheduling again
enable premption
}

where the places in which schedule() is called?

System Calls Related to Scheduling

System Call Description

nice( ) Change the priority of a conventional process.
getpriority( ) Get the maximum priority of a group of conventional processes.
setpriority( ) Set the priority of a group of conventional processes.
sched_getscheduler( ) Get the scheduling policy of a process.
sched_setscheduler( ) Set the scheduling policy and priority of a process.
sched_getparam( ) Get the scheduling priority of a process.
sched_setparam( ) Set the priority of a process.
sched_yield( ) Relinquish the processor voluntarily without blocking.
sched_get_ priority_min( ) Get the minimum priority value for a policy.
sched_get_ priority_max( ) Get the maximum priority value for a policy.
sched_rr_get_interval( ) Get the time quantum value for the Round Robin policy.

Runqueue :

Runqueue is list of all process with state = TASK_RUNNING
CFS Tasks are maintained in both list and redblack tree

Each active process can be in only one runqueue.
However threads from the same process can be on different runqueue.

struct rq
{
unsigned long nr_running;
#define CPU_LOAD_IDX_MAX 5
unsigned long cpu_load[CPU_LOAD_IDX_MAX]
struct load_weight load;

struct cfs_rq cfs;
struct rt_rq rt;

struct task_struct *idle , *curr;
u64 clock;
}

Scheduler Class :

enqueue_task
dequeue_task -> Enqueue/Dequeue the task into the runqueue(cfs rq / rt rq).

userspace does not interact with scheduler class.
It just sets the SCHED_*** flag.
Kernel sets the mapping between these.

No comments:

Post a Comment