"Operating System Combat 45 Lectures" 03 What's in the Black Box: Kernel Structure and Design (Study Notes)

Only as a study note for my study of "45 Lectures on Operating System Combat", the original course link: Geek Time "45 Lectures on Operating System Combat" - Peng Dong (net name LMOS)

what's in the black box

The system kernel is like a black box to us, we only know what it can do, but not how it is implemented. As black box developers, it's important for us to figure out what's in the kernel.

The kernel is the manager of computer resources, and computer resources can be roughly divided into two categories: hardware resources and software resources. Hardware resources include: bus, CPU, memory, hard disk, network card, graphics card, and I/O. Software resources are various forms of data in the computer, such as various files and programs.

Macro kernel structure

Monolithic kernel (English: Monolithic kernel), also known as single core, is a kind of core architecture of operating system. The characteristic of this architecture is that the entire core program is in the identity of Kernel Space and Supervisor Mode. to run.

The macro kernel is regarded as a single process running in a single address space. All services provided by the kernel operate in privileged mode in this large kernel address space, which is called the kernel space. It is usually stored as a single static binary file on disk, or on cache, loaded into kernel space in memory after booting, and started working.

--Baidu Encyclopedia

The macro kernel is to compile the process management code, memory management code, I/O device management code, file system code, graphics system code and other functional module codes, and then link them together to form a large executable program.

This large program implements all the codes of the above functions, and provides some interfaces to the user application software, these interfaces are the so-called system API functions.

The macro-kernel structure has obvious drawbacks, because it is not modular, extensible, and portable, one of the components is vulnerable, and all components in the kernel may fail.

Macro kernel development of a new function also has to recompile, link, and install the kernel. In fact, this original kernel structure is no longer used. The only advantage of this kind of kernel is that the performance is very good, because in the kernel, these components can call each other and the performance is very high.

microkernel structure

Micro kernel (Micro kernel) is a simplified version of the kernel that provides the core functions of the operating system. It is designed to increase portability in a small memory space and provides a modular design to allow users to install different interfaces, such as DOS, Workplace OS , Workplace UNIX, etc. New operating systems such as IBM, Microsoft, Open Software Foundation (OSF), UNIX System Laboratory (USL), and Hongmeng OS have all taken advantage of this research achievement.

Micro kernel (often translated into µ-kernel or micro kernel in English). It is an operating system kernel that can provide necessary services; these necessary services include tasks, threads, Inter-Process Communication (IPC, Inter-Process Communication), and memory management. All services (including device drivers) run in user mode, and these services are handled like any other program. Because each service just runs in its own address space. So these services are protected from each other.

--Baidu Encyclopedia

When an application wants to request a related service, it sends a message corresponding to the service to the microkernel, and the microkernel forwards the message to the related service process, and then the service process starts to process the related service. The programming model of the service process is to process messages from other processes in a loop to complete related service functions.

When the microkernel works, it needs to continuously perform message passing and task process switching, and these overheads greatly reduce the system performance.

However, the microkernel still has many advantages. It has a clear structure, which is conducive to collaborative development, and has good system portability and strong expansibility.

Separating hardware dependencies

The Windows or Linux systems we usually use are built layer by layer from the hardware layer to the operating system layer to the application layer. The main purpose of layering is to shield the low-level details and make the upper-level development easier.

To separate hardware dependencies is to separate the operating system hardware from the code that handles differences in hardware functionality.

Because machines with different hardware use the same operating system, the codes for operating the hardware functions are the same, but because the underlying hardware drivers of the machines are different, there must be differences in the specific codes when the hardware processes related functions.

Therefore, at this time, it is best to put the underlying hardware code in a separate layer, such as the hardware platform-related layer. When the operating system wants to run on different hardware platforms, only the code in the hardware platform-related layer needs to be modified, so that The portability of the system is significantly enhanced.

Our choice

According to the previous content, Mr. Peng divided the operating system to be designed into three layers, namely the kernel interface layer, the kernel function layer and the kernel hardware layer.

kernel interface layer

  1. defines a subset of UNIX interfaces
  2. This interface will check whether the parameters are legal. If the parameters are OK, continue to call the lower-level code, otherwise an error will be returned.

Kernel functional layer

  1. Process management
  2. memory management
  3. Interrupt management
  4. Device management

kernel hardware layer

  1. initialization
  2. CPU control
  3. interrupt handling
  4. physical memory management
  5. Other functions of the platform

A picture sums it up:

Image source: original text of the course

insert image description here
The above kernel is actually a hybrid kernel

The hybrid kernel is essentially a microkernel, except that it allows some microkernel structures to run in the user space and the code runs in the kernel space, which makes the kernel run more efficiently. This is a compromise, and the designers refer to the theory that a microkernel-structured system runs poorly.

--Baidu Encyclopedia

Guess you like

Origin blog.csdn.net/weixin_43772810/article/details/124161336