Lecture 8 - CPU Scheduling Flashcards
What is scheduling?
Scheduling refers to a set of policies and mechanisms to control the sequence of jobs (work) to be performed by a computer system
What is allocation? How is it different than scheduling?
Suppose we have jobs and some resources, allocation determines which jobs get to use which resources
Scheduling on the other hand determines the sequence of execution
What’s are the 3 goals of CPU scheduling?
Consider a single CPU case:
• Maximize CPU utilization
• Minimize job response times
• Maximize throughput
What are the 3 pieces of information that we need to perform scheduling?
- Resources
• Lets assume only one CPU
• We have I/O resources
• Memory used in a shared manner
2. Jobs • Number of processes • Process creation rate, termination rate • How long a process runs • How long a process uses CPU versus I/O
- Other issues
• Scheduling policies, priorities
Define CPU burst and I/O burst. Which one’s faster?
Why do these clarify why multiprocessing is beneficial?
They define the amount of time each of these resources are used. CPU burst is much faster.
While a process is in CPU burst, the I/O is idle, and vice versa. We can utilize the idle resources more efficiently with multiprocessing.
What is a CPU-bound and I/O bound process? Give one example of each.
Not all processes have an even mix of CPU and I/O usage…
- CPU-bound process.
A number crunching program may do a lot of computation and minimal I/O: - I/O-bound process.
A data processing job may do little computation and a lot of I/O:
Do long CPU bursts happen more often than short bursts?
No, the opposite is true. 2 millisecond is the most likely burst.
What is the role of the Short-term scheduler?
Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them
* Queue may be ordered in various ways
Name 4 occasions when CPU scheduling decisions take place.
Which one of these are non-preemptive, and which ones are preemptive?
CPU scheduling decisions may take place when a process:
- Switches from running to waiting state
- Switches from running to ready state
- Switches from waiting to ready
- Terminates
Scheduling under 1 and 4 is non-preemptive.
All other scheduling is preemptive.
Name three occasions where preemptive scheduling occurs in OSs.
Consider access to shared data
Consider preemption while in kernel mode
Consider interrupts occurring during crucial OS activities
What are the 9 evaluation criteria for schedulers? Explain each briefly.
- CPU utilization
* defined as the capacity used divided by the total capacity
* varies from 100% (completely used) to 0% (not used at all!) - Efficiency
* Useful work divided by Total work. - Throughput
* defined as the number of jobs completed per unit time - Turnaround time
* time to complete a job. It is the wall clock time elapsed between the completion and arrival events of the job - Waiting time
* total time spent waiting in the ready queue - Service time
* total time spent servicing the job. Total time the job spent in the active queue - Response time
* wall clock time elapsed between the time the first response (first run) is produced and the arrival of the job - Fairness
- Deadlines
How do we design a scheduler?
- select one or more primary performance criteria
- rank them in order of importance
- performance criteria may not be independent of each other (e.g., increased processor utilization leads to longer response times) so the design of a scheduler usually involves a careful balance of the requirements
What are the two scheduling policies? Explain each briefly and give two examples.
What kind of jobs are each good for?
- Non-Preemptive
* Scheduler does not interrupt running process
* Current process runs until it blocks, waiting for an event or a resource, or it terminates
- > First-Come-First-Served (FCFS)
- > Shortest Job first (SJF)
Good for “background” batch jobs.
- Preemptive
* Scheduler forces current process to release the CPU
* Eviction of process occurs at clock interrupt, I/O interrupts
- > Round-Robin (RR)
- > Priority
Good for “foreground” interactive jobs.
Define the First-Come-First-Served (FCFS) scheduling policy.
What kind of jobs is it best for? Worst?
How is the relative importance of jobs measured?
Name 3 problems with FCFS.
FCFS = First-In-First-Out (FIFO)
- simplest scheduling policy
- arriving jobs are inserted into the tail (rear) of the ready queue
- job to be executed next is removed from the head (front) of the queue
FCFS performs better for long jobs. Worst for interactive jobs.
Relative importance of jobs measured only by arrival time (poor choice)
Problems
- A long CPU-bound job may hog the CPU
- Short (or I/O-bound) jobs have to wait for long periods
- Can lead to a lengthy queue of ready jobs, known as the “convoy effect”
Define the Shortest Job First (SJF) scheduling policy.
Name 2 problems with SJF.
- selects the job with the shortest (expected) processing time first
- Shorter jobs are always executed before long jobs
Problem with SJF
- need to know or estimate the processing time of each job
- long running jobs may starve for the CPU when there is a steady supply of short jobs.
What’s a preemptive version of Shortest Job First?
Preemptive SJF is also called Shortest Remaining Time First (SRTF)
Name one method to determine the next CPU burst in SJF.
- Can be done by using the length of previous CPU bursts, using exponential averaging
Tn+1 = tn*alpha + (1-alpha)tn-1 + (1-alpha)^j *tn-j + …(1-alpha)^n+1 * T0
where Tn is guess, tn is previous, alpha is 0
Calculate average waiting time of following Shortest Remaining Time First scheduling: Process, Arrival, Burst P1 0 8 P2 1 4 P3 2 9 P4 3 5
[(10-1) + (1-1) + (17-2) + (5-3)]/4 = 6.5 msec
Explain how the Round-Robin Scheduling policy works.
What are three criteria its efficiency depends on?
What kind of job’s is it most suitable for? least?
- Periodically preempt a running job
- CPU suspends the current job when time-slice expires
- Job is rescheduled after all other ready jobs are executed at least once
Efficiency of RR depends on
- Time-slice length
- If too short, CPU will be spending too much time on context switching
- If too long, interactive jobs will suffer (becomes a FCFS policy)
Good for interactive jobs.
Not suitable for long batch jobs
Explain how the Priority-based Scheduling policy works.
How do we prevent starvation?
- Each process is assigned a priority
- Process chosen for execution based on priority (highest priority first)
- Priority + preemption allows preemption when a higher priority process comes in
To prevent starvation:
Priority + aging boosts the priority as a process stays in the ready queue
Rank FCFS, RR, SJF in order of increasing processing overhead.
FCFS, RR, SJF (potentially, if plenty of mini jobs)
Explain the difference between Long-Term, Medium-term and Short-term scheduling.
Long-term (job) scheduling is done when a new process is created. It controls the degree of multi-programming
Medium-term scheduling involves suspend/resume processes by swapping them out of or in to memory.
Short-term (process or CPU) scheduling occurs most frequently and decides which process to execute next
Define 3 characteristics of Interactive scheduling
What does the priority of processes depend on? How is it determined?
- Time-sliced
- Priority-Based,
- Preemptive
Priority depends on expected time to block
- interactive threads should have high priority
- compute threads should have low priority
Determine priority using past history
- processor usage causes decrease
- sleeping causes increase
Explain Lottery scheduling using 25 lottery tickets
What’s the problem with lottery scheduling?
25 lottery tickets are distributed equally to you and your four friends
* you give 5 tickets to your one thread
* they give one ticket each to their threads
A lottery is held for every scheduling decision
* your thread is 5 times more likely to win than the others
Problem: It’s not deterministic.