Skip to content

Stub scheduler policy syscalls#22

Merged
jserv merged 1 commit into
mainfrom
sched
May 10, 2026
Merged

Stub scheduler policy syscalls#22
jserv merged 1 commit into
mainfrom
sched

Conversation

@jserv
Copy link
Copy Markdown
Contributor

@jserv jserv commented May 10, 2026

Add sched_{setparam,setscheduler,getscheduler,getparam,get_priority_min, get_priority_max,rr_get_interval}. Newer musl and glibc pthread_create probe the parent thread's policy via sched_getscheduler before spawning a worker; returning ENOSYS broke thread startup for guests that exercised that path.

Pid arguments are TIDs in Linux scheduler ABI, not TGIDs, so a worker calling sched_*(gettid()) must reach its own thread entry. Live TIDs are matched through thread_tid_alive(); unknown pids return ESRCH.

Setter errno ordering tracks Linux 6.x kernel/sched/syscalls.c: copy_from_user runs before find_process_by_pid, so a bad sched_param pointer plus an unknown pid yields EFAULT, not ESRCH.

Any policy transition away from SCHED_OTHER is refused. SCHED_BATCH and SCHED_IDLE return EPERM at priority 0 rather than being silently accepted while the stub keeps reporting SCHED_OTHER. SCHED_FIFO and SCHED_RR collapse to EINVAL when priority is outside [1, 99] and to EPERM when valid; SCHED_DEADLINE through the legacy entry is EINVAL because the syscall cannot supply deadline attributes (real Linux requires sched_setattr). SCHED_RESET_ON_FORK (0x40000000) is parsed off the policy before validation; any other high bit is EINVAL.

sched_rr_get_interval reports a 100 ms slice, matching the sched_rr_timeslice default and a typical CFS quantum, instead of a zero timespec that would mislead callers branching on the value.

sched_getaffinity also runs through the per-thread pid gate so unknown pids return ESRCH instead of silently succeeding.


Summary by cubic

Stubbed Linux scheduler policy syscalls with Linux-like TID semantics and errno order to unblock musl/glibc pthread_create and tighten PID checks. Also updated sched_getaffinity and added a targeted test for per-thread TIDs and policy validation.

  • New Features
    • Implemented sched_setparam, sched_setscheduler, sched_getscheduler, sched_getparam, sched_get_priority_min, sched_get_priority_max, sched_rr_get_interval.
    • Enforced TID-based pid args (pid 0 allowed; unknown pids return -ESRCH) and Linux-like errno order for setters/getters.
    • Modeled only SCHED_OTHER; reject other policies with Linux-like -EINVAL/-EPERM rules, strip SCHED_RESET_ON_FORK, and return a 100ms slice from sched_rr_get_interval.
    • sched_getaffinity now uses the same per-thread PID gate; added test-sched-policy and a Makefile target.

Written for commit d8873a2. Summary will update on new commits.

Add sched_{setparam,setscheduler,getscheduler,getparam,get_priority_min,
get_priority_max,rr_get_interval}. Newer musl and glibc pthread_create
probe the parent thread's policy via sched_getscheduler before spawning
a worker; returning ENOSYS broke thread startup for guests that exercised
that path.

Pid arguments are TIDs in Linux scheduler ABI, not TGIDs, so a worker
calling sched_*(gettid()) must reach its own thread entry. Live TIDs
are matched through thread_tid_alive(); unknown pids return ESRCH.

Setter errno ordering tracks Linux 6.x kernel/sched/syscalls.c:
copy_from_user runs before find_process_by_pid, so a bad sched_param
pointer plus an unknown pid yields EFAULT, not ESRCH.

Any policy transition away from SCHED_OTHER is refused. SCHED_BATCH
and SCHED_IDLE return EPERM at priority 0 rather than being silently
accepted while the stub keeps reporting SCHED_OTHER. SCHED_FIFO and
SCHED_RR collapse to EINVAL when priority is outside [1, 99] and to
EPERM when valid; SCHED_DEADLINE through the legacy entry is EINVAL
because the syscall cannot supply deadline attributes (real Linux
requires sched_setattr). SCHED_RESET_ON_FORK (0x40000000) is parsed
off the policy before validation; any other high bit is EINVAL.

sched_rr_get_interval reports a 100 ms slice, matching the
sched_rr_timeslice default and a typical CFS quantum, instead of a
zero timespec that would mislead callers branching on the value.

sched_getaffinity also runs through the per-thread pid gate so unknown
pids return ESRCH instead of silently succeeding.
@jserv jserv mentioned this pull request May 10, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

@jserv jserv merged commit 53723e5 into main May 10, 2026
5 checks passed
@jserv jserv deleted the sched branch May 10, 2026 12:10
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