Scheduling Introduction
Notes
- This is chapter 5 of the book.
- Scheduling is selecting the next task to be given access to the CPU
- We will at first assume, for simplicity, that there is only one cpu/core
- But extend this later.
- We need to be aware of two extremes for processes
- I/O intensive: tend to run in short bursts and need more data
- Computationally intensive: tend to run in long bursts and need less data.
- Most processes are I/O intensive (figure 5.2 in the book)
- There are others in between, but we tend to think about these two
- The I/O intensive processes tend to self-regulate
- The computationally intensive processes are a problem for schedulers
- We tend to refer to the ready queue
- This may indeed be a fifo
- But it could be a ordered set of fifos
- Or a tree
- Or something else
- Including just a linked list.
- The book lists four reasons scheduling must occur
- The current process switches from running to waiting (sleep, I/O request, ...)
- The current process is interrupted but is still able to run
- Another process switches from waiting to ready
- The current process terminates.
- When scheduling takes place for reasons 1 or 4, it is nonpreemptive
- When scheduling takes place for reasons 2 or 3 it is preemptive
- As we have seen, preemptive scheduling can cause concurrency issues.
- The dispatcher is normally the part of the CPU that does the context switch
- Switches to kernel mode
- Saves the state of the current process
- Will possibly be required to do some memory management
- Restores/establishes the state of the new process
- Switches to user mode
- The dispatcher requires time, so switching between processes has an associated expense.
- Just for a clue
-
grep /ctx /proc/stat for context switches since boot
-
grep ctxt /proc/self/status for a process, substitute self with pid for another process.
- Generally, we have several goals a scheduler should or must achieve
- CPU Utilization: keep the cpu as busy as possible
- Throughput: Complete as many processes as possible
- Turnaround time: complete processes as quickly as possible
- Waiting time: Minimize the amount of time a process spends waiting
- Response time: especially in interactive systems
- Note that some of these are contradictory and some are (semi) equivalent.