Process management, Threads, Process Scheduling--Operating Systems
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two...
-
date post
19-Dec-2015 -
Category
Documents
-
view
217 -
download
0
Transcript of 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two...
![Page 1: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/1.jpg)
1
Threads, SMP, and Microkernels
Chapter 4
![Page 2: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/2.jpg)
2
Process: Some Info.• Motivation for threads!• Two fundamental aspects of a “process”:
• Resource ownership• Scheduling or execution
• Resource ownership - process includes a virtual address space to hold the process image
• Scheduling/execution- follows an execution path that may be interleaved with other processes
• These two characteristics are treated independently by the operating system
![Page 3: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/3.jpg)
3
Process• Dispatching is referred to as a thread or
lightweight process• Resource of ownership is referred to as a
process or task• So far, we have considered processes that had
just one thread: • A “process” or a “process with one thread” are kind of
similar!
![Page 4: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/4.jpg)
4
Multithreading• An attempt to define multithreading:
• Operating system supports multiple threads of execution within a single process
• MS-DOS supports a single thread• UNIX supports multiple user processes but only
supports one thread per process• Windows, Solaris, Linux, Mach, and OS/2
support multiple threads
![Page 5: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/5.jpg)
5
![Page 6: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/6.jpg)
6
What exactly is a Process now?
• Have a virtual address space which holds the process image
• Protected access to processors, other processes, files, and I/O resources
![Page 7: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/7.jpg)
7
What exactly is a Thread now?• An execution state (running, ready, etc.)• Saved thread context when not running• Has an execution stack• Some per-thread static storage for local
variables• Access to the memory and resources of its
process• All threads of a process share this
![Page 8: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/8.jpg)
8
![Page 9: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/9.jpg)
9
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
![Page 10: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/10.jpg)
10
Uses of Threads in a Single-User Multiprocessing System
• Foreground to background work:• In GUI-based applications, one thread can make
display and the other can process input
• Asynchronous processing: • Daemons or services in OSes
• Speed of execution: • Make even better use of processor, especially in
multiprocessor systems
• Modular program structure
![Page 11: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/11.jpg)
11
Threads: What happens to state models?
• 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
![Page 12: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/12.jpg)
12
Thread States• States associated with a change in thread state
• Spawn• Spawn another thread
• Block• Unblock• Finish
• Deallocate register context and stacks
![Page 13: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/13.jpg)
13
Remote Procedure Call Using Single Thread
![Page 14: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/14.jpg)
14
Remote Procedure Call Using Threads
![Page 15: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/15.jpg)
15
Multithreading
![Page 16: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/16.jpg)
16
TOP Command
![Page 17: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/17.jpg)
17
PSTREE Command
![Page 18: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/18.jpg)
18
/proc directory on Linux
![Page 19: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/19.jpg)
19
Details of Process 2114
![Page 20: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/20.jpg)
20
Adobe PageMaker
![Page 21: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/21.jpg)
21
Categories of Thread Implementation
• User-level threads• Kernel-level threads
![Page 22: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/22.jpg)
22
![Page 23: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/23.jpg)
23
User-Level Threads• All thread management is done by the
application• The kernel is not aware of the existence of
threads
![Page 24: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/24.jpg)
24
User-Level Threads
![Page 25: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/25.jpg)
25
![Page 26: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/26.jpg)
26
Kernel-Level Threads• Windows is an example of this approach• Kernel maintains context information for the
process and the threads• Scheduling is done on a thread basis
![Page 27: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/27.jpg)
27
Kernel-Level Threads
![Page 28: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/28.jpg)
28
VAX Running UNIX-Like Operating System
![Page 29: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/29.jpg)
29
Combined Approaches• Example is Solaris• Thread creation done in the user space• Bulk of scheduling and synchronization of
threads within application
![Page 30: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/30.jpg)
30
Combined Approaches
![Page 31: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/31.jpg)
31
Relationship Between Threads and Processes
![Page 32: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/32.jpg)
32
Flynn’s Taxonomy• There is no authoritative classification of parallel computers! • Flynn’s taxonomy is one such classification based on number of
instruction and data stream processed by a parallel computer: • Single Instruction Single Data (SISD)• Multiple Instruction Single Data (MISD)• Single Instruction Multiple Data (SIMD)• Multiple Instruction Multiple Data (MIMD)
• Almost all modern computers fall in this category
![Page 33: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/33.jpg)
33
Flynn’s Taxonomy• Extensions to Flynn’s taxonomy:
• Single Program Multiple Data (SPMD)—a programming model
• This classification is largely outdated!
![Page 34: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/34.jpg)
34
![Page 35: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/35.jpg)
35
Symmetric Multi-Processors (SMP)• A SMP is a parallel processing system with a
shared-everything approach:• The term signifies that each processor shares the
main memory and possibly the cache
• Typically a SMP can have 2 to 256 processors• Examples include AMD Athlon, AMD Opteron
200 and 2000 series, Intel XEON etc
![Page 36: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/36.jpg)
36
Shared Memory• All processors have access to shared memory:
• Notion of “Global Address Space”
![Page 37: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/37.jpg)
37
![Page 38: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/38.jpg)
38
Multiprocessor Operating System Design Considerations
• Simultaneous concurrent processes or threads: • Executing same kernel code should not result in
erroneous behavior
• Scheduling: • Opportunities exist to execute multiple threads of the
same process
• Synchronization• Memory management• Reliability and fault tolerance
![Page 39: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/39.jpg)
39
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
![Page 40: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/40.jpg)
40
![Page 41: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/41.jpg)
41
Benefits of a Microkernel Organization
• Uniform interface on request made by a process• Extensibility• Flexibility• Portability• Reliability• Distributed System Support• Object-oriented Operating System
![Page 42: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/42.jpg)
42
Microkernel Design• Low-level memory management
• Mapping each virtual page to a physical page frame
![Page 43: 1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d365503460f94a0ea9e/html5/thumbnails/43.jpg)
43
Microkernel Design• Interprocess communication• I/O and interrupt management