freenode
Kernel & Low-Level

Proxy execution work tackles sleeping lock owners

Stultz's latest Linux scheduler series also fixes priority inversion, stall accounting, and a use-after-free in the experimental feature.

Google's John Stultz has posted the next stage of proxy execution, the Linux scheduler work that lets a task blocked on a mutex lend its place on the CPU to the lock owner so a higher-priority waiter is not stuck behind a lower-priority holder.

This stage covers the case where that owner is itself asleep. Priority boosting cannot wake a sleeping task, so the waiter is taken off the runqueue and parked on a list attached to the owner. When the owner wakes, those waiters are put back on the same CPU so they can boost it. Stultz said the idea is simple and the implementation is not: waiters form trees, a task in the middle of a tree can wake, and that cascade has to be unwound without losing or double-counting anyone. He asked scheduler maintainer Peter Zijlstra to consider landing the earlier correctness fixes even if the full feature is not ready to queue.

Those fixes matter because proxy execution already breaks assumptions elsewhere in the scheduler. A mutex-blocked task stays on the runqueue, so the task the CPU is running and the task whose context it is using can differ. Mathieu Desnoyers found that waking the donor did not force a reschedule: the scheduler compared the woken task with itself and left the old owner running in the donor's context. In his tests a real-time waiter ran 800 milliseconds late, and a deadline waiter consumed a period of the donor's runtime. A separate bug left real-time and deadline tasks unable to migrate to an idle CPU after an in-place wake, so a FIFO task waited half a second behind a higher-priority task while another CPU sat idle.

Other patches repair pressure-stall accounting that could report full memory stalls above partial ones, a remote tick that looked at the wrong task after the local tick had been stopped, and a use-after-free if a donor exited while the owner still held a pointer used for mutex handoff. Cycles in the blocked-on chain, which can spin while holding the runqueue lock, are cut off as well. Load tracking and deadline bandwidth were also wrong when blocked donors moved between CPUs. Kernel locks are not supposed to cycle, but the series is being built toward user-controlled futexes, where the kernel cannot assume the chain is well formed.