Page MenuHomeFreeBSD

SCHED_4BSD: maybe_resched() cannot schedule ast() for curthread
ClosedPublic

Authored by kib on Jan 29 2026, 6:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 2, 3:49 PM
Unknown Object (File)
Tue, Feb 24, 3:08 PM
Unknown Object (File)
Sun, Feb 22, 1:15 PM
Unknown Object (File)
Sat, Feb 14, 4:14 PM
Unknown Object (File)
Thu, Feb 12, 11:56 PM
Unknown Object (File)
Tue, Feb 10, 3:47 AM
Unknown Object (File)
Feb 5 2026, 4:24 AM
Unknown Object (File)
Feb 5 2026, 4:24 AM
Subscribers

Details

Summary
SCHED_4BSD: maybe_resched() cannot schedule ast() for curthread

maybe_resched() needs to schedule TDA_SCHED for curthread, but this
requires taking curthread lock while owning some other thread lock.  To
avoid introducing the order
- Use a scheduler-private TDP flag
- register an unconditional TDA_SCHED_PRIV for 4BSD
When an AST needs to be scheduled, i.e. the current thread must do
context switch in the return to userspace path, set the flag.
Then the ast handler calls ast_scheduler(), which gives the same
effect as scheduling TDA_AST.

The overhead is a single function call on each userspace return, for
4BSD case.

Reported and tested by: pho

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Jan 29 2026, 6:19 PM
kib edited the summary of this revision. (Show Details)

Simplify. Use TDP_SCHED1 instead of the new field in the ts structure.

sys/kern/sched_4bsd.c
284

KASSERT that td == curthread here?

kib marked an inline comment as done.Jan 29 2026, 10:34 PM
kib added inline comments.
sys/kern/sched_4bsd.c
284

This is ast handler, so the invariant holds by definition.
But added the MPASS().

kib marked an inline comment as done.

Add assert that ast handler is called for curthread.

markj added inline comments.
sys/kern/sched_4bsd.c
284

the invariant holds by definition

Not quite though, ast_kclear() may call the AST handler. I'm aware it does not do that here, today.

This revision is now accepted and ready to land.Jan 29 2026, 11:01 PM