Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Read the classes (20 minutes)
Run ps -eo pid,ni,pri,cls,psr,comm | head -20 on your machine. List the classes you see and one task of each.
Done when: a list with TS and, if present, FF or RR.
Hint
TS is time sharing, the normal class.
Easy 2: Throttle numbers (20 minutes)
Read sched_rt_runtime_us and sched_rt_period_us. Compute the share left for normal tasks.
Done when: the share (period − runtime) ÷ period, 5 per cent for the default values.
Hint
(1,000,000 − 950,000) ÷ 1,000,000.
Easy 3: Pick the policy (20 minutes)
Choose a policy for: a video encoder run overnight, a motor controller with a 1 ms deadline, and a web browser.
Done when: SCHED_BATCH or SCHED_IDLE, a real-time or deadline policy, and SCHED_OTHER.
Hint
Think of what must be met on time, and what may wait.
Medium
Medium 1: Idle against normal (30 minutes)
Pin two spinning loops to one processor, one under chrt -i 0. Run for 5 seconds and read both CPU times from /proc/<pid>/stat (fields 14 and 15).
Done when: a table in which the idle loop gets below 1 per cent.
Hint
The fields 14 and 15 of /proc/<pid>/stat are user and system ticks.
Medium 2: The real-time limit (30 minutes)
Run a normal loop and a chrt -r 10 loop pinned to one processor for 6 seconds. Report the share of the normal one and compare it with 1 − runtime ÷ period.
Done when: a share near 5 per cent and one sentence of explanation.
Hint
Both loops must share one processor.
Medium 3: Check your privileges (30 minutes)
Write the sched_setscheduler program of section 2. Run it as the superuser (or with sudo) and as an ordinary user. Record both results.
Done when: two outputs, one with the new policy and one with Operation not permitted.
Hint
Without privileges, sched_setscheduler returns -1 with EPERM.
Hard
Hard 1: Measure wake-up latency (60 minutes)
Write the wake-up test: pin to one processor, sleep 10 ms 200 times, record the lateness. Run it with 0, 2 and 4 spinners at nice 0, then with the spinners at nice 10 and under SCHED_IDLE. Report averages and worst cases.
Done when: a table like section 4, with a sentence on whether nice helps on your kernel.
Hint
Subtract the requested sleep from the measured one.
Hard 2: Diagnose a staged problem (90 minutes)
Start six spinners at nice 0 and one program that does a 5 ms burst of work every 50 ms. Use vmstat, top and /proc/<pid>/sched to diagnose the problem, apply the lightest remedy that brings the program's lateness under 1 ms, and show the numbers before and after.
Done when: a short report with r, the lateness before and after, and the remedy used.
Hint
The spinners give r of 7 on two processors.
Hard 3: Compare the whole level (90 minutes)
Using your simulators from pages 2 to 6, build one table for the workload of page 1 that shows the average turnaround, waiting and response time for FCFS, SJF, SRTF, round robin (quantum 3) and priority (priorities of your choice). Write six sentences on which policy suits which system.
Done when: a table with five rows and a justified choice for a desktop, a batch server and a controller.
Hint
Reuse the same four processes in every simulator.