Chapter 3 Process Scheduling
Chapter 3 Process Scheduling
Chapter 3 Process Scheduling
1
20/09/2012
P1 P2 P3
- waiting time for P1 = 6;P2 = 0; P3 = 3
- average waiting time: (6 + 0 + 3)/3 = 3
0 24 27 30
- much better than previous case
- waiting time for P1 = 0; P2 = 24; P3 = 27 - Convoy effect: short process arriving after long process may
- average waiting time: (0 + 24 + 27)/3 = 17 have to wait a long time
2
20/09/2012
3
20/09/2012
Time Quantum and Context Switch Time Turnaround Time Varies With The Time Quantum
5. Multilevel Queue
- ready queue is partitioned into separate queues
- a new job is placed in one of the queues
- each queue has its own scheduling algorithm, for example
• foreground (interactive) – RR
• background (batch) – FCFS
- scheduling must be done between the queues
• fixed priority scheduling; (i.e., serve all from foreground then
from background) - possibility of starvation
• time slice – each queue gets a certain amount of CPU time which
it can schedule amongst its processes
i.e., 80% to foreground in RR, 20% to background in FCFS
4
20/09/2012
6. Guaranteed Scheduling
- what if we want to guarantee that a process get x% of the
CPU?
How do we write the scheduler?
- scheduling algorithm would compute the ratio of fraction of
• CPU time a process has used since the process began
• CPU time it is supposed to have
- process with the lowest ratio would run next
- difficult to implement
7. Lottery
- issues lottery tickets to processes for various resources D. ALGORITHM EVALUATION
- the scheduler then randomly selects a lottery number - many scheduling algorithms
- the winning process gets to run - need criteria to select one for a system
- the more lottery tickets you have, the better your chance of - also need to evaluate algorithms
“winning” - four evaluation methods
- processes can give (or lend) their tickets to their children or • deterministic modeling
to other processes • queuing models
- more important processes can be given more tickets • simulations
• implementation
5
20/09/2012
- advantages: 3. Simulation
• very fast way of analyzing systems - program a model of a computer system
- disadvantages: - software data structures represent system components
• mathematics can become complex, so processes and systems are
- a clock is maintained
usually modeled in unrealistic but tractable ways
• many assumptions may have to be made
- as the clock is advanced, the state of the various components
• accuracy is therefore questionable
in the system are modified
- if a process in the real system requires 5 seconds of CPU
time, it will actually execute in a moment in the simulation
(the clock will simply be advanced)
- the simulator keeps track of variables in order to calculate
statistics for utilization, throughput, waiting time, etc.
6
20/09/2012
F. THREAD SCHEDULING
- some issues concerning SMP include
- distinction between user-level and kernel-level threads
- process has affinity for processor on which it is currently • thread library schedules user-level threads to run on LWP
running; avoid migration of processes • use process-contention scope (PCS)
- a process has a value that indicates preference • scheduling competition is within the process
• soft affinity – possible migration - for one-to-one
• hard affinity – no migration
• kernel thread scheduled onto available CPU using system-
contention scope (SCS)
• Load balancing
• competition among all threads in system
- keep workload evenly distributed across all processors
• push migration
• pull migration
7
20/09/2012
- since the JVM doesn’t ensure time-slicing, the yield() method Relationship between Java and Win32 Priorities
may be used:
while (true) {
// perform CPU-intensive task
...
Thread.yield();
}
8
20/09/2012
9
20/09/2012
10