Chapter-02-scheduling
Chapter-02-scheduling
1
Process Behavior
• Batch
– Nonpreemptive algorithms or preemptive algorithms with long
time periods for each process
– Reduces process switches and improves performance
• Interactive
– Preemptive algorithms to keep one process from hogging the CPU
and denying service to the others
• Real time
– Preemption is sometimes not needed because the processes know
that they may not run for long periods of time and usually do their
work and block quickly
4
Scheduling Algorithm Goals
6
Scheduling in Batch Systems (2)
• Shortest Job First
– Nonpreemptive
– Run times are known in advance
– Optimal average turnaround time
(when all the jobs are available simultaneously)
– Average turnaround time
In (a), (8 12 16 20) / 4 14 minutes
In (b), (4 8 12 20) / 4 11 minutes
7
Scheduling in Batch Systems (3)
8
Scheduling in Batch Systems (4)
12
Scheduling in Interactive Systems (2)
15
Scheduling in Interactive Systems (5)
• Guaranteed Scheduling
– With n processes running, each one should get 1/n of the CPU
cycles.
• Keeps track of how much CPU each process has had since
its creation
• Computes
actual CPU time consumed
ratio
CPU time entitled
– E.g. 0.5 : a process has only had half of what it should have had
• Runs the process with the lowest ratio until its ratio has
moved above its closest competitor
16
Scheduling in Interactive Systems (6)
• Lottery Scheduling
– Gives processes lottery tickets for various system resources,
such as CPU time.
– Whenever a scheduling decision has to be made, a lottery
ticket is chosen at random, and the process holding that ticket
gets the resource.
– A process holding a fraction f of the tickets will get about a
fraction f of the resource.
– Highly responsive
– Cooperating processes can exchange tickets if they wish.
– Video server in which several processes are feeding video
streams to their clients at different frame rates.
17
Scheduling in Interactive Systems (7)
• Fair-Share Scheduling
– Previous scheduling
• Owner of the process not considered
• E.g. in round-robin
– User 1 with 9 processes
– User 2 with 1 process gets only 10% of the CPU
– Takes into account who owns a process before scheduling it
– E.g.
• User 1 with A,B,C,D : 50%
• User 2 with E: 50%
• AEBECEDEAEBE…
18
Scheduling in Real-Time Systems
• A real-time system must react appropriately to external
events by the deadline.
• E.g.
– Compact disk player, patient monitoring in a hospital intensive-
care unit, autopilot in an aircraft, robot control in a factory
• Having the right answer too late is often just as bad as not
having it at all.
• Hard real time
– Absolute deadlines must be met
• Soft real time
– Missing an occasional deadline is undesirable, but nevertheless
tolerable.
• Real-time behavior
– Achieved by dividing the program into a number of processes,
each of whose behavior is predictable and known in advance.
19
Scheduling in Real-Time Systems
• Events
– Periodic: occuring at regular intervals
– Aperiodic: occuring unpredictably
• Schedulable real-time system
– Given
• m periodic events
• event i occurs with period Pi and requires Ci seconds to handle
– Then the load can only be handled if the sum of the fraction of the
CPU being used by each process <= 1.
m
Ci
i 1 Pi
1
21
Thread Scheduling (1)