Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.

Similar presentations


Presentation on theme: "1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs."— Presentation transcript:

1 1 Threads, SMP, and Microkernels Chapter 4

2 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 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 4 Process Dispatching is referred to as a thread or lightweight process Resource of ownership is referred to as a process or task

5 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 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 7 MSDOS Java Virtual Environment UNIX Windows, Solaris, Mach, OS/2

8 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 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 10 Code/Text Data Code/Text and Data (share by all threads) Thread1Thread2Thread3 Single Thread vs multiple threads No thread One process, Multiple threads Thread keeps different PCs because they are running different parts of the code in the process All threads share state and resources of the process

11 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 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 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 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 15 Thread Functionality Thread States:  Threads have execution states like process Thread Synchronization  Threads may need to synchronize with one another

16 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 17 Remote Procedure Call Using Process (Single Thread of execution)

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

19 19 Benefit of threads: Multithreading

20 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 21 Example use of thread in Adobe 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 22 Threads Implementation User Level threads (ULT) Kernel-level threads (KLT) or kernel supported threads or lightweight processes

23 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 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 25 User-Level Threads

26 26 Process B Running Thread 2 Running Process B Blocked Thread 2 percieved as running Process B Ready Thread 2 percieved as running Process B Running Again Thread 1 running Thread 2 blocked

27 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 28 Kernel-Level Threads

29 29 User Level thread vs Kernel Level Thread : Advantages and disadvantages User Level ThreadKernel Level Thread Advantages  thread switching does not require switching to kernel mode.  scheduling is based on application  program of this type can run on any OS.  kernel can schedule multiple thread from the same process on different processor.  if a thread is blocked, kernel can schedule another thread of the same process.  kernel routine itself can be multithreaded. Disdvantages  a system call cause all thread in the process to be blocked.  the whole process is assigned to one processor, thus threads executes alternately.  switching thread require mode switch to kernel mode. This means it is slower due to overheads..

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

31 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 32 Relationship Between Threads and Processes

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

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

38 38

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

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

41 41

42 42 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

43 43 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

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

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

46 46 Microkernel Design - Function 1. Low-level memory management  Mapping each virtual page to a physical page frame

47 47 Microkernel Design 2. Interprocess communication Using Message –> header + body Port –> queue of messages 3. I/O and interrupt management Handle hardware interrupt using messages Microkernel recognizes interrupt, generate messages for user-level processes to cater foir the interrupt.

48 48 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

49 49 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

50 50

51 51 Windows Process Object

52 52 Windows Thread Object

53 53 Windows 2000 Thread States Ready Standby Running Waiting Transition Terminated

54 54

55 55 Solaris Process includes the user’s address space, stack, and process control block User-level threads Lightweight processes (LWP) Kernel threads

56 56

57 57

58 58 Solaris Lightweight Data Structure Identifier Priority Signal mask Saved values of user-level registers Kernel stack Resource usage and profiling data Pointer to the corresponding kernel thread Pointer to the process structure

59 59

60 60 Linux Task Data Structure State Scheduling information Identifiers Interprocess communication Links Times and timers File system Address space Processor-specific context

61 61 Linux States of a Process Running Interruptable Uninterruptable Stopped Zombie

62 62


Download ppt "1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs."

Similar presentations


Ads by Google