CPE 3106_Chapter 4

Threads, SMP, and Microkernels

Threads: Resource ownership and execution

Processes and Threads

Processes have two characteristics:

  1. Resource ownership - process includes a virtual address space to hold process image.

  2. Scheduling/execution - follows an execution path that may be interleaved with other processes.

These two characteristics are treated independently by the operating system.

The unit of dispatching is referred to as a thread or lightweight process. While the unit of resource ownership is referred to as a process or task.

Multithreading

Multithreading is the ability of an OS to support multiple, concurrent paths of execution within a single process.

  • Java run-time environment is a single process with multiple threads.

  • Multiple processes and threads are found in Windows, Solaris, and many modern versions of UNIX.

Single Thread Approaches

MS-DOS supports a single user process and a single thread. On the other hand, some UNIX support multiple user processes but only one thread per process.

Processes

There’s a virtual address space which holds the process image and with protected access to

  • Processors,

  • Other processes,

  • Files,

  • I/O resources

One or more Threads in Process

Each thread has the following:

  1. An execution state (running, ready, etc.)

  2. Saved thread context when not running

  3. An execution stack

  4. Some per-thread static storage for local variables

  5. Access to the memory and resources of its process (all threads of a process share this).

One way to view a thread is as an independent program operating within a process.

Threads vs. Processes

Benefits of Threads
  • It takes less time to create a new thread than a process.

  • It takes less time to terminate a thread than a process.

  • Switching between two threads takes less time than switching between processes.

  • Threads can communicate with each other without invoking kernel.

Thread use in a Single-User System
  • Foreground and background work

  • Asynchronous processing

  • Speed of execution

  • Modular program structure

Threads

Several actions can affect all of the threads in a process. Therefore, the OS must manage these at the process level.

Examples:

  • Suspending a process involves suspending all threads of the process

  • Termination of a process terminated all of the threads within the process.

Activities similar to Processes

Threads - they have execution states and may synchronize with one another, similar to a process.

Here are the two aspects of thread functionality:

  • States

  • Synchronization

Thread Execution States

States associated with a change in thread state:

  1. State (another thread

  2. Block - Issue: will blocking one thread block the others or all threads.

  3. Unblock

  4. Finish thread - deallocate register context and stacks.

Remote Procedure Call (RPC)

As an example, consider a program that performs two remote procedure calls (RPCs) to two different hosts in order to obtains a combined result.

  • Using Single Thread

  • Using One Thread Per Server

  • Multithreading on a Uniprocessor

Adobe PageMaker

Categories of Thread Implementation
  1. User Level Thread (ULT)

  2. Kernel Level Thread (KLT) - also called kernel-supported threads, lightweight processes

User-Level Threads

In this implementation, all thread management is done by the application. The kernel is not aware of the existence of threads.

Relationship between ULT Thread and Process States

Kernel-Level Threads

Kernel remains context information for the process and the threads. With this, no thread management is done by the application. Scheduling is done on a thread basis. Windows is an example of this approach.

Advantages:

  1. The kernel can simultaneously schedule multiple threads from the same process on multiple processors.

  2. If one thread in a process is blocked, the kernel can schedule another thread of the same process.

  3. Kernel routines themselves can be multithreaded.

Disadvantages:

  1. The transfer of protocol from one thread to another within the same process requires a mode switch to the kernel.

Combined Approaches

Thread creation can be done in user space. Bulk of scheduling and synchronization of threads can be done by the application. An example of this approach is Solaris.


Relationship Between Thread and Processes

Symmetric Multiprocessing (SMP)

Traditional View

Traditionally, the computer has been viewed as a sequential machine. A processor executed instructions one at a time in sequence and each instruction is a sequence of operations.

Two popular approaches providing parallelism are:

  • Symmetric Multiprocessors (SMPs)

  • Clusters (ch 16)

Categories of Computer Systems

  1. Single Instruction Single Data (SISD) stream - single processor executed a single instruction stream to operate on data stored in a single memory.

  2. Single Instruction Multiple Data (SIMD) stream - each instruction is executed on a different set of data by the different processors.

  3. Multiple Instruction Single Data (MISD) stream - a sequence of data is transmitted to a set of processors, each of the processors execute a different instruction sequence.

  4. Multiple Instruction Multiple Data (MIMD) stream - a set of processors execute different instruction sequences on different data sets.

Parallel Processor Architectures

Symmetric Multiprocessing

Kernel can execute on any processor, thereby allowing portions of the kernel to execute in parallel. Typically, each processor does self-scheduling from the pool of available process or threads.

Typical SMP Organization

Multiprocessor OS Design Considerations

The key design issues include:

  1. Simultaneous concurrent processes or threads

  2. Scheduling

  3. Synchronization

  4. Memory Management

  5. Reliability and Fault Tolerance

Microkernel

A microkernel is a small OS core that provides the foundation for modular extensions. The big question is, how small must a kernel be to qualify as a microkernel; Must drivers be in user space?

In theory, this approach provides a high degree of flexibility and modularity.

Kernel Architecture

Microkernel Design: Memory Management

Low-level memory management - this requires mapping each virtual page to a physical page frame. Most memory management tasks occur in user space.

Microkernel Design: Interprocess Communication

Communication between processes or threads in a microkernel OS is via messages. A message includes:

  1. A header that identifies the sending and receiving process and

  2. A body that contains data, a pointer to a block of data, or some control information about the process.

Microkernel Design: I/O and Interrupt management

Within a microkernel, it is possible to handle hardware interrupts as messages and to include I/O ports in address spaces. A particular user-level process is assigned to the interrupt and the kernel maintains the mapping.

Benefits of a Microkernel Organization

  1. Uniform interfaces on requests made by a process

  2. Extensibility

  3. Flexibility

  4. Portability

  5. Reliability

  6. Distributed system support

  7. Object oriented operating systems