Operating Systems CMPSC 473 Processes 6 September 24
Operating Systems CMPSC 473 Processes (6) September 24 2008 - Lecture 12 Instructor: Bhuvan Urgaonkar
Announcements • Quiz 1 is out and due in at midnight next M • Suggested reading: Chapter 4 of SGG • Honors credits – Still possible to enroll – Email me if you are interested – Extra work in projects
• Done Overview of Process. How a process is born – Parent/child relationship related Topics – fork, clone, … • How it leads its life – Loaded: Later in the course – Executed • CPU scheduling • Context switching • Where a process “lives”: Address space Done – OS maintains some info. for each process: PCB – Process = Address Space + PCB • How processes request services from the OS – System calls • • How processes communicate Threads (user and kernel-level) How processes synchronize How processes die Done Partially done Start today Finish today
Multi-threading Models • User-level thread libraries – E. g. , the one provided with Project 1 – Implementation: You are expected to gain this understanding as you work on Project 1 – Pop quiz: Context switch overhead smaller. Why? – What other overheads are reduced? Creation? Removal? • Kernel-level threads • There must exist some relationship between user threads and kernel threads – Why?
Multi-threading Models: Many-to-one Model User thread k Kernel thread • Thread management done by user library • Context switching, creation, removal, etc. efficient (if designed well) • Blocking call blocks the entire process • No parallelism on u. Ps? Why? • Green threads library on Solaris
Multi-threading Models: One-to-many Model User thread k k Kernel thread • Each u-l thread mapped to one k-l thread • Allows more concurrency – If one thread blocks, another ready thread can run – Can exploit parallelism on u. Ps • Popular: Linux, several Windows (NT, 2000,
Multi-threading Models: Many-to-many Model User thread k k k Kernel thread • # u-l threads >= #k-l threads • Best of both previous approaches?
Multi-threading Models: Many-to-many Model (2) User thread Kernel thread k k • Popular variation on many-to-many model • Two-level model • IRIX, HP-UX, Tru 64 UNIX, Older than Solaris 9
Popular Thread Libraries • Pthreads – The POSIX standard (IEEE 1003. 1 c) defining an API for thread creation and synchronization – Specification NOT implementation – Recall 311 and/or Check out Fig 4. 6 – You will use this in Project 1 • Win 32 threads • Java threads – JVM itself is at least a thread for the host OS – Different implementations for different OSes
Thread-specific Data • Often multi-thread programs would like to have each thread have access to some data all for itself • Most libraries provide support for this including Pthreads, Win 32, Java’s lib.
Approach #3: User or kernel support to automatically share code, data, files! code registers stack heap registers stack data registers stack files registers stack In virtual memory threads URL parsing process Network sending process Network reception process Interprets response, composes media together and displays on browser screen • E. g. , a Web browser • Share code, data, files (mmaped), via shared memory mechanisms (coming up) – Burden on the programmer • Better yet, let kernel or a user-library handle sharing of these parts of the address spaces and let the programmer deal with synchronization issues
Approach #3: User or kernel support to automatically share code, data, files! code registers stack heap data registers stack heap registers stack files heap registers stack heap In virtual memory threads URL parsing process Network sending process Network reception process Interprets response, composes media together and displays on browser screen • E. g. , a Web browser • Share code, data, files (mmaped), via shared memory mechanisms (coming up) – Burden on the programmer • Better yet, let kernel or a user-library handle sharing of these parts of the address spaces and let the programmer deal with synchronization issues – User-level and kernel-level threads
Scheduler Activations User thread • Kernel provides LWPs that appear like processor to the u-l library • Upcall: A way for the kernel to notify an application about certain events – Similar to signals • E. g. , if a thread is about to block, kernel makes an upcall and allocates it a new LWP Lightweight • U-l runs an upcall handler that may schedule process another eligible thread on the new LWP • Similar upcall to inform application when the Kernel thread blocking operation is done k • Read Sec 4. 4. 6 • Paper by Tom Anderson (Washington) in early 90 s • Pros and cons?
Costs/Overheads of a Context Switch • Direct/apparent – Time spent doing the switch described in previous lectures – Fixed (more or less) • Indirect/hidden costs – Cache pollution – Effect of TLB pollution (will study this when we get to Virtual Memory Management) – Workload dependent
- Slides: 14