Threads, SMP, and MicroKernels

Slides:



Advertisements
Similar presentations
Threads Chapter 4 Threads are a subdivision of processes
Advertisements

Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Threads, SMP, and Microkernels
Operating Systems: Internals and Design Principles
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chorus and other Microkernels Presented by: Jonathan Tanner and Brian Doyle Articles By: Jon Udell Peter D. Varhol Dick Pountain.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Operating Systems (OS) Threads, SMP, and Microkernel, Unix Kernel
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads, SMP, and Microkernels
Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Computer System Architectures Computer System Software
Operating System A program that controls the execution of application programs An interface between applications and hardware 1.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Operating Systems Lecture 09: Threads (Chapter 4)
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Operating System 4 THREADS, SMP AND MICROKERNELS
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Operating Systems 1 K. Salah Module 2.0: Processes Process Concept Trace of Processes Process Context Context Switching Threads –ULT –KLT.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Ihr Logo Operating Systems Internals & Design Principles Fifth Edition William Stallings Chapter 2 (Part II) Operating System Overview.
Threads G.Anuradha (Reference : William Stallings)
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
Threads, SMP, and Microkernels Chapter 4. Threads, SMP, and Microkernels 1. Processes and threads 2. Symmetric MultiProcessing (SMP) 3. Microkernel: structuring.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Operating System 4 THREADS, SMP AND MICROKERNELS.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
Chapter 4 Threads Seventh Edition By William Stallings Operating Systems: Internals and Design Principles.
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Module 2.0: Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Threads, SMP and Microkernels Process vs. thread: –Unit of resource ownership (process has virtual address space, memory, I/O channels, files) –Unit of.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
CS 6560: Operating Systems Design
Chapter 4 Threads.
Threads, SMP, and Microkernels
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads and Concurrency
Threads Chapter 4.
Chapter 4 Threads, SMP, and Microkernels
Presentation transcript:

Threads, SMP, and MicroKernels Processes and threads The two characteristics of a process unit of resource ownership virtual address space for the process image I/O channels, devices, files unit of dispatching/scheduling/execution This is the execution path through one or more modules. It is also the entity that is being scheduled and dispatched by the OS. A process may have many dispatching units. A unit of dispatching is commonly called a thread or lightweight process. New notion of Process : unit of resource ownership

Threads Single process, single thread DOS Multiple processes, single thread per process UNIX One process, multiple threads Java run-time (actually not an OS) Multiple processes, multiple threads per process Solaris, Windows 2000/XP, Windows XP, Mach, OS/2, Linux Multithreading a process unit of protection and unit of resource allocation virtual address space, process image protected access to processors, interprocess communication (IPC), files, I/O resources

Threads (cont.) Multithreading (cont.) Each thread has a thread execution state (running, ready, etc.) a separate control block, with priority, some thread related state information, and saved processor context when not running (with program counter) an execution stack some per-thread static storage for local variables access to the memory and resources of its process, shared with all other threads in the process, A single application logically doing several functions, especially in GUI systems. Example application -- a file server entertaining requests to create, open, read, and write on files. One thread per request Two threads cannot write on the same file at the same time.

less time to switch between two threads within the same process Benefits of threads less time to create (10 times) and terminate than doing the same thing to a process less time to switch between two threads within the same process parallel processing -- multiple threads executing simultaneously on different processors. communication between different executing modules within the same process In most OS, communication between independent processes requires the intervention of the kernel to provide protection and the mechanism needed for communication. Because threads within the same task share memory and files, they can communicate with each other without invoking the kernel.

Example applications using threads Threads in a spreadsheet program One thread displays menus and read user input (foreground work). Another thread executes user commands and updates the spreadsheet (background work). Adobe PageMaker Writing, design, and production tool for desktop publishing service thread event-handling thread screen-drawing thread When the event-handling thread (e.g., doing a large computation, etc.) or the screen-drawing thread is busy, the service thread (e.g., printing, file importing, etc.) restricts user activity by disabling menu items and displaying a “busy” cursor. The user is free to switch to other applications, or even kill the computation through the service thread.

Example applications using threads (cont.) Adobe PageMaker (cont.) Dynamic scrolling Redrawing the screen as the user drags the scroll indicator -- is possible. The event-handling thread monitors the scroll bar and redraws the margin ruler (which can be done relatively quickly). Meanwhile, the screen-redraw thread constantly tries to redraw the page and catch up. (Each user click on the scroll bar aborts the previous drawing and starts a new one.) In this example, the event-handling thread can be considered as doing foreground work while the screen-redraw thread is considered the background work.

Example applications using threads (cont.) Asynchronous processing Have a backup thread periodically saving the current user data to disk when the main thread is doing some computation. Speedy execution In a multiprocessor system, one thread reads in data while another thread does the computation.

Threads (cont.) Because all threads in a task share the same address space, all threads must enter a suspend state at the same time. Thread functionality thread states running, ready, blocked no suspend state thread operations spawn, block, unblock, finish thread synchronization The alteration of one resource by a thread affects other threads. e.g., opening files same techniques as process synchronization

User-level threads (ULT) thread management done by a threads library at user mode/space thread spawning, destruction, scheduling, message passing, switching--saving and restoring thread context setting state of each thread kernel not aware of existence of threads Examples in Fig. 4.7 Fig. 4.7b: thread 2 invokes I/O action. Fig. 4.7c: process B’s clock quantum expires. Fig. 4.7d: thread 2 needs some action performed by thread 1; thread switching occurs and is managed by threads library.

advantages of ULT over KLT ULT vs KLT advantages of ULT over KLT Thread switching does not require kernel mode privileges, i.e., no mode switches. Scheduling can be application specific. round-robin for one application, priority-based for another ULT runs on any OS, even ones not supporting multithreading. disadvantages of ULT In a typical OS, many system calls are blocking. When a ULT executes a system call (I/O, etc.) , all of the threads within the process are blocked. A multithreaded application cannot take advantage of multiprocessing: the kernel assigns only one CPU to the process.

Kernel-level threads (KLT) also called lightweight processes thread management done by kernel Examples: Windows 2000, Linux, OS/2 advantages of KLT The kernel can assign multiple CPUs to different threads of the same process, i.e., true multiprocessing. If one thread in a process is blocked, the kernel can schedule another thread of the same process. Kernel routines themselves can be multithreaded. disadvantages of KLT The transfer of control from one thread to another within the same process requires a mode switch to the kernel. This is very time consuming. See table 4.1.

Combined ULT and KLT example: Solaris Thread creation, scheduling, and synchronization are done completely in user space. The multiple ULTs from a single application are mapped onto some (smaller or equal) number of KLTs. advantages Multiple threads within the same application can run in parallel on multiple CPUs. A blocking system call need not block the entire process.

User and Kernel-Level Threads Performance Null fork: the time to create, schedule, execute, and complete a process/thread that invokes the null procedure. Signal-Wait: the time for a process/thread to signal a waiting process/thread and then wait on a condition. Procedure call: 7 s Kernel Trap:17 s Thread Operation Latencies (taken on VAX (1992))

User and Kernel-Level Threads Performance Observations While there is a significant speedup by using KLT multithreading compared to single-threaded processes, there is an additional significant speedup by using ULTs. However, whether or not the additional speedup is realized depends on the nature of the applications involved. If most of the thread switches require kernel mode access, then ULT may not perform much better than KLT.

Symmetric multiprocessing SISD (Single instruction, single data stream) SIMD (multiple data stream) vector and array processors MIMD (multiple instruction, multiple data stream) general purpose processors, each capable of processing any instruction distributed memory (loosely coupled) shared memory (tightly coupled) master/slave The OS kernel always runs on a particular processor (master). relatively simple OS (compared to SMP) Disadvantages: single point of failure, bottleneck

Symmetric multiprocessing (cont.) shared memory (tightly coupled) (cont.) symmetric (SMP) kernel executed as multiple processes or threads Each processor may execute these kernel threads; self scheduling. Complicated OS : synchronization, conflict resolution, etc. SMP organization shared memory, bus, I/O subsystem separate cache : cache coherence problem

Multiprocessor OS design considerations simultaneous concurrent processes or threads reentrant code for kernel routines no deadlock for kernel tables and management structures scheduling synchronization mutual exclusion, locks, event ordering memory management coordinate paging of processor/cache couple reliability graceful degradation during processor failure

microkernel architecture Microkernels microkernel architecture Old OS’s are big IBM OS/360: 5000 programmers, 1 million lines, 5 years Multics: 20 million lines Difficulty of maintenance New OS’s: object-oriented architecture absolutely essential core OS functions kernel (supervisor) mode external subsystems built on the microkernel executed in user mode as server processes (that are part of the OS) interaction via message passing through microkernel device drivers, file systems, virtual memory manager, windowing system, security services

Benefits of a microkernel organization uniform interface no distinction between user-level and kernel-level services: all done by message passing extensibility e.g., addition of new types of disks flexibility easiness of modification to adapt to different environment addition/deletion of services for different types of users portability minimal effort to port to different machines reliability microkernel can be rigorously tested because of its small size; small number of API library functions distributed system support A process can send a message (with service provider ID) without knowing on which machine the target service resides. Object-oriented OS

Performance of microkernel Microkernels (cont.) Performance of microkernel It takes longer to build and send messages than to make supervisor calls. more user/kernel mode switch than traditional OS Microkernel design no absolute rules on services included hardware dependent functions functions needed to support servers and applications running in user mode Low-level memory management mapping a virtual page to a physical page frame outside microkernel protection of address space of one process from another at process level page replacement algorithm application-specific memory sharing policies

Microkernel design (cont.) Microkernels (cont.) Microkernel design (cont.) Interprocess communication (IPC) messages header (with sender and receiver ID), data between threads: send location of data between processes: memory-to-memory copy The microkernel maintains ports where queues of messages are associated; ports also indicate which other processes can communicate to them. Ports are assigned to processes for IPC. I/O and interrupt management I/O ports address space recognition of interrupts only assignment of interrupts to certain interrupt handlers The interrupt handlers are external to the microkernel.