0
4.6kviews
Static and Dynamic area of context
1 Answer
0
46views

The context of a process made up of three areas are given below:

  • A user-level context that has contents of its (user) address space.
  • A register context that has contents of hardware registers.
  • A system context that has contents of Kernel data structures that related to the process

The User Level Context

User level context consists of the process text, data, user stack and shared memory that is in the virtual address space of the process. The part which resides on swap space is also part of the user level context.

The Register Context

The register context consists of the following components:

  • Program counter stores the address of the next instruction to be executed. It is an address in the kernel or in user address space.
  • The processor status register (PS) denotes hardware status related to the process. It has sub-fields which specify if last instruction overflowed, or resulted in 0, a positive or negative value, etc. It also specifies the current processor execution level and current and most recent modes of execution (such as the kernel, user).
  • The stack pointer points to the current address of the next entry in the kernel or user stack. If it will point to the next free entry or last used entry is dependent on the machine architecture. The direction of the growth of stack (toward numerically higher or lower addresses) also depend on machine architecture.
  • The general purpose registers contain data generated by the process during its execution.

The System Context

The system level context has two parts a "static part" and a "dynamic part". A process has one static part throughout its lifetime. But it can have a variable number of dynamic parts.

The static part consists of the following parts:

  • The process table entry
  • The u-area
  • P-region entries, region tables, and page tables.

The dynamic part consists of the following components:

  • The kernel stack stores the stack frames the kernel functions. Even if all processes share the kernel text and data, kernel stack requires a different for all processes as every process might be in a different state depending on the system calls it executes. The pointer to the kernel stack is usually stored in the u-area but it differs according to system implementations. The kernel stack is empty when the process executes in user mode
  • The dynamic part of the system level context consists in the form of layers, which looks as a last-in-first-out stack. Each system-level context layer contains information necessary to recover the previous layer, including the register context of the previous layer.

The kernel pushes a context layer at the time when an interrupt occurs, when a process makes a system call, or when a process does a context switch. It pops a context layer when it returns from an interrupt handler, returns from a system call, or when a context switch happens. Thus, a context switch entails a push-pop operation: The kernel pushes the context of the old process and pops the context layer of the new process. The process table entry stores the necessary information to recover the current context layer.

The following figure shows the components that form the context of a process:

enter image description here

The right side of the figure shows the dynamic part of the context. It consists of several stack frames where each stack frame contains saved register context of the previous layer and the kernel stack as it executes in that layer.

System context layer 0 is a dummy layer that shows the user-level context; growth of the stack here is in the user address space and the kernel stack is null. The process table entry contains the information to recover the current layer in the process (visualized by the arrow). The maximum number of context layer depends on how many levels of interrupts the system supports.

Suppose the system supports 5 levels interrupts (software, terminal, disk, peripheral devices, clock), then 7 context layers are sufficient. One for user-level context, One for system call and five for different interrupt levels.

As the kernel blocks all the lower level interrupts when a higher level interrupt occurs, there could be a maximum one interrupt of each level. Therefore, in the worst case (interrupts occurring in the sequence of level 1 to 5), seven context layers will be used. Although the kernel executes in the context of a process, the logical function it performs does not necessarily pertain to the process. For instance, interrupts handlers do not generally change the static parts of the process.

Please log in to add an answer.