650 likes | 968 Views
Threads, SMP, and Microkernels. Chapter 4. Focus and Subtopics. Focus: More advanced concepts related to process management : Resource ownership vs execution Processes and threads Symmetric Multiprocessing Microkernels Discussions on threads for contemporary OS Windows Solaris Linux.
E N D
Threads, SMP, and Microkernels Chapter 4
Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs execution • Processes and threads • Symmetric Multiprocessing • Microkernels • Discussions on threads for contemporary OS • Windows • Solaris • Linux
Characteristics that embody a Process • Resource ownership - process includes a virtual address space to hold the process image. Process are allocated resources from time to time. • Scheduling/execution- Process execution follows an execution path that may be interleaved with other processes These two characteristics are treated independently by the operating system
Process • Dispatching is referred to as a thread or lightweight process • Resource of ownership is referred to as a process or task
Multithreading • The ability of an OS to support multiple threads of execution • There are 4 different approaches to usage of threads. • One Process, one thread of execution (thread as an entity is not recognize – thread of execution is within process) • One Process, multiple threads • Multiple Process, one thread per process • Multiple Process, multiple threads.
Multithreading • Most operating systems support multiple threads of execution within a single process: • MS-DOS only supports a single thread • Java runtime environment is a one process environment which supports multiple threads. • UNIX supports multiple user processes but only supports one thread per process • Windows, Solaris, Linux, Mach, and OS/2 support multiple threads per process
Java Virtual Environment MSDOS UNIX Windows, Solaris, Mach, OS/2
A Process within multithreaded environment • Have a virtual address space which holds the process image • Protected access to • Processors • other processes (interprocess communication) • Files • I/O resources (devices and channels)
Threads - within a process : • An execution state (running, ready, etc.) • A saved thread context when not running(can view it as an independent program counter within a process) • Has an execution stack • Some per-thread static storage for local variables • Access to the memory and resources of its process, shared by all threads of a process.
Single Thread vs multiple threads One process, Multiple threads • Thread keeps different PCs because they are running different parts of the code in the process No thread Code/Text Data Thread1 Thread2 Thread3 Code/Text and Data (share by all threads) • All threads share state and resources of the process
Benefits of Threads • Takes less time to create a new thread than a process • Less time to terminate a thread than a process • Less time to switch between two threads within the same process • Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel
Example benefits of usage of threads • An application have multiple functionality: • Use threads for each functionality – better than a single process with many functionality • A file server: • Each new file request means a thread is created for file management for each request • Many threads can be created and destroyed. • In multi CPU machine, a CPU can handle one thread. • Resources are shared
Example Uses of Threads In a Single-User Multiprocessing System • Foreground and background work: • Each thread perform a specific function • Asynchronous processing: • Each asynchronous element implemented as thread – backup • Speed of execution: • Simultaneous thread execution • Modular program structure: • Easier to design
Actions that effect all threads • Suspending a process involves suspending all threads of the process since all threads share the same address space • Termination of a process, terminates all threads within the process
Thread Functionality • Thread States: • Threads have execution states like process • Thread Synchronization • Threads may need to synchronize with one another
Thread States • Key States for thread • Running • Ready • Blocked • What about Suspend? • Does not make sense. This is a process concept. • If a process is swapped out, all its threads are also swapped out. • Basic thread operations associated with a change in thread state • Spawn • A spawned process with threads also spawn a process with threads • Block • A thread that is waiting for an event is blocked, allowing OS to pick up another thread to run. • Unblock • When a thread that is waiting for an event had the event occurs, it is unblocked and moved to ready queue. • Finish • When a thread completes, OS deallocate its register context and stacks
Remote Procedure Call Using Process (Single Thread of execution)
Thread Synchronization • Threads share same address space (Code, data etc) • If a thread alter something in the address space, it will effect other threads. • Thus the need to synchronize activities of various threads • Issues in process synchronization is the same in thread synchronization
Example use of thread inAdobe PageMaker • Writing, design, production for desktop publishing • Thread structure for Adobe Pagemaker in OS/2 operating System • Three active threads: • Event-handling • Screen-redraw • Service • Each thread perform certain functions • For synchronization between threads, the software use message passing.
Threads Implementation • User Level threads (ULT) • Kernel-level threads (KLT) or kernel supported threads or lightweight processes
User-Level Threads • All thread management is done by the application • The kernel is not aware of the existence of threads • Application can use thread library to • Create thread • Destroy thread • Message passing between thread • Save/restore thread context etc. Process (a) Pure User-level
User-Level Threads • All the above takes place within the process, within user address space. As far as the kernel is concerned, it is scheduling a process . • An application (a process) can start with a single thread, at any time another thread can be spawned using the utility in the thread library. Thread library is responsible to create approriate thread data structure for the new thread, pass control to ready thread in the process.
Process B Blocked Thread 2 percieved as running Process B Running Thread 2 Running Process B Running Again Thread 1 runningThread 2 blocked Process B Ready Thread 2 percieved as running
Kernel-Level Threads • Windows is an example of this approach • Kernel maintains context information for the process and the threads • In this case, thread is managed by the OS kernel. There is no kernel management code in the application itself. • Scheduling is done on a thread basis ie: kernel schedule thread as well as process. Process
User Level thread vs Kernel Level Thread : Advantages and disadvantages
Comparing ULT, KLT and Processes Comparison in VAX Running UNIX-Like OS Time to create, schedule, execute and complete in microseconds
Combined Approaches • Example is Solaris • thread creation is done in user space • scheduling and synchronization in user space • multiple ULT combined into a number of KLT • multiple threads within the same application can run on multiple processors. • a thread that make a system call can be blocked, but the whole process cannot be blocked.
Other Thread Implementations • Multiple process Multiple threads : • multiple processes running and each process have many threads. The threads can move from one process to another process. • There is one OS using this implementation, called TRIX. TRIX uses concepts of domain and threads. • Domain consists of address space and ports which messages can be sent and received between domain. • A thread is as the normal definition. Multiple threads can be executing in a single domain. But a thread from a domain can also execute in another domain. Thus the multiple domain multiple thread. • Kernel manages different address space related to the domain independently. There is no overhead in process creation when moving thread from one domain to another. • Multiple process Single threads : • Here a thread can move among processes addresses spaces. An OS called clouds is using this method. The kernel of clouds is called Ra. The processes can also be on different machines.
Categories of Computer Systems • Single Instruction Single Data (SISD) stream • Single processor executes a single instruction stream to operate on data stored in a single memory • Single Instruction Multiple Data (SIMD) stream • Each instruction is executed on a different set of data by the different processors
Categories of Computer Systems • Multiple Instruction Single Data (MISD) stream • A sequence of data is transmitted to a set of processors, each of which executes a different instruction sequence. Never implemented • Multiple Instruction Multiple Data (MIMD) • A set of processors simultaneously execute different instruction sequences on different data sets
Symmetric Multiprocessing • Kernel can execute on any processor • Typically each processor does self-scheduling form the pool of available process or threads
Multiprocessor Operating System Design Considerations • Simultaneous concurrent processes or threads • Scheduling • Synchronization • Memory management • Reliability and fault tolerance
Microkernels • Small operating system core • Contains only essential core operating systems functions • Many services traditionally included in the operating system are now external subsystems • Device drivers • File systems • Virtual memory manager • Windowing system • Security services
Benefits of a Microkernel Organization • Uniform interface on request made by a process • Don’t distinguish between kernel-level and user-level services • All services are provided by means of message passing • Extensibility • Allows the addition of new services • Flexibility • New features added • Existing features can be subtracted
Benefits of a Microkernel Organization • Portability • Changes needed to port the system to a new processor is changed in the microkernel - not in the other services • Reliability • Modular design • Small microkernel can be rigorously tested
Benefits of Microkernel Organization • Distributed system support • Message are sent without knowing what the target machine is • Object-oriented operating system • Components are objects with clearly defined interfaces that can be interconnected to form software
Microkernel Design – Functions to include in Kernel • Low-level memory management • Interprocess communication • I/O and interrupt management
Microkernel Design - Function • Low-level memory management • Mapping each virtual page to a physical page frame
Microkernel Design • Interprocess communication • Using Message –> header + body • Port –> queue of messages • I/O and interrupt management • Handle hardware interrupt using messages • Microkernel recognizes interrupt, generate messages for user-level processes to cater foir the interrupt.
How OS Processes are supported • How processes are named • Are threads being used • How are process represented • How are process protected • How IPC and synchronization are done • How processes are related to each other
Microsoft Windows Processes • Implemented as objects • An executable process may contain one or more threads • Both processes and thread objects have built-in synchronization capabilities