60 likes | 92 Views
Linux Process (Task) Structure and Scheduling Overview. CS3013 C02 Jae Chung & Hariharan Kannan. Process Control Block (PCB). Process is called “ Task ” in Linux PCB: struct task_struct Essentials : pid, state, *stack, *files, *semaphore Task Ment : *next_task, *prev_task, *ptree, …
E N D
Linux Process (Task) Structure and Scheduling Overview CS3013 C02 Jae Chung & Hariharan Kannan
Process Control Block (PCB) • Process is called “Task” in Linux • PCB: struct task_struct • Essentials: pid, state, *stack, *files, *semaphore • Task Ment: *next_task, *prev_task, *ptree, … • Task Sched: priority, counter, *next_run, *prev_run • Resource Usage: times, maj_flt, min_flt, nswap • And more …
Init (0) Init (0) 1 … n 1 2 3 … … … … Init (0) 3 … m Task Managements Task Tree (All Tasks) Task List (All Tasks) Run Queue (Ready Tasks)
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) • process with most credits is selected • goodness() = 0 (if counter = 0) • goodness() = counter + priority (otherwise) • Timer goes off (jiffy, 1 per 10 ms) • then lose a count (0, then suspend) • No runnable process (all suspended) • reload (recalculate) counter value • 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)