Linux Scheduling 2002
Linux Scheduling 2002
Patrick Stahlberg
<Patrick.Stahlberg@hadiko.de>
What is scheduling?
What is scheduling?
Interactive processes
Batch processes
Real-time processes
I/O-bound
CPU-bound
For a Multiuser-Multitasking-OS:
Direct invocation
During System Calls
Mostly indirectly via sleep_on()
e.g. when waiting for a resource
Lazy invocation
After System Calls or interrupts
if need_resched is set
e.g. after sched_set_scheduler()
The timer interupt also sets need_resched, making sure that schedule()
is called frequently
Data structures used by the scheduler
need_resched
A flag set by interrupt handling routines
When set, ret_from_intr() calls schedule()
policy
Scheduling policy, see following slide
rt_priority
Static priority field for real-time processses
priority
Base time quantum (SCHED_RR)
Base priority (SCHED_OTHER)
counter
Scheduling classes
Real-time processes
Static priority
p1
p2
p3
t1 t2
The SCHED_RR scheduling class
Real-time processes
Static priority
p1
p2
p3
t1 t2 t3 t4 t5
The SCHED_OTHER scheduling class
Dynamic priority
Time slicing
if (p->mm == prev->mm)
return p->counter + 1 + 20 - p->nice;
else
return p->counter + 20 - p->nice;
Literature:
kernel/sched.c
http://en.tldp.org/LDP/tlk/kernel/processes.html#tth_sEc4.3
sched_setscheduler(2)
http://www.kernelnewbies.org/documents/schedule/
http://www.ora.com/catalog/linuxkernel/chapter/ch10.html
End. Questions?