Linux /proc/schedstat Exposes Per-Thread Scheduling Wait, But Metric Has a Flaw
A developer analyzing Linux thread scheduling found that /proc/[pid]/task/[tid]/schedstat exposes per-thread runqueue wait time, allowing engineers to identify which threads are being denied CPU time on a running system. A bash script was built to delta two snapshots of this file and rank threads by either absolute wait-seconds or a wait-fraction metric calculated as wait divided by total runnable time. Testing revealed a counterintuitive problem: idle kernel threads like ksoftirqd scored a 94.7% wait fraction on a quiet machine, while genuinely starved whisper.cpp threads under heavy load scored only 65.7%. This means the fraction-based metric ranks idle threads as needier than truly starved ones, inverting the severity signal an operator would want. The article concludes that the denominator — a thread's own runnable time — is the root cause of the inversion, leaving the metric unreliable for alerting on real CPU starvation.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in