Multiple Kernel Level and Process Control
Overview of Processes and Threads
The discussion revolves around the management of multiple processes and their respective threads within a system, especially in a multi-threaded environment.
Key Components of Process Management
User Level Thread Structures:
Representation of threads at the user level.
Used by a threading library to manage multiple user threads for a single process.
Process Control Blocks (PCB):
Data structures that store essential information about each process.
Includes details such as the process's state, program counter, CPU registers, memory management information, and I/O status information.
Kernel Level Thread Structures:
These are managed by the operating system kernel.
Responsible for the actual scheduling and execution of threads on CPU cores.
Relationships and Dependencies
Mapping of User Level Threads to Process Control Blocks:
The threading library maintains a relationship between user level threads and the PCB of the process they belong to.
This relationship ensures that user threads operate within the correct address space associated with their process.
Kernel Level Threads and Process Address Space:
Each process must keep track of its kernel level threads that execute on its behalf.
Conversely, each kernel level thread must know the address space within which it operates.
CPU Management in Multi-Threading Systems
In systems with multiple CPUs, additional data structures are required:
CPU Data Structures: Needed to represent each CPU in the system.
Relationships Between Kernel Level Threads and CPU:
Each kernel level thread is associated with a specific CPU, known as CPU affinity.
Tracking which CPU a thread last ran on or is scheduled to run on is essential for effective scheduling.
For each CPU:
A pointer to its current thread.
Information regarding threads that typically run on that CPU.
Context Switching in Thread Management
The kernel supports multiple kernel level threads for a single user level process, enabling thread-level parallelism.
Context Switching: When switching between kernel level threads:
The kernel efficiently determines when threads belong to different processes based on their process control blocks.
Each PCB has different virtual address mappings, so switching between threads from different processes involves:
Invalidating the current address mappings.
Restoring the address mappings associated with the new thread.
This process includes saving the state of the current kernel level thread's PCB and restoring the state for the new kernel level thread being scheduled.