Linux Process (Task) Structure and Scheduling Overview CS 3013 C 02 Jae Chung & Hariharan Kannan
Process Control Block (PCB) Process is called “Task” in Linux PCB: struct task_struct w Essentials: pid, state, *stack, *files, *semaphore w Task Ment: *next_task, *prev_task, *ptree, … w Task Sched: priority, counter, *next_run, *prev_run w Resource Usage: times, maj_flt, min_flt, nswap w And more …
Task Managements Init (0) Task Tree (All Tasks) 1 2 3 … … … Task List (All Tasks) Init (0) 1 … Run Queue (Ready Tasks) Init (0) 3 … … n m
Linux Scheduler Functions (Previous process give up CPU) Handles interrupts (latter half) Select next process (task) to run Performs context switch if necessary (Let go the next process selected)
Linux Process Scheduling Normal: Credit-Based (counter variable) w process with most credits is selected w goodness() = 0 (if counter = 0) w goodness() = counter + priority (otherwise) w Timer goes off (jiffy, 1 per 10 ms) w then lose a count (0, then suspend) w No runnable process (all suspended) w reload (recalculate) counter value w counter = counter/2 + priority Real-Time: goodness() = 1000 + rt_priority
Kernel Source Files to Start /usr/src/linux/include/linux/sched. h /usr/src/linux/kernel/sched. c /usr/src/linux/kernel/sys. c (getrusage) /usr/src/linux/kernel/fork. c (fork)