Lecture07 - Monday April 13 Project#2 Homework#1 Progress...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Monday, April 13 Project #2 Homework #1 Progress reports? Ian's Seminar Wednesday in class Solutions are posted Friday in class Quiz #1 Today's topic Multiprocessor scheduling Process Control Blocks Linux ConstantTime Scheduler Exponential Averaging n +1 = t n + (1 - ) n . Expand the formula: n+1 = tn + (1 - ) t n-1 + ... + (1 - ) j t n-j + ... + (1 - ) n+1 0 Since both and (1 ) are less than or equal to 1, older terms have less weight (as compared to more recent terms). Typical is 0.5 Example A longrunning process's most recent actual time in the CPU was 100 ms, and its previous actual time was 140 ms. The exponential weighted average of older time slices is 180 ms. Recent history is weighted at 50%. i.e., tn1 = 140 tn = 100 = 0.5 n1 = 180 Using standard exponential averaging, what is the estimated length of this process's next time slice ( n+1)? Note: first find n , then use it to find n+1 Example Solution tn1 = 140 tn = 100 = 0.5 n1 = 180 First find n Then find n+1 = 0.5 * 140 + 0.5 * 180 = 160 n+1 = tn + (1 ) n n = tn1 + (1 ) n1 = 0.5 * 100 + 0.5 * 160 = 130 MultipleProcessor Scheduling CPU scheduling is more complex when multiple CPUs are available. Each processor must be scheduled Schedules must be coordinated Symmetric multiprocessing (SMP) Asymmetric multiprocessing (ASMP) Homogeneous processors within a multiprocessor system. One of the processors Alleviates need for data copying. accesses the system data structures coordinates other processors Multiprocessor scheduling Linux CPU schedulers provide SMP support Load balancing Process Creation Each process has an identification number (PID) Every process is a descendant of the init process (PID = 1) linux ps A shows all processes Process Creation (Cont.) linux/unix examples Note: When a new program is loaded, fork syscall creates new process exec syscall used after a fork to replace the process's instruction space with a new program. create a new process by a fork of the init process (create duplicate init process) then exec the program (load program, data, etc., into new process environment) Process Control Block (PCB) PCB is a table in each process environment Contains system information Process mode/state Program counter CPU registers CPU scheduling information Memorymanagement information Accounting information I/O status information etc. Process descriptor Linux PCB Type is struct task_struct defined in linux/sched.h stored in the task list circular doublylinked list Process Termination When process executes last statement (exit) ... output data from child to parent (via wait). process's resources are reclaimed by the operating system. Process Termination (cont.) Parent may terminate execution of child processes (abort) when , e.g. Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting. System may "reparent" an orphan child Operating system does not allow child to continue without a parent. Cascading termination. Invoking a Scheduler The scheduler is invoked ... when a process's timeslice expires when a process generates or receives an interrupt when a new or suspended process becomes runnable (priority check) on a hardware dependent interval Process descriptor Linux PCB Type is struct task_struct defined in linux/sched.h stored in the task list circular doublylinked list Linux CPU Schedulers "Constant Time Scheduler" "Rotating Stairway Deadline Scheduler" (RSDL) "Completely Fair Scheduler" (CFS) O(1) See kernel/sched.c in the 2.6.20 source tree See kernel/sched_fair.c in the 2.6.23 (and up) source tree Constant Time Scheduler Fully preemptive hybrid multilevel feedback queue with dynamic dual priority / timeslice recalculations and roundrobin scheduling with O(1) selection overhead. ~6700 lines of C code The runqueue The basic scheduler structure is the runqueue Each processor in a system implements one runqueue Each runqueue implements two arrays of queues active expired The runqueue Each array contains a separate element for each defined priority level Each array element is a queue Each queue has zero or more processes at that queue's priority level default is 140 levels Each process has a defined timeslice scheduling is "roundrobin" within each queue, quantum is hardwaredependent doesn't have to use it all in one CPU burst e.g., 100ms timeslice might use 5 x 20ms bursts (roundrobin) Selecting the next process A bitmap specifies which priority levels have active processes Very important: initially all zeros bit is set to one if the corresponding priority level's queue is not empty The bitmap makes the selection overhead O(1) i.e., the selection time does not depend on the number of active processes finding the first onebit is very fast (usually implemented in hardware) The Linux runqueue Selecting the next process Example: 00001001000111000 ... 0011000 (140 bits) means the priority4 queue has one or more active processes, and that queue will be handled first by roundrobin scheduling until every process in that queue has expired*. *expired by using up its timeslice, getting sent to a waiting queue, terminating ... Expired processes When a process's timeslice expires, the process is moved to one of the queues in the expired array. When all processes in the active array have expired, the scheduler swaps the pointers to the active and expired arrays ! priority may be recalculated timeslice is recalculated (exponential averaging) instantaneous no expensive data movement Dynamic active array At any time, a new highpriority process might arrive Highly interactive processes might be re inserted into a queue in the active array with a new timeslice and a new priority. Linux CPU scheduler is fully preemptive Sounds like starvation ... any process can be preempted ... unless it holds a lock Starvation? No! ... because Every process's timeslice must expire Default maximum timeslice is 800ms Macro checks to see if expired array has been waiting too long if so, all active processes are moved to the expired array (with recalculated priorities and timeslices), and the array pointers are swapped. Processes have two "priorities" Recalculation nice static, assigned by app or OS priority dynamic, calculated by scheduler measure of how easily the process will yield the CPU to another process 20 (CPU hog) +19 (pushover) based on nice and process interactivity index interactivity index based on percentage of time waiting while runnable Timeslice dynamic, calculated by scheduler based on priority Issues "Interactivity", which is part of the priority calculation, is based on "sleep average". Once in a while, somebody manages to fool the CPU scheduler Usually performs very well Sometimes performs very badly. Many highpriority processes swapping in an out of memory Can produce deadlock See thud.c, chew.c, etc. Questions? ...
View Full Document

This note was uploaded on 06/28/2009 for the course CS 411 taught by Professor Staff during the Spring '08 term at Oregon State.

Ask a homework question - tutors are online