Académique Documents
Professionnel Documents
Culture Documents
Fedora 12 Specifications
Fedora 12 is a 0s based on the Linux kernel, developed by the community-supported Fedora Project and sponsored by Red Hat. Fedora 12 uses Fedora Core 6 development environment Fedora core 6 uses the 2.6.18 based Linux kernel
4/21/12
4/21/12
4/21/12
Selecting processes one by one from the ready queue and allocate CPU for them. decisions may occur on
Process Switches from running to waiting state Switches from running to ready state Switches from waiting to ready Terminates
4/21/12
Scheduling Policy
Process Preemption
When the dynamic priority of the currently running process is lower than the process waiting in the readyqueue A process may also be preempted when its time quantum expires
Quantum duration too short - system overhead caused by task switching becomes excessively high Quantum duration too long - processes no longer appear to be executed concurrently, degrades the response time of interactive applications, and degrades the responsiveness of the system
The rule of thumb adopted by Linux is: choose a duration as 4/21/12 long as possible, while keeping good system response time
utilization keep the CPU as busy as possible Throughput Number of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it 4/21/12
Scheduling Algorithems
First
Come First Serve Scheduling Job First Scheduling Scheduling Scheduling Queue Scheduling
Shortest Priority
Feedback-Queue Scheduling
4/21/12
4/21/12
The
average of waiting time in this policy is usually quite long time for P1=0; P2=24; P3=27
Waiting
Average
4/21/12
Suppose
4/21/12
Consider if we have a CPU-bound process and many I/O-bound processes There is a convoy effect as all the other processes waiting for one of the big process to get off the CPU FCFS scheduling algorithm is nonpreemptive
4/21/12
algorithm associates with each process the length of the processes next CPU burst
If
there is a tie, FCFS is used In other words, this algorithm can be also regard as shortest-next-cpu-burst algorithm
4/21/12
is optimal gives minimum average waiting time for a given set of processes
4/21/12
Example
Processes Burst time
P1 P2 P3 P4 6 8 7 3
FCFS average waiting time: (0+6+14+21)/4=10.25 SJF average waiting time: (3+16+9+0)/4=7
4/21/12
4/21/12
4/21/12
Priority Scheduling
A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority)
Preemptive Non-preemptive
SJF is a special priority scheduling where priority is the predicted next CPU burst time, so that it can decide the priority
4/21/12
Priority Scheduling
Processes Burst time Priority Arrival time P1 P2 P3 P4 P5 10 1 2 1 5 3 1 4 5 2
4/21/12
Priority Scheduling
Processes Burst time Priority Arrival time P1 P2 P3 P4 P5 10 1 2 1 5 3 1 4 5 2 0.0 1.0 2.0 3.0 4.0
Gantt chart for both preemptive and nonpreemptive, also waiting time
4/21/12
Priority Scheduling
Problem : Starvation low priority processes may never execute Solution : Aging as time progresses increase the priority of the process
4/21/12
Round-Robin Scheduling
The It A
Round-Robin is designed especially for time sharing systems. is similar FCFS but add preemption concept small unit of time, called time quantum, is defined
4/21/12
Round-Robin Scheduling
Each
process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
4/21/12
Round-Robin Scheduling
4/21/12
Round-Robin Scheduling
If
there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
4/21/12
Round-Robin Scheduling
Performance q large => FIFO q small => q must be large with respect to context switch, otherwise overhead is too high
Typically,
4/21/12
Round-Robin Scheduling
4/21/12
Linux Scheduler History Linux schedulers history is short but the popularity
and its development achieved makes it impossible to say that this was introduced in the later part of the 19th century.
Below are some the schedulers' through its brief Linux Version Scheduler history
Linux pre 2.5 Linux 2.5-2.6.23 Linux Post 2.6.23 Multilevel Feedback Queue O(1) Scheduler Completely Fair Scheduler
LINUX Schedulers
Linux
operating system is a time sharing system thus the concept of short and long term schedulers is taken to higher level, an additional intermediary level of scheduling or commonly known as medium term scheduling.
introducing
1.2 scheduler used a circular queue for runnable task management that operated with a round-robin scheduling policy.
.Features of 1.2 scheduler
Efficient for adding and removing processes (with a lock to protect the structure ). Simple and fast .
2.2 scheduler
Linux
2.2 schedulers introduced the idea of scheduling classes, permitting scheduling policies for real-time tasks, non-preemptive tasks, and non-real-time tasks. 2.4 scheduler
Linux
Preemption
not possible
Lower priority task can execute while high priority task waits
O(n)
complexity
4/21/12
Fair Scheduler
Merged into the 2.6.23 kernel Runs task with the gravest need Guarantees fairness (CPU usage)
No
runqueues!
Uses a time-ordered red-black binary tree Leftmost node is the next process to run
4/21/12
2 N L
4/21/12
N L
N L
N L
Red/Black Continues.
1.
Every node has two children, each colored either red or black. Every tree leaf node is colored black. Every red node has both of its children colored black. Every path from root to a tree leaf contains same number of black nodes
2.
3.
4.
4/21/12
timeslices!... sort of
Uses wait_runtime (individual) and fair_clock (queue-wide) Processes build up CPU debt Different priorities spend time differently Half priority task sees time pass twice as fast
O(log
n) complexity
Only marginally slower than O(1) at very 4/21/12 large numbers of inputs
CFS has three primary structures task_struct, sched_entity, and cfs_rq. task_struct is the top-level entity, containing things such as task priorities, scheduling class, and the sched_entity struct. (sched.h, L1117) sched_entity includes a node for the RB tree and the vruntime statistic, among others. (sched.h, L1041)
cfs_rq contains the root node, task 4/21/12 group (more on this later), etc.
While CFS does not directly use priorities or priority queues, it does use them to modulate vruntime buildup. In this version, priority is inverse to its effect a higher priority task will accumulate vruntime more slowly, since it needs more CPU time.
Likewise, a low-priority task will have its vruntime increase more quickly, causing it to be preempted earlier. 4/21/12
...that's it?
The CFS algorithm is, as stated, a lot simpler than the previous one, and does not require many of the old variables. Preemption time is variable, depending on priorities and actual running time. So we don't need assign tasks a given timeslice.
4/21/12
Other additions
CFS introduced group scheduling in release 2.6.24, adding another level of fairness. Tasks can be grouped together, such as by the user which owns them. CFS can then be applied to the group level as well as the individual task level.
So, for three groups, it would give each about a third of the CPU time, and then divide that time up among 4/21/12
Modular scheduling
Alongside the initial CFS release came the notion of modular scheduling, and scheduling classes. This allows various scheduling policies to be implemented, independent of the generic scheduler.
sched.c, which we have seen, contains that generic code. When schedule() is called, it will call pick_next_task(), which will look at 4/21/12 the task's class and call the class
Scheduling classes!
Two scheduling classes are currently implemented: sched_fair, and sched_rt. sched_fair is CFS, which We are talking about this whole time. sched_rt handles real-time processes, and does not use CFS it's basically the same as the previous scheduler.