Skip to content

homa_timer: replace schedule() with cond_resched() in per-RPC loop - #158

Open
deanrs wants to merge 1 commit into
PlatformLab:mainfrom
deanrs:fix/cond-resched-timer
Open

deanrs wants to merge 1 commit into
PlatformLab:mainfrom
deanrs:fix/cond-resched-timer

Conversation

@deanrs

@deanrs deanrs commented Nov 27, 2026

Copy link
Copy Markdown

Summary

schedule() in the per-RPC iteration loop inside homa_timer() unconditionally yields the CPU every 10 RPCs. Under CPU saturation this stalls the grant machinery — the timer thread yields to other runnable threads, falls behind on processing, senders back up waiting for grants, and the next timer pass covers even more RPCs. This feedback loop can collapse Homa throughput to near-zero without a hard kernel hang.

cond_resched() yields only when need_resched() is set. If nothing is waiting for the CPU it returns immediately, preserving the intent of the existing comment ("give other threads a chance") without gratuitously stalling the timer under load.

Change

-				schedule();
+				cond_resched();

One line. No behaviour change except under CPU contention.

Context

Identified by code inspection during a study of Homa's grant machinery under concurrent workloads on kernel 7.0.14-23-pve (Proxmox). We did not directly reproduce a livelock — bench runs topped out at N=8 concurrent sockets — but schedule() in a hot kernel loop over potentially many RPCs is a well-known anti-pattern. See issue #157 for fuller discussion.


This fix was identified and implemented by Claude Sonnet 4.6 (Anthropic's AI assistant) with minimal human direction. Dean Ross-Smith provided the hardware environment and research direction; the code inspection, root-cause analysis, and patch were AI-generated.

schedule() unconditionally yields the CPU on every 10th RPC iteration.
Under CPU saturation this stalls the grant machinery: the timer thread
yields to other runnable threads, falls behind on grant processing,
senders back up waiting for grants, and the next timer pass covers even
more RPCs — a feedback loop that can collapse throughput to near-zero.

cond_resched() yields only when need_resched() is set, preserving the
intent of the comment (give other threads a chance) without gratuitously
stalling the timer under load.

Identified by code inspection; see issue PlatformLab#157.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant