0% found this document useful (0 votes)
12 views32 pages

Threads, SMP, and Microkernels Explained

The document discusses operating systems with a focus on threads, symmetric multiprocessing (SMP), and microkernels. It outlines the characteristics of processes and threads, the benefits of multithreading, and compares user-level and kernel-level threads. Additionally, it provides case studies of various operating systems, including Windows, Solaris, and Linux, highlighting their approaches to process and thread management.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views32 pages

Threads, SMP, and Microkernels Explained

The document discusses operating systems with a focus on threads, symmetric multiprocessing (SMP), and microkernels. It outlines the characteristics of processes and threads, the benefits of multithreading, and compares user-level and kernel-level threads. Additionally, it provides case studies of various operating systems, including Windows, Solaris, and Linux, highlighting their approaches to process and thread management.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/18/2024

Operating Systems

“Threads, SMP, and Microkernels”

Roadmap
• Threads: Resource ownership and execution
• Symmetric multiprocessing (SMP).
• Microkernel
• Case Studies of threads and SMP:
• Windows
• Solaris
• Linux

1
3/18/2024

Processes and Threads


• Processes have two characteristics:
• 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

Processes and Threads


• The dispatching unit is referred to as a thread or lightweight process
• The entity that owns a resource is referred to as a process or task
• One process / task can have one or more threads

2
3/18/2024

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

Single Thread Approaches


• MS-DOS supports a single user
process and a single thread.
• Some UNIX, support multiple user
processes but only support one
thread per process

3
3/18/2024

Multithreading
• 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
the main topic

Processes
• A virtual address space which holds the process image
• Protected access to
• Processors,
• Other processes,
• Files,
• I/O resources

4
3/18/2024

One or More Threads in Process


• Each thread has
• An execution state (running, ready, etc.)
• Saved thread context when not running
• 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)

One view…

• One way to view a thread is as an independent program counter


operating within a process.

5
3/18/2024

Threads vs. processes

Benefits of Threads
• Takes less time to create a new thread than a process
• Less time to terminate a thread than a process
• Switching between two threads takes less time that switching
processes
• Threads can communicate with each other
• without invoking the kernel

6
3/18/2024

Thread use in a Single-User System


• Foreground and background work
• Asynchronous processing
• Speed of execution
• Modular program structure

Threads
• Several actions that affect all of the threads in a process
• The OS must manage these at the process level.
• Examples:
• Suspending a process involves suspending all threads of the process
• Termination of a process, terminates all threads within the process

7
3/18/2024

Activities similar to Processes


• Threads have execution states and may synchronize with one another.
• Similar to processes
• We look at these two aspects of thread functionality in turn.
• States
• Synchronisation

Thread Execution States


• States associated with a change in thread state
• Spawn (another thread)
• Block
• Issue: will blocking a thread block other, or all threads
• Unblock
• Finish (thread)
• Deallocate register context and stacks

8
3/18/2024

Example: Remote Procedure Call


• Consider:
• A program that performs two remote procedure calls (RPCs)
• to two different hosts
• to obtain a combined result.

RPC Using Single Thread

9
3/18/2024

RPC Using One Thread per Server

Multithreading on a Uniprocessor

10
3/18/2024

Categories of Thread Implementation


• User Level Thread (ULT)
• thread that are managed entirely by user-level code
• Not requiring any support from the operating system kernel.
• Kernel level Thread (KLT) also called:
• kernel-supported threads
• lightweight processes.

User-Level Threads
• All thread management is done
by the application
• The kernel is not aware of the
existence of threads

11
3/18/2024

Kernel-Level Threads
• Kernel maintains context information
for the process and the threads
• No thread management done by
application
• Scheduling is done on a thread basis
• Windows is an example of this approach

Advantages of KLT
• The kernel can simultaneously schedule multiple threads from the
same process on multiple processors.
• If one thread in a process is blocked, the kernel can schedule another
thread of the same process.
• Kernel routines themselves can be multithreaded.

12
3/18/2024

Disadvantage of KLT
• The transfer of control from one thread to another within the same
process requires a mode switch to the kernel

Comparison ULT and KLT


Criteria User-Level Threads (ULTs) Kernel-Level Threads (KLTs)

Managed entirely by user-level code, without kernel


Management Managed by the operating system kernel
support
Scheduled by a user-level thread library or application, Scheduled by the operating system kernel, which may
Scheduling
without kernel intervention provide advanced scheduling algorithms and policies
Context switching occurs entirely in user space,
Context switching requires a system call or trap into
Context Switching without requiring a system call or trap into kernel
kernel mode, which can incur overhead
mode
ULTs share the same process address space and KLTs have their own kernel-level data structures, which
Resources
resources as the parent process can result in higher overhead and memory usage
ULTs are limited to a single processor core and cannot KLTs can be assigned to different processor cores and can
Scalability
take full advantage of multicore systems take full advantage of multicore systems
ULTs must use user-level synchronization mechanisms, KLTs can use both user-level and kernel-level
Synchronization which can be more efficient but may be subject to synchronization mechanisms, providing more flexibility
priority inversion and other issues and better enforcement of policies
ULTs are highly portable across different operating KLTs may be less portable, as different operating systems
Portability systems, as long as a compatible user-level thread may have different thread APIs and scheduling
library is available mechanisms

13
3/18/2024

Combined Approaches
• Thread creation done in the user
space
• Bulk of scheduling and
synchronization of threads by the
application

• Example is Solaris

Relationship Between Thread and Processes

14
3/18/2024

Roadmap
• Threads: Resource ownership and execution
• Symmetric multiprocessing (SMP).
• Microkernel
• Case Studies of threads and SMP:
• Windows
• Solaris
• Linux

Traditional View
• Traditionally, the computer has been viewed as a sequential machine.
• A processor executes instructions one at a time in sequence
• Each instruction is a sequence of operations
• Two popular approaches to providing parallelism
• Symmetric Multi Processors (SMPs)
• Clusters (ch 16)

15
3/18/2024

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

Categories of Computer Systems


• Multiple Instruction Single Data (MISD) stream
• A sequence of data is transmitted to a set of processors, each of
execute a different instruction sequence
• Multiple Instruction Multiple Data (MIMD)
• A set of processors simultaneously execute different instruction sequences on
different data sets

16
3/18/2024

Parallel Processor Architectures

Multiprocessor

Multicomputer
/ cluster

Symmetric Multiprocessing
• Kernel can execute on any processor
• Allowing portions of the kernel to execute in parallel
• Typically, each processor does self-scheduling from the pool of
available process or threads

17
3/18/2024

Typical SMP Organization

symmetricity

Multiprocessor OS Design Considerations


• The key design issues include
• Simultaneous concurrent processes or threads
• Scheduling
• Synchronization
• Memory Management
• Reliability and Fault Tolerance

18
3/18/2024

Roadmap
• Threads: Resource ownership and execution
• Symmetric multiprocessing (SMP).
• Microkernel
• Case Studies of threads and SMP:
• Windows
• Solaris
• Linux

Microkernel
• A microkernel is a small OS core that provides the foundation for
modular extensions.
• 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.

19
3/18/2024

Kernel Architecture

Microkernel Design: Memory Management


• Low-level memory management - Mapping each virtual page to a
physical page frame
• Most memory management tasks occur in user space

20
3/18/2024

Microkernel Design: Interprocess Communication

• Communication between processes or threads in a microkernel OS is


via messages.
• A message includes:
• A header that identifies the sending and receiving process and
• A body that contains direct data, a pointer to a block of data, or some control
information about the process.

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

21
3/18/2024

Benefits of a Microkernel Organization


• Uniform interfaces on requests made by a process.
• Extensibility
• Flexibility
• Portability
• Reliability
• Distributed System Support
• Object Oriented Operating Systems

Comparison Microkernel vs Monolitic kernel


Criteria Microkernel Monolithic Kernel
Minimalistic kernel that provides basic Entire kernel including device drivers, system
Architecture services, with additional services implemented calls, and other services are executed in
as user-space processes kernel space
More secure due to smaller attack surface, as
Exposes entire kernel to potential security
Security most operating system services are run in user
vulnerabilities
space
More flexible and easier to customize and
Requires modifications to kernel code to add
Flexibility maintain as new services can be added
new functionality
without modifying the kernel itself
Better performance due to all system
Generally slower due to increased reliance on
services being executed in kernel space,
Performance interprocess communication and message
avoiding the overhead of interprocess
passing
communication
Easier to debug and maintain due to modular Debugging and maintenance can be more
Debugging and
design, where different services run as difficult due to all services running in the
Maintenance
independent processes same kernel space

22
3/18/2024

Roadmap
• Threads: Resource ownership and execution
• Symmetric multiprocessing (SMP).
• Microkernel
• Case Studies of threads and SMP:
• Windows
• Solaris
• Linux

Which OS uses microkernel / monolithic


kernel
• Windows:
• Windows NT and later versions use a hybrid kernel that combines elements of a microkernel
and a monolithic kernel.
• Earlier versions of Windows (such as Windows 95, 98, and ME) use a monolithic kernel.
• Linux:
• a monolithic kernel, but it can also support loadable kernel modules that can be dynamically
loaded and unloaded at runtime.
• macOS:
• a hybrid kernel that combines elements of a microkernel and a monolithic kernel.
• iOS:
• a hybrid kernel that combines elements of a microkernel and a monolithic kernel.
• Android:
• a monolithic kernel, but it also includes a user-level component called the Binder IPC
mechanism that provides some microkernel-like functionality.

23
3/18/2024

Which OS uses microkernel / monolithic


kernel
• some research and niche operating systems that use microkernels,
such as
• QNX, Minix, and L4 microkernel.
• Minix can be downloaded from the official website:
[Link]
• select the version of Minix you want to download (e.g., stable or
development) and the architecture (e.g., x86, ARM, or PowerPC), and the
format (e.g., ISO or USB image).
• Install Minix on virtual machine (VM) such as VirtualBox and VMware

Different Approaches to Processes


• Differences between different OS’s support of processes include
• How processes are named
• Whether threads are provided
• How processes are represented
• How process resources are protected
• What mechanisms are used for inter-process communication and
synchronization
• How processes are related to each other

24
3/18/2024

Windows Processes
• Processes and services provided by the Windows Kernel are relatively
simple and general purpose
• Implemented as objects
• An executable process may contain one or more threads
• Both processes and thread objects have built-in synchronization capabilities

Relationship between Process and Resources

25
3/18/2024

Windows Process Object

Windows Thread Object

26
3/18/2024

Thread States

Windows SMP Support


• Threads can run on any processor
• But an application can restrict affinity / natural liking
• Soft Affinity
• The dispatcher tries to assign a ready thread to the same processor it last ran
on.
• This helps reuse data still in that processor’s memory caches from the
previous execution of the thread.
• Hard Affinity
• An application restricts threads to certain processor

27
3/18/2024

Solaris
• Solaris implements multilevel thread support designed to provide
flexibility in exploiting processor resources.
• Processes include the user’s address space, stack, and process control
block

Solaris Process
• Solaris makes use of four separate thread-related concepts:
• Process: includes the user’s address space, stack, and process control block.
• User-level threads: a user-created unit of execution within a process.
• Lightweight processes: a mapping between ULTs and kernel threads.
• Kernel threads

28
3/18/2024

Relationship between Processes and Threads

Traditional Unix vs Solaris

Solaris replaces the


processor state
block with a list of
LWPs

29
3/18/2024

LWP Data Structure


• An LWP identifier
• The priority of this LWP
• A signal mask
• Saved values of user-level registers
• The kernel stack for this LWP
• Resource usage and profiling data
• Pointer to the corresponding kernel thread
• Pointer to the process structure

Solaris Thread States

30
3/18/2024

Linux Tasks
• A process, or task, in Linux is represented by a task_struct data
structure
• This contains a number of categories including:
• State
• Scheduling information
• Identifiers
• Interprocess communication
• And others

Linux Process/Thread Model

31
3/18/2024

Thank You

32

You might also like