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.