Runnable queues, scheduling classes và context-switch cost
CPU utilization không nói queue delay, throttling hay lock waits; scheduler evidence cần per-task state, run queue và cgroup quota.
Scheduler
Task states
Running/runnable, interruptible sleep, uninterruptible sleep, stopped/traced and zombie. D state thường chờ kernel I/O và đóng góp load average; R tasks compete CPU. Tool letters are snapshots, sample over time.
Scheduling classes
Normal CFS/EEVDF-style fair scheduling influenced by nice/weight; real-time FIFO/RR and deadline have stricter semantics/risk. Priority is not guaranteed latency under locks/I/O/IRQ and misuse can starve system.
Context switches
Voluntary switch when block/yield; involuntary when preempted/time slice. Cost includes scheduler, register state, cache/TLB/branch predictor locality and NUMA migration. Count alone not bad: high switches from useful I/O differ from lock thrash.
Affinity and NUMA
CPU affinity can preserve locality or isolate workloads but reduces scheduler flexibility and creates hotspots. NUMA remote memory access matters; thread/memory placement and GC behavior need measurement. Containers cpuset/quota expose different CPU views.
cgroup CPU
cpu.weight shares relative capacity; cpu.max quota/period can throttle despite host idle in other scopes. Check cpu.stat throttled_usec/nr_throttled, pressure stall and application latency. Requests/limits and runtime processor detection influence pool sizing.
Queueing
Concurrency above service capacity grows runnable/wait queues. Little's Law helps relate throughput, latency and in-flight under stable conditions. Bound worker pools, use backpressure and identify first queue; adding threads often moves bottleneck.