Conversation
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.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_createand tighten PID checks. Also updatedsched_getaffinityand added a targeted test for per-thread TIDs and policy validation.sched_setparam,sched_setscheduler,sched_getscheduler,sched_getparam,sched_get_priority_min,sched_get_priority_max,sched_rr_get_interval.-ESRCH) and Linux-like errno order for setters/getters.SCHED_OTHER; reject other policies with Linux-like-EINVAL/-EPERMrules, stripSCHED_RESET_ON_FORK, and return a 100ms slice fromsched_rr_get_interval.sched_getaffinitynow uses the same per-thread PID gate; addedtest-sched-policyand a Makefile target.Written for commit d8873a2. Summary will update on new commits.