THINK FIRST·CODE LATER

← All labs

Linux in practice: affinity, real-time classes and migrations

Problem

On a Linux machine with at least 2 cores:

  1. Start a CPU-bound process: yes > /dev/null &. Run ps -o pid,psr,cls,ni,pri,comm -p <pid> several times. The PSR column is the core it is running on — does it move? Then pin it: taskset -cp 1 <pid> and check again.
  2. cat /proc/<pid>/sched | head -25 — find se.vruntime, nr_migrations, nr_voluntary_switches and nr_involuntary_switches. Explain voluntary vs. involuntary switches for yes compared with sleep 100.
  3. Start two more yes processes pinned to core 1 with taskset -c 1, one of them with nice -n 5. Use top to verify the CFS shares (Chapter 5 predicts 75.3% / 24.7% for nice 0 vs. 5 when two tasks compete).
  4. Carefully try a real-time class: sudo chrt -f 10 taskset -c 1 yes > /dev/null & (SCHED_FIFO priority 10) while the nice-0 yes still runs on core 1. What happens to the normal task's CPU share? Why is running a CPU-bound SCHED_FIFO task dangerous? Kill all yes processes afterwards (pkill yes).
  5. cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor and scaling_cur_freq (if available) — which DVFS governor is used, and does the frequency change under load?

Report the key output and explain it with this chapter's concepts.

Work it out on paper, in a document or here, then compare with the model answer. Your answer stays in your browser — it is never sent to or stored on the server.