kernel/sched/syscalls.c
Source file repositories/reference/linux-study-clean/kernel/sched/syscalls.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/syscalls.c- Extension
.c- Size
- 39383 bytes
- Lines
- 1579
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/cpuset.hlinux/sched/debug.huapi/linux/sched/types.hsched.hautogroup.h
Detected Declarations
syscall nicesyscall sched_setschedulersyscall sched_setparamsyscall sched_setattrsyscall sched_getschedulersyscall sched_getparamsyscall sched_getattrsyscall sched_setaffinitysyscall sched_getaffinitysyscall sched_yieldsyscall sched_get_priority_maxsyscall sched_get_priority_minsyscall sched_rr_get_intervalsyscall sched_rr_get_interval_time32function Copyrightfunction normal_priofunction effective_priofunction set_user_nicefunction sched_setschedulerfunction scoped_guardfunction can_nicefunction can_nicefunction task_priofunction idle_cpufunction sched_core_idle_cpufunction find_get_taskfunction check_same_ownerfunction __setscheduler_dl_pifunction __setscheduler_dl_pifunction uclamp_resetfunction __setscheduler_uclampfunction for_each_clamp_idfunction uclamp_validatefunction __setscheduler_uclampfunction __sched_setschedulerfunction SCHED_DEADLINEfunction scoped_guardfunction _sched_setschedulerfunction sched_set_fifofunction sched_setattrfunction sched_setattr_nocheckfunction stop_machinefunction sched_set_fifofunction sched_set_fifo_lowfunction thefunction sched_set_normalfunction do_sched_setschedulerfunction sched_copy_attr
Annotated Snippet
SYSCALL_DEFINE1(nice, int, increment)
{
long nice, retval;
/*
* Setpriority might change our priority at the same moment.
* We don't have to worry. Conceptually one call occurs first
* and we have a single winner.
*/
increment = clamp(increment, -NICE_WIDTH, NICE_WIDTH);
nice = task_nice(current) + increment;
nice = clamp_val(nice, MIN_NICE, MAX_NICE);
if (increment < 0 && !can_nice(current, nice))
return -EPERM;
retval = security_task_setnice(current, nice);
if (retval)
return retval;
set_user_nice(current, nice);
return 0;
}
#endif /* __ARCH_WANT_SYS_NICE */
/**
* task_prio - return the priority value of a given task.
* @p: the task in question.
*
* Return: The priority value as seen by users in /proc.
*
* sched policy return value kernel prio user prio/nice
*
* normal, batch, idle [0 ... 39] [100 ... 139] 0/[-20 ... 19]
* fifo, rr [-2 ... -100] [98 ... 0] [1 ... 99]
* deadline -101 -1 0
*/
int task_prio(const struct task_struct *p)
{
return p->prio - MAX_RT_PRIO;
}
/**
* idle_cpu - is a given CPU idle currently?
* @cpu: the processor in question.
*
* Return: 1 if the CPU is currently idle. 0 otherwise.
*/
int idle_cpu(int cpu)
{
return idle_rq(cpu_rq(cpu));
}
/**
* idle_task - return the idle task for a given CPU.
* @cpu: the processor in question.
*
* Return: The idle task for the CPU @cpu.
*/
struct task_struct *idle_task(int cpu)
{
return cpu_rq(cpu)->idle;
}
#ifdef CONFIG_SCHED_CORE
int sched_core_idle_cpu(int cpu)
{
struct rq *rq = cpu_rq(cpu);
if (sched_core_enabled(rq) && rq->curr == rq->idle)
return 1;
return idle_cpu(cpu);
}
#endif /* CONFIG_SCHED_CORE */
/**
* find_process_by_pid - find a process with a matching PID value.
* @pid: the pid in question.
*
* The task of @pid, if found. %NULL otherwise.
*/
static struct task_struct *find_process_by_pid(pid_t pid)
{
return pid ? find_task_by_vpid(pid) : current;
}
static struct task_struct *find_get_task(pid_t pid)
{
Annotation
- Immediate include surface: `linux/sched.h`, `linux/cpuset.h`, `linux/sched/debug.h`, `uapi/linux/sched/types.h`, `sched.h`, `autogroup.h`.
- Detected declarations: `syscall nice`, `syscall sched_setscheduler`, `syscall sched_setparam`, `syscall sched_setattr`, `syscall sched_getscheduler`, `syscall sched_getparam`, `syscall sched_getattr`, `syscall sched_setaffinity`, `syscall sched_getaffinity`, `syscall sched_yield`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.