asm/thread_info.h
linux/threads.h /proc/sys/kernel/pid_max
linux/sched.h
kernel/fork.c
linux/kthread.h struct task_struct *kthread_create
Process Priority
- Process Priority
- Timeslice
- The Scheduling Policy in Action
Specifically, CFS determines that the text editor has run for less time than the video encoder. Attempting to give all processes a fair share of the processor, it then preempts the video encoder and enables the text editor to run.
Scheduler Classes
- Process Scheduling in Unix Systems
- Fair Scheduling
Each scheduler class has a priority.The base scheduler code, which is defined in kernel/sched.c, iterates over each scheduler class in order of priority.
CFS is defined in kernel/sched_fair.c.
The Linux Scheduling Implementation
With the discussion of the motivation for and logic of CFS behind us, we can now explore CFS’s actual implementation, which lives in kernel/sched_fair.c.
- Time Accounting: The Scheduler Entity Structure; The Virtual Runtime
- Process Selection: Picking the Next Task; Adding Processes to the Tree; Removing Processes from the Tree
This is, in fact, the core of CFS’s scheduling algorithm: Pick the task with the smallest vruntime.That’s it! - The Scheduler Entry Point:
The main entry point into the process schedule is the function schedule(), defined in kernel/sched.c. - Sleeping and Waking Up: Wait Queues, Waking Up
Preemption and Context Switching
- User Preemption
Calls switch_to(), declared in, to switch the processor state from the previous process’s to the current’s. - Kernel Preemption
Real-Time Scheduling Policies
Via the scheduling classes framework, these real-time policies are managed not by the Completely Fair Scheduler, but by a special real-time scheduler, defined in kernel/sched_rt.c.
Scheduler-Related System Calls
Scheduling Policy and Priority-Related System Calls
Processor Affinity System Calls
Yielding Processor Time