Von Neumann architecture and answering operating system (what, why, how) questions

1. Hardware

von Neumann architecture

Our common computers, such as notebooks. Or our uncommon computers, such as servers, mostly obey the von Neumann system.
What is Von Neumann Architecture? As shown below:
insert image description here
input devices: mouse, keyboard, camera, microphone, disk, network card, etc.
Output devices: monitors, disks, players, network cards, disks, etc.
Input devices and output devices are collectively referred to as peripherals (external devices).
Some devices are pure input or output devices, and some devices can be both input devices and output devices.
Calculator: Perform calculation tasks (arithmetic calculations, logical calculations) on our data.
Controller: Control the calculation process of our hardware to a certain extent. For example: Is the data input to the device ready? When will the data be taken from the memory for calculation.
The arithmetic unit and the controller combine into a CPU.

From the above, it can be seen that each hardware of the computer is an independent entity, and when the computer is working, each hardware must perform data interaction, so each unit must be connected with "wires", that is, physically connected, in order to To enable data interaction between various hardware, this "line" is divided into a system bus and an IO bus. The line connecting the CPU and the memory (memory) is the system bus, and the line connecting the memory (memory) and the input and output devices is the IO bus.

The von Neumann architecture stipulates that the data of the input device can only be input to the memory, and then the memory passes the data to the CPU to perform the calculation function, and the result obtained after the calculation is then passed to the memory, and the memory is then output to the output device. The CPU cannot directly take data from the input device for calculation, and then write the result to the output device. This is a rule of the von Neumann architecture. why? The reason is that the speed of the CPU is too fast, and the input and output devices are peripherals, and the speed is very slow. If the CPU directly takes and outputs data from the input and output devices, the CPU will always wait for the data from the input device to be ready, and The data of the calculated results must always wait for the output device to get it. If the speed difference between the two is too large, it is destined to work serially. In this case, the speed of the whole machine depends on the speed of the input and output devices, that is, it will change. It is very slow, which is not conducive to the improvement of the efficiency of the whole machine. And add memory (memory) between the CPU and peripherals, the speed of the memory is much faster than the speed of the input and output devices, but slower than the speed of the CPU, and the space of the memory is much larger than that of the CPU, so the memory can be processed in advance. Cache the code and data to be executed, that is, when the CPU is performing other calculations, the memory is also loading data at the same time, that is, it can work in parallel, and when the CPU goes to the memory to calculate the data, the code that needs to be calculated And the data has been completely loaded into the memory, at this time, the CPU can quickly get the data from the memory for calculation, which can greatly improve the efficiency of the whole machine.
Therefore, the memory (memory) is at the core of the von Neumann architecture. The memory is a hardware-level cache space, similar to the buffer of the C language.

Answer two questions:
Question 1: Why must a program be loaded into memory first to run?
A program is a file, and the file is placed on the disk. The code and data in the program must be run and calculated by the CPU, and the CPU will only get the data in the memory, so the program must first be loaded into the memory in order to run. The root cause is dictated by the von Neumann architecture! ! ! ! All software design must obey the underlying hardware structure! !
Question 2: Why do we not add \n when writing the printf printing function, and the printed data will be cached in the buffer first, because the result after the CPU runs is originally written back to the memory, that is, written back to the buffer , and then wait until a specific scene is refreshed to the display, instead of the CPU directly interacting with the output device, so caching during printing is a normal phenomenon.
It is worth noting that the CPU and the input and output devices are not connected only in the interactive data, but there is a certain connection in the control signal.

insert image description here
Regarding von Neumann, a few points must be emphasized:
First, the memory here refers to memory.
Second, regardless of the cache situation, the CPU here can and can only read and write memory, and cannot access peripherals (input or output devices). Third, peripherals (input or output devices)
need to input or output data, and only Can write to memory or read from memory.

In a word, all devices can only deal directly with memory.

2. Software

2.1 Layered structure of computer

insert image description here

2.2 Concept of operating system

Any computer system contains a basic collection of programs called an operating system (OS). Broadly understood, the operating system includes:
the kernel (process management, memory management, file management, driver management)
other programs (such as function libraries, shell programs, etc.)
The operating system collectively referred to by the kernel plus other programs is an operation in a broad sense system, but when we usually talk about the operating system, we actually refer to the kernel of the operating system, that is, the operating system in a narrow sense refers to the kernel of the operating system.

2.3 What is the operating system?

An operating system is a piece of software that manages hardware and software.

2.4 Why is there an operating system?


1. The operating system helps users manage the following hardware and software resources.
2. In order to provide users with a good (safe, stable, efficient) operating environment.
In general, the operating system provides users with a good execution environment (purpose) by managing the underlying software and hardware resources (means).

Who are the users here?
The users here do not refer to ordinary people’s users, because the apps we usually use are software developed by programmers, such as various games and Douyin; we are not using the operating system directly, but using the app built on the operating system The software above, so the users here actually refer to programmers, who are using the operating system and developing various application software on the operating system, so that they can be provided to ordinary people.

Because the operating system is the manager of software and hardware resources, the information of the underlying hardware resources cannot be modified at will, so users cannot directly access the underlying hardware by bypassing the operating system, but we know that all our operations on the upper layer are ultimately It will be converted into operations on the underlying hardware. For example, when we write the printf function in C language, we print the content on the monitor. When we send information to others, the information must be sent to the network card. These are operations They all need to access the underlying hardware resources, but the operating system does not trust anyone, so in order to ensure the security of its own data, the operating system can also provide services to users. It provides users with access to calls in the form of interfaces. Let users get data inside the operating system. The so-called interface is provided by the operating system. Calls to internal functions implemented in C language are called system calls for short. All access to the internal data of the operating system must be completed through system calls.

Because the system call interface is very troublesome to use, the cost of using the system call interface for ordinary users is relatively high, so many programmers have written various libraries of C language C++ based on the system call interface, so we usually write C language C++ When programming, the bottom layer of the library function interface called must encapsulate some kind of system call interface, because the operating system can only be accessed through the system call interface.

2.5 How does the operating system manage the underlying software and hardware resources?


The essence of management is: through the management of data, the management of the underlying software and hardware resources is achieved.

Management is sometimes separated, just like the boss and employees in a large company. The boss does not manage the employees directly, but manages the employees by obtaining the data of the employees through the supervisor. The same is true for the operating system, which does not directly manage the underlying hardware resources, but obtains the data of the underlying hardware resources through the driver, and then achieves the purpose of management. The operating system here is equivalent to the decision maker, and the driver is the executor. So there are so many underlying hardware resources, and there are so many underlying software and hardware resources, how should the operating system manage them?

First of all, there are many attributes of hardware, and they are scattered. Direct management is definitely not possible. Although the various attributes of the underlying hardware are definitely different, they all have these attributes, and the operating system is Written in C language, if you want to describe a multi-attribute object in C language, there is no doubt that you need to use a structure, so the way to clearly describe the underlying hardware resources is to follow the attribute information of the hardware , declare the corresponding structure, and then define each object one by one, and fill in the attribute information of each hardware into the structure, each structure object is the data describing the underlying hardware resources, this process is the process of description .

But is it enough to describe each object clearly? Of course not, if we want to manage these data better, we must organize these data in a certain data structure. Therefore, these data about software and hardware resources can be connected in the form of a doubly linked list. In this way, the management of the underlying software and hardware resources by the operating system is transformed into adding, deleting, checking and modifying the doubly linked list. For example, now that there is an additional piece of hardware, the operating system only needs to define another object, fill in the relevant attribute information, and then link this object to the doubly linked list. If a piece of hardware is broken and needs to be removed, just find the corresponding node in this doubly linked list and delete it. This process is an organizational process.

So to put it simply, the core idea of ​​the operating system to manage the underlying software and hardware resources can be summed up in six words, that is: "Describe first, then organize".

The above is all the content I want to share with you today, have you learned it? If this article is helpful to you, please be careful and pay attention to it. We will continue to update relevant content about the Linux operating system in the future. See you in the next issue! ! ! ! ! ! !

Guess you like

Origin blog.csdn.net/weixin_70056514/article/details/131713725