Part 2 of 6 · 2 min read
Bursts
Think of it this way. A cook alternates between chopping, which needs the cook's hands, and waiting for the oven, which does not. While one dish is in the oven, the cook can chop for another. The analogy stops where it comes to the kitchen's size: a computer may have only one pair of hands, the processor, for all the dishes.
In plain words: Every program behaves like that cook. It computes for a while, then asks for something slow, such as a disk read, a network reply or a keypress, and waits. The stretch of computing is a CPU burst. The stretch of waiting is an I/O burst, the wait for input or output (Level 0). A process is a loop: CPU burst, I/O wait, CPU burst, I/O wait, and so on, until it ends.
Processes differ in the lengths of their bursts. A video encoder computes for seconds without asking for anything: it is CPU-bound. A text editor computes for microseconds after each key and then waits for the next one: it is I/O-bound. Real measurements show that most bursts are short and a few are long.
Linux counts how each process gave up the processor. A test ran two programs for 2 seconds each, on one processor shared with a competing spinning process. The first program spun without ever waiting. The second slept for 1 millisecond, again and again. The counters in /proc/self/status showed:
spinner voluntary 0, forced 248
sleeper voluntary 1767, forced 0
A voluntary switch happens when the process itself stops, because it must wait. A forced (or involuntary) switch happens when the kernel takes the processor away from a process that still wants to run. The spinner was forced off 248 times in 2 seconds, about once every 8 milliseconds, and it never waited. The sleeper gave up the processor 1,767 times by itself and was never forced off, because every burst ended before the kernel needed to intervene.
This pattern is the key to scheduling. While a process waits, the processor is free for another one. A scheduler that keeps the processor busy with ready processes while others wait for I/O uses the machine well.
CPU burst
A CPU burst is the time a process executes on a processor between two waits, that is, from the moment it starts running until it blocks for input or output or ends.
Example: a program that computes for 3 milliseconds and then reads from a disk has a CPU burst of 3 milliseconds, followed by an I/O wait.
Check yourself: 1. What is the difference between a CPU-bound and an I/O-bound process? 2. In the test, why did the sleeper have no forced switches? 3. What does a voluntary switch tell about the process?