1.3 Operating environment of the operating system

1.3 Operating environment of the operating system

Knowledge Graph

Operating environment of the operating system

1. Operating mechanism of the operating system

In computer systems, CPUs usually execute two different types of programs:

  • Operating system kernel program : usually execute some privileged instructions (referring to instructions in the computer that are not allowed to be directly executed by the user, such as interrupt instructions, these instructions must be scheduled and executed by the operating system),
  • User-programmed : Mainly execute non-privileged instructions .

In the specific implementation, the CPU state is divided into user state (target state) and core state (pipe state, kernel state). When the CPU is in the user mode, only non-privileged instructions can be executed ; when the CPU is in the core state, the CPU can execute both privileged instructions and non-privileged instructions . User-programmed programs run in user mode, and operating system kernel programs run in core mode .

Almost all modern operating systems have a hierarchical structure:

  • Modules with higher hardware correlation, such as clock correlation and interrupt processing, are at the lowest level;
  • Programs with high running frequency, such as process association and memory management, are located in the upper layer.

These two parts constitute the kernel of the operating system, and both run in the core state.

Most operating system kernels include the following:

1. Clock Management

There are two main categories of clock functions in the operating system:

  • Provide users with system time;
  • Through the management of clock interruption, process switching is realized.

2. Interrupt mechanism

The original purpose of introducing interrupt technology is to improve CPU utilization in a multi-channel environment.

Later, with the development of modern operating systems, interrupts became the basis of various operations of the operating system, such as the input of mouse and keyboard information, process management and scheduling, and file access. It can be said that modern operating systems rely on interrupt-driven software.

In the interrupt mechanism, only a small part belongs to the kernel, which is responsible for protecting and restoring the information at the interrupt site and transferring control to the relevant processing program. This can reduce interrupt processing time and improve CPU utilization.

3. Primitive

In an operating system designed according to a hierarchical structure, the bottom layer must be some public small programs that can be called, and they each complete a prescribed operation. They have the following characteristics:

  • At the bottom of the operating system, it is the part closest to the hardware;
  • Program operation is atomic;
  • The program has a short running time and frequent calls.

The program with these characteristics is usually called primitive (Atomic Operation). The direct way to define primitives is to close the interrupt, and open the interrupt after all actions are completed indivisible.

4. Data structure and processing of system control

There are many data structures used to register status information in the system. In order to achieve effective management, the system needs some basic operations. Common operations are as follows:

  • Process management : process state management, process scheduling and dispatch, creation and cancellation of process control blocks, etc.;
  • Memory management : memory space allocation and recovery, memory information protection program, code swap program, etc.;
  • Equipment management : buffer management, equipment allocation and recycling, etc.

It can be found from the above content that the core state instructions actually include system call instructions and some operation instructions for clocks, interrupts and primitives.

Two, the concept of interruption and exception

In order to realize the switch between the CPU user state and the core state, a channel is established in the CPU core state to realize the transition from the user state to the core state. In the actual operating system, the only way that the CPU can access these channels when running the upper-level program is through interrupts and exceptions .

Interruption, also known as external interrupt , refers to the occurrence of something other than CPU instructions. For example, the I/O device end interrupt indicates that the device input/output is completed, and it is hoped that the processor can send the next input/output request to the device while allowing the program to continue running.

Clock interruption means that a fixed time slice has arrived, allowing the processor to process timing and start timing tasks. This type of interrupt is usually something that has nothing to do with the current program running.

Exception (Exception) is also called internal interruption, exception and trap. It refers to events that originate from within the CPU executing instructions, such as address violations, arithmetic overflows, page faults in the virtual memory system, and special trap instructions. The handling of exceptions generally depends on the operating site of the current program, and exceptions usually cannot be shielded, and must be dealt with immediately once they occur .

Three, system call

The so-called system call refers to the user calling some sub-functions provided by the operating system in the program. The system call can be regarded as a special announcement subroutine.

These system calls can be roughly divided into the following categories according to their functions:

  • Equipment management: complete equipment request or release, and equipment startup and other functions;
  • File management: complete the functions of reading, writing, creating and deleting files;
  • Process management: complete process creation, cancellation, blocking and wake-up functions;
  • Process communication: complete functions such as message transmission or signal transmission between processes;
  • Memory management: complete memory allocation, recycling, and obtain the size and initial address of the memory area occupied by the job.

The user program cannot directly perform operations that affect the speed of the system, and must request the operating system to execute it on behalf of the system through a system call to improve the stability and security of the system and prevent the user program from changing or accessing important system resources at will, affecting other processes Implementation.

System call execution process

At the operating system level, what we care about is the software implementation and switching between the core state of the system and the user state.

List some examples of shifting from user mode to core mode:

  • The user program requires the service of the operating system, that is, system call;
  • An interruption occurred;
  • An error state occurred in the user program;
  • The user program tried to execute a privileged instruction;
  • The transition from the core state to the user state is also generated by a privileged instruction, usually an interrupt return instruction.

Changing from user mode to core mode requires not only switching states, but the stack used may also need to be switched from user stack to system stack, but the system stack also belongs to the process.

If the program runs from the user mode to the core mode, the access control instruction will be used. The access control instruction is used in the user mode, so it is an unprivileged instruction.

Reference material: Wangdao postgraduate entrance examination-operating system

Guess you like

Origin blog.csdn.net/qq_43580193/article/details/112910308