Outline for 1/23/98
-
Last time: Deadlock formalisms, detection.
- Administrative:
Program 1 due and Program 2 on web later today.
CRA mentorship program - deadline soon www.cs.wisc.edu/~condon/mentor.html
- Objective for today:
Deadlock Avoidance - Banker’s Algorithm
We talked before about the mechanisms for supporting processes and threads - turning to the scheduling policies for choosing which to run when.
Avoidance - Banker’s Algorithm
- Each process must declare its maximum claim on each of the resources and may never request beyond that level.
- When a process places a request, the Banker decides whether to grant that request according to the following criteria:
- “If I grant this request, then there is a run on the bank (everyone requests the remainder of their maximum claim), will we have deadlock?”
Representing the State
- n processes, m resources
- avail[m] - avail[i] is the number of available units of Ri
- max[n,m] - max[i,j] is claim of Pi for Rj
- alloc[n,m] - alloc[i,j] is current allocation of Rj to Pi
- need[n,m] = max[n,m] - alloc[n,m] - the rest that can be requested.
Basic Outline of Algorithm
if (request[i,j] > avail[j]) defer;
//Sufficient resources for request
//pretend to grant request
avail[j] = avail [j] - request [i,j];
alloc[i,j] = alloc[i,j] + request [i,j];
need[i,j] = need[i,j] - request [i,j];
if (safe state) grant; else defer;
Processor Scheduling
-
We’ve talked about how: mechanisms to support process abstraction (context switch, timer interrupts, queues of process descriptors)
- We’ve talked about why: use of concurrent processes/threads in problem-solving.
- Next issue: policies for choosing which process/thread, among all those ready to run, should be given the chance to run next.
Goals of Scheduling Policy
Improve performance in terms of one of these measures:
- Throughput (to maximize productivity) #jobs per second.
- Response time (to minimize the average time between arrival to completion of requests)
- Utilization (to maximize use of some device) time-in-use / elapsed time
Other goals:
- To guarantee fairness
No starvation, low variance on response time
- To meet deadlines.
real time systems (e.g. process control, continuous media)
Multiprogramming as a Utilization Issue
Overlap of computation and I/O
Determine mix and multiprogramming level (kind and number of processes competing) in order to “cover” the idle times caused by I/O
Flavors of Scheduling
- Long-term scheduling - which jobs get resources (e.g., loaded into memory) and the chance to compete for cycles (be on the ready queue).
- Short-term scheduling - which of those processes gets the next quantum of CPU time.
- Non-preemptive - a running process has to explicitly yield or block to give up control.
- Preemptive - interrupts cause scheduling opportunities to reevaluate who should be running now (more “valuable” ready task?)
Scheduling Algorithms
- SJF - Shortest Job First (provably optimal in minimizing average response time, assuming we know service times in advance)
- FIFO, FCFS
- Round Robin
- Multilevel Feedback Queuing
- Priority Scheduling
SJF
-
In preemptive case, shortest remaining time first.
- In practice, we have to predict the CPU service times (computation time until next blocking).
- Favors interactive jobs, needing response, & repeatedly doing user interaction
- Favors jobs experiencing I/O bursts - soon to block, get devices busy, get out of CPU’s way
-
Focus is on an average performance measure, some long jobs may starve under heavy load/ constant arrival of new short jobs.
Round Robin
-
Running each job, in turn, for a quantum of time (enforced by timer interrupt).
- Context switch overhead for each quantum.
Typical 10-100 usec.
- Tradeoff in choosing quantum size between throughput and fairness (low variance)
- Very short - system spends all its time switching
- Very long - degrades to FCFS, less wasted time
Manipulating Priorities
- External priority (user rank, paid bribes)
- Internal priorities - scheduler dynamically calculates and uses for queuing discipline.
- Priority boost for holders of resource
- Priority reassigned as the remainder of previous quantum remaining (if I/O bound, large unused portion of quantum; if CPU bound, nothing left)
- Adaptive to observed behavior.
Multilevel Queues
- Adaptive policy - past behavior determines which queue
- Policy specifies how processes move between queues
- Lower queues in later turns, favors short jobs without predicted time.