Part 5 of 7 · 2 min read
Latency
In plain words: A taxi driver waiting at a stand moves at once when a call comes, if the road is free. If the stand is full of other cars that are also moving, the driver may wait to get out. A task that has slept and is made ready by an event (a timer, a packet, a key) is in the same position. The analogy stops in one place: a taxi can sound a horn to pass, while a task has only its priority and its weight.
The wake-up latency is the time between the moment the event makes a task ready and the moment the task first runs. For an interactive program, this is what the user feels, more than the average share.
A test measures it. A program pinned to one processor sleeps 10 ms 200 times and notes how late each wake-up was. Spinning tasks run on the same processor. The averages and the worst cases:
| Competing spinning tasks | Average lateness | Worst lateness |
|---|---|---|
| 0 | 0.19 ms | 1.29 ms |
| 1 | 0.12 ms | 3.99 ms |
| 2 | 0.12 ms | 4.00 ms |
| 4 | 1.66 ms | 4.66 ms |
With one or two spinners, the sleeper usually ran at once (average 0.12 ms): the scheduler favours a task that has been sleeping, as page 5 explained (it is owed time). The worst cases of about 4 ms show a wake-up that had to wait out the slice of the running task. With four spinners the average rose to 1.66 ms.
Can the spinners be made less harmful? Three variants of the four-spinner test, three runs each:
| Spinners run as | Average lateness | Worst lateness |
|---|---|---|
| nice 0 | 1.8 to 2.0 ms | 4 to 8.5 ms |
| nice 10 | 2.0 ms | 4.0 ms |
SCHED_IDLE |
0.07 to 0.21 ms | 0.15 to 7.6 ms |
Raising the nice value to 10 did not help the sleeper's latency here, though it cut the spinners' share of the processor (page 5). SCHED_IDLE made the average about ten times smaller, because an idle-class task never stands in the way of a normal one. The rare long worst case in the idle runs (7.6 ms in one run) shows that single values vary between runs, so a claim about latency needs many samples.
Wake-up latency
Wake-up latency is the time from the moment an event makes a sleeping task runnable to the moment that task starts to run on a processor.
Example: a task whose timer expires at 100.000 ms and which first runs at 100.120 ms has a wake-up latency of 0.12 ms.
Check yourself:
1. What was the average lateness with four normal-priority spinners?
2. Why did SCHED_IDLE spinners help more than nice 10 spinners?
3. Why is a single worst-case figure not enough?