1. Introduction

Conceptually, a computer can be abstracted into the model shown below

The CPU, memory, and I/O devices are all connected by a system bus and communicate with other devices through the bus

2. CPU

The CPU is the brain of the computer, pulling instructions from memory and executing them.

2.1 CPU workflow

Taking instructions out of memory, decoding them and executing them, the CPU repeats this process all the time.

Figure 1.1CPU workflowCopy the code

2.2 Superscalar CPU

Pipelining is inefficient, so superscalar cpus are introduced

Superscalar CPUS work in this way, multiple values and decoding at the same time, the value decoding instructions will be completed into the buffer, buffer corresponding to multiple execution units, whenever there are instructions in the buffer and there are free execution units, it will be taken out of the buffer into the execution unit execution.

Figure 1.2 Superscalar CPU workflowCopy the code

2.3 Kernel mode and user mode

Most cpus have two modes, kernel mode and user mode

In kernel mode, the CPU can execute every instruction in the instruction set, using all the capabilities of the hardware

In user mode, the CPU can only execute a subset of the instruction set and access all functions by itself

On desktops and servers, operating systems run in kernel mode. In most embedded systems, part of the operating system runs in kernel mode and the rest in user mode

3. The memory

3.1 Memory is divided into four levels

Register cache memory hard disk

Figure 2.1 Four layers of storageCopy the code

3.2 register

Registers exist in the CPU, and access is as fast as the CPU, with no delay

3.3 Cache

Common cache rows are placed inside or very close to the CPU

3.3.1 Cache hit

When the program needs to read a word, it checks whether the desired word is in the cache. If it is in the cache, it is called a cache hit

If the cache misses, access requests are passed through the bus to memory, which slows down access speed

PS: the cache

A large number of resources exist in one place of computer memory, and a small number of resources are frequently used. The frequently used resources are placed in storage at a higher level than the large number of resources, which is called cache.

When a computer reads a file, it puts frequently used files from the hard disk into memory. This is the application of cache.

There are several issues to consider when using caching

1) When to put resources in the cache

2) Which layer of storage to put resources on

3) What is removed from the cache when it is full

4) Where to put the removed content

3.3.2 rainfall distribution on 10-12 memory

Memory is usually called random-access memory (RAM), which is faster than disk. Programs are entered and executed here first.

PS: the flash memory

Speed between memory and disk, data does not disappear after power failure

3.4 disk

3.4.1 Disk Workflow

Like an old-fashioned record player, disks are stacked on top of each other, each with a pointer that rotates as it reads data from the disk, reading a circular region called a track.

Figure 2.2 Disk workflowCopy the code

We often talk about the speed of the disk, how many megabits per second, from the flow of the disk, we can see that the speed of the disk is the speed of the disk arm rotation

3.4.2 SOLID-state Drives

Solid-state drives don’t work the same way as regular disks; they’re actually flash memory

3.4.3 Virtual Memory

The virtual memory mechanism of the computer is to put the contents that need to be read repeatedly in the disk into the memory to speed up the computer. It is also a kind of cache application

4. I/O devices

An I/O device is divided into two parts: the device controller and the device itself

4.1 Device Controller

The device controller is a chip or a group of chips inserted on the circuit board. It is the bridge between the operating system and the device. It operates the device with the operating system, and the operating system issues commands to it.

Figure 3.1 Device controllerCopy the code

4.2 Device Itself

Hard drive, keyboard, mouse, monitor and so on

The device itself has a relatively simple standardized interface, such as SATA disks. SATA is the interface name of the device

4.3 Device Drivers

How the operating system operates the device controller, the answer is to install device controllers on the operating system, device controllers that talk to the controller, issue commands, and receive responses.

4.4 Three input and output modes

1) Busy waiting: the user program initiates a system call, which the kernel translates into a procedure call for the device driver. The device driver initiates I/O, checking in cycles to see if the device has done its job. When it has done its job, the device driver sends the data returned by the device to the specified location, and the operating system returns control to the caller.

Disadvantages: Obviously, the CPU has to be constantly checked until the device is finished, during which time the user can do nothing

2) Interrupt control: The device driver starts the device to issue an interrupt when the operation is complete, and the driver passes the interrupt to the operating system.

3) Direct memory access: A special chip (DMA) is used for I/O operations, which directly controls the communication between memory and controller without continuous CPU intervention, and also issues an interrupt when the operation is complete.

5. The bus

A wire that connects all the hardware on a computer

5.1 PCI bus

Multiple devices use the same wire to transmit data, and when multiple devices need to send data, the mediator decides which device can use the bus. (Already out of date)

5.2 PCIe bus

End-to-end links, where each device has a separate wire to send data

6. Start the computer

After learning computer related hardware knowledge, let’s understand how the computer works inside the computer when it is started

First, the BIOS runs, scans the I/O devices to see if the memory is properly installed, scans all the devices on the bus, and then finds a boot loader module from the hard disk that boots the operating system (WINDOWS/LINUX). The operating system then asks the BIOS for configuration information about each device. The operating system checks whether the drivers of the corresponding device are properly installed. If all the drivers are properly installed, the operating system transfers them to the kernel, creates all required processes, and starts the login program on the terminal.

\