1 / 62

Threads, SMP, and Microkernels

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.

london
Download Presentation

Threads, SMP, and Microkernels

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Threads, SMP, and Microkernels Chapter 4

  2. 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

  3. 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

  4. Process • Dispatching is referred to as a thread or lightweight process • Resource of ownership is referred to as a process or task

  5. 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.

  6. 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

  7. Java Virtual Environment MSDOS UNIX Windows, Solaris, Mach, OS/2

  8. 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)

  9. 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.

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. Thread Functionality • Thread States: • Threads have execution states like process • Thread Synchronization • Threads may need to synchronize with one another

  16. 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

  17. Remote Procedure Call Using Process (Single Thread of execution)

  18. Benefit of threads:Remote Procedure Call Using 2 Threads

  19. Benefit of threads:Multithreading

  20. 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

  21. 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.

  22. Threads Implementation • User Level threads (ULT) • Kernel-level threads (KLT) or kernel supported threads or lightweight processes

  23. 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

  24. 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.

  25. User-Level Threads

  26. 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

  27. 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

  28. Kernel-Level Threads

  29. User Level thread vs Kernel Level Thread : Advantages and disadvantages

  30. Comparing ULT, KLT and Processes Comparison in VAX Running UNIX-Like OS Time to create, schedule, execute and complete in microseconds

  31. 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.

  32. Relationship Between Threads and Processes

  33. 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.

  34. 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

  35. 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

  36. Symmetric Multiprocessing • Kernel can execute on any processor • Typically each processor does self-scheduling form the pool of available process or threads

  37. Multiprocessor Operating System Design Considerations • Simultaneous concurrent processes or threads • Scheduling • Synchronization • Memory management • Reliability and fault tolerance

  38. 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

  39. 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

  40. 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

  41. 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

  42. Microkernel Design – Functions to include in Kernel • Low-level memory management • Interprocess communication • I/O and interrupt management

  43. Microkernel Design - Function • Low-level memory management • Mapping each virtual page to a physical page frame

  44. 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.

  45. 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

  46. 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

More Related