Threads, SMP, and Microkernels
Threads, SMP, and Microkernels
Chapter 4
Contents
?Processes and threads ?Symmetric multiprocessing ?Microkernels ?Window 2000 thread and SMP management ?Solaris thread and SMP management ?Linux process and thread management
Processes of yesterday
?Unit of resource ownership
?process is allocated a virtual address space to hold the process image
?Unit of dispatching
?scheduled and dispatched by the OS ?execution may be interleaved with other processes
Processes of today
?Process or task
?unit of resource ownership ?virtual address space, main memory, I/O devices, and files
Multithreading
?Refers to the ability of an OS to support multiple threads of execution within a single process ?MS-DOS supports a single user process and a single thread ?UNIX supports multiple user processes but only supports one thread per process ?Windows 2000, Solaris, Linux, Mach, and OS/2 support multiple threads
Threads
?Within a process, there may be one or more threads, each with the followings
?thread execution state(running, ready,...) ?saved thread context
?program counter, stack, register set, child threads, memory for local variables
Benefits of Threads
?Takes less time to create a new thread than a process
?no need to allocate a virtual address space
?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
Threads
?Actions that affect all of the threads in a process
?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 that process
Thread States
?Operations associated with a change in thread state
?Spawn
?a thread within a process may spawn another thread within the same process
Implementation of Threads
?User-level threads(ULTs) ?Kernel-level threads(KLTs)
?also referred to as kernel-supported threads or lightweight processes
?Combined approaches
User-Level Threads
?All thread management is done by the application
?kernel is not aware of the existence of threads
?Advantages of ULTs
?thread switching does not require kernel mode privileges ?scheduling is application specific ?ULTs can run on any OS
Figure 4.7 Examples of the relationship between User-level thread states and process states
User-Level Threads
?Disadvantages of ULTs
?when a thread is blocked, all of the threads within that process are blocked ?cannot take advantage of multiprocessing
?kernel assigns one process to only one processor at a time
Kernel-Level Threads
?Windows 2000 and OS/2 are examples of this approach ?Kernel maintains the context information for the process and the threads ?Scheduling by the kernel is done on a thread basis
?Multiple ULTs from a single application are mapped onto some(smaller or equal) number of KLTs
M:1
M:M
TRIX
Symmetric Multiprocessing
?Kernel can execute on any processor ?Typically each processor does selfscheduling from the pool of available processes or threads
?Scheduling
?may be performed by any processor
Microkernel
?Small operating system core ?Contains only essential 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
?Extensibility
?allows the addition of new services
?Flexibility
?not only can new features be added to OS, but existing features can be subtracted
?Reliability
?modular design ?small microkernel can be rigorously tested
Microkernel Design
?Functions that must be included
?Low-level memory management
?mapping each virtual page to a physical page frame
?Inter-process communication
?message is the basic form ?message passing between separate processes involves memory-to-memory copying
?current research on thread-based IPC and memory sharing scheme
?Object table
?have handles to other objects known to this process ?one handle exists for each thread contained in this object
Multithreading
?Threads in different processes may execute concurrently ?Multiple threads within the same process may be allocated to separate processors and execute concurrently ?Threads in different processes can exchange information through shared memory that has been set up between the two processes
Solaris
?Thread-related concepts used by Solaris
?Process
?includes the users address space, stack, and process control block
?User-level threads
?implemented through a threads library
?Lightweight processes
?can be viewed as a mapping between ULTs and kernel threads
?Kernel threads
?Suspension
?go into the stopped state
?Preemption
?go into the runnable state
?Yielding
?yield to another runnable thread
Linux Process
?State ?Scheduling information ?Identifiers ?Interprocess communication : SVR4 is supported ?Links ?Times and timers ?File system ?Virtual memory ?Processor-specific context
?Uninterruptable
?another blocked state, but will not accept any signals
?Stopped
?halted, and can only resume by positive action from another process
?Zombie