当前位置:网站首页>Do you have all the basic embedded knowledge points that novices often ignore?

Do you have all the basic embedded knowledge points that novices often ignore?

2022-06-24 18:47:00 Lixiaoyao

     Focus on 、 Official account of star standard , Straight to the highlights

12c681d4a1d5c5d20376dd6ede269d63.png

source :《 The essence of Computer Science 》

To solve various problems , People have invented countless machines . There are many kinds of embedded devices , From computers embedded in Mars rover robots to systems for manipulating nuclear submarine navigation systems , To name but a few .

feng • Neumann is 1945 The first calculation model was proposed in , Whether it's a laptop or a phone , Almost all computers follow the same principle as this model .

So do you know how computers work ? This article will discuss these contents :

◎ Understand the basics of computer architecture

◎ Select the compiler to convert the code into instructions that the computer can execute

◎ Improve the storage speed of data according to the memory hierarchy

After all , In the eyes of non programmers , Programming should be as magical as magic , We programmers don't think so .

Architecture

A computer is a machine that operates data according to instructions , It is mainly composed of processor and memory . Memory, also known as RAM( Random access memory ), Used to store instructions and data to be operated . Processor, also known as CPU( a central processor ), It gets instructions and data from memory , And perform the corresponding calculation . Next , We will discuss how these two parts work .

Memory

Memory is divided into many units , Each unit stores a small amount of data , Identified by a numeric address . When reading or writing data in memory , Operate one unit at a time .

A specific storage unit for reading and writing , The numeric address of the unit must be found .

Since memory is an electrical component , The unit address is transmitted as a binary number through the signal line .

Binary numbers 2 Is the cardinality of , Its working principle is as follows :

719893b9d62c7124a98aa12aad9e5253.png

Each signal line transmits one bit , The signal is represented by a high voltage “1”, Low voltage indicates signal “0”, Pictured 7-1 Shown .

f4bfe0395a41d6f7802ad2fb712abea7.png

For a given cell address , Memory can perform two operations : Get its value or store a new value , Pictured 7-2 Shown . The memory includes a special signal line for setting the operation mode .

3fa8397b2c7f763ca31292148cb45002.png

Each storage unit usually stores one 8 Bit binary number , It's called byte . Set to “ read ” Mode time , The memory retrieves the bytes stored in the unit , And pass 8 Data transmission line output , Pictured 7-3 Shown .

eb1d364067c34df796f12db34ca432a5.png

Set to “ Write ” Mode time , The memory gets a byte from the data transmission line , And write it into the corresponding unit , Pictured 7-4 Shown .

11aa8298346815894768f6e151d743c7.png

A group of signal lines that transmit the same data is called a bus . Used to transmit addresses 8 Two signal lines form an address bus , Another method for transmitting data between storage units 8 Two signal lines form a data bus . The address bus is one-way ( For receiving data only ), The data bus is bidirectional ( For sending and receiving data ).

In all computers ,CPU And RAM Exchange data all the time :CPU Constantly from RAM Get instructions and data , Occasionally, the output and some calculations are stored in RAM in , Pictured 7-5 Shown .

ce7f63c72596cf0cc804f36d61c415ca.png

CPU

CPU It includes several internal storage units called registers , It can perform simple mathematical operations on the numbers stored in these registers , Can also be in RAM Transfer data between and registers . Can indicate CPU Perform the following typical operations :

◎ Remove data from storage location 220 Copy to register 3;

◎ Register 3 And registers 1 Add the numbers in .

CPU The set of all operations that can be performed is called the instruction set , Each operation in the instruction set is assigned a number . Computer code is essentially a representation CPU Number sequence of operations , These operations are stored digitally in RAM in . Input / Output data 、 Some calculations and computer code are stored in RAM in .

By means of RAM Contains instructions to rewrite part of the code , The code can even modify itself , This is the usual way for computer viruses to escape the detection of anti-virus software . similarly , Biological viruses change their own DNA To avoid the attack of the host immune system .

chart 7-6 Taken from the Intel 4004 Operation manual , Shows part of CPU Method of mapping instructions to numbers . With the development of manufacturing technology ,CPU More and more operations are supported . modern CPU The instruction set is extremely large , But the most important directives existed decades ago .

95ff4ac79c64fc6c53e68568670b8252.png

CPU The operation of is endless , It constantly gets and executes instructions from memory . The core of this cycle is PC register ,PC (program counter) yes “ Program counter ” For short .PC It's a special register , The storage address used to store the next instruction to be executed .CPU The workflow of is as follows :

(1) from PC The specified storage address acquisition instruction ;

(2) PC Self increasing ;

(3) Execution instruction ;

(4) Return steps 1.

PC stay CPU Reset to default value at power on , It is the address of the first instruction to be executed in the computer . This instruction is usually an immutable built-in program , Used to load the basic functions of the computer .

In many personal computers , This procedure is called BIOS( Basic I / O system ).

CPU This operation will continue after power on “ obtain - perform ” Cycle until shutdown . However , If CPU Can only follow the order 、 Sequential operation list , Then it's no different from a fancy calculator .CPU The magic of is that it can be directed to PC Write a new value in , So as to realize the branch of the execution process , or “ Jump ” To another location in memory . This branch can be conditional . Here's the one below CPU Instruction as an example :“ If register 1 be equal to 0, take PC Set to address 200”. This instruction is equivalent to :

if x = 0
compute_this()
else
compute_that()

That's it . Whether it's opening a website 、 Play computer games or edit spreadsheets , There is no difference in the calculations involved , Are a series of data that can only sum up the data in memory 、 Simple operation of comparing or moving .

A lot of simple operations are combined , Can express complex processes . With the classic 《 Space Invaders 》 Take the game for example , Its code includes approximately 3000 A machine command .

8ac454f66da5100d116d575c9dab419b.png

CPU The clock   As early as 20 century 80 years ,《 Space Invaders 》 It's all the rage . The game is equipped with 2 MHz CPU Running on the arcade .“2 MHz” Express CPU The clock of , namely CPU The number of basic operations that can be performed per second . The clock frequency is 200 Ten thousand Hertz (2 MHz) Of CPU About... Can be performed per second 200 Ten thousand basic operations . Completing a machine command requires 5 To 10 Sub basic operation , Therefore, the old arcade can run hundreds of thousands of machine instructions per second .

With the progress of modern science and Technology , Ordinary desktop computers and smartphones are usually equipped with 2 GHzCPU, Hundreds of millions of machine instructions can be executed per second . today , Multicore CPU It has been put into large-scale application , Such as tetranuclear 2 GHz CPU It can execute nearly... Per second 10 100 million machine instructions . Looking forward to the future ,CPU The number of cores equipped may be more and more .

CPU Architecture   Has the reader thought about ,PlayStation The game of CD Why not run on a desktop computer ?iPhone Why can't apps be in Mac Run in ? The reason is simple , Because of their CPU The architecture is different .

x86 Architecture has now become an industry standard , Therefore, the same code can be executed on most personal computers . But considering the requirements of power saving , The mobile phone uses CPU The architecture is different . Different CPU Architecture means different CPU Instruction set , It also means that instructions are encoded into numbers in different ways . Desktop computer CPU Your instructions are not mobile phones CPU Valid instructions , vice versa .

32 Bit and 64 Bit architecture   The first one is CPU yes Intel 4004, It uses 4 Bit architecture . In other words , such CPU In a single machine instruction, the maximum number of 4 Bit binary numbers perform summation 、 Compare and move operations .Intel 4004 The data bus and address bus of are only 4 strip .

Not long after ,8 position CPU It became popular , such CPU Used to run the DOS Early personal computers .20 The 1980s and 1990s , Famous portable game console Game Boy Just use 8 Bit processor . such CPU You can do this in one instruction 8 Operate on binary numbers .

The rapid development of technology makes 16 Bit and after 32 Bit architecture becomes dominant .CPU The register increases , To accommodate 32 Digit number . Larger registers naturally give rise to larger data and address buses : have 32 The address bus of a signal line can be connected to 232 byte (4 GB) To address in memory .

People's thirst for computing power has never stopped . Computer programs are becoming more and more complex , More and more memory is consumed ,4 GB Memory can no longer meet your needs . Suitable for use 32 The digital address pair of bit register exceeds 4 GB Memory addressing is tricky , This becomes 64 The motivation for the rise of bit architecture , This architecture is now dominant .64 position CPU You can operate on very large numbers in one instruction , and 64 Bit registers store addresses in a large amount of storage space :264 Bytes are equivalent to more than 170 Gigabytes (GB).

Large end sequence and small end sequence   Some computer designers think , It should be in... From left to right RAM And CPU Store numbers in , This pattern is called small end sequence . Other computer designers tend to write data in memory from right to left , This pattern is called big endian . therefore , according to “ Byte order ” Different , Binary sequence 1-0-0-0-0-0-1-1 The numbers are also different .

◎ big-endian :27 + 21 + 20 = 131

◎ Small end of the sequence :20 + 26 + 27 = 193

Most of the current CPU Small end sequence mode is adopted , But there are also many computers with large end sequence mode . If the big end sequence CPU It needs to be explained by the small end sequence CPU Data generated , Measures must be taken to avoid byte order mismatch . Programmers operate directly on binary numbers , This problem should be paid special attention to when parsing data from network switches . Although most computers use small end sequence mode at present , However, because most early network routers used large end order CPU, Therefore, Internet traffic is still standardized on the basis of large end order . Garbled code will appear when reading large end sequence data in small end sequence mode , vice versa .

Simulator   In some cases , You need to run something different on your computer CPU Design code , So that in the absence of iPhone To test iPhone application , Or play the popular old Super Nintendo game . This is achieved through software called Simulator .

The simulator is used to simulate the target machine , It assumes that it has the same CPU、RAM And other hardware . The simulator program decodes the instructions , And execute... In a simulated machine . You can imagine seeing , If the architecture of the two machines is different , So it's not easy to simulate another machine inside one machine . Fortunately, modern computers are much faster than previous machines , So simulation is not impossible . We can use Game Boy The simulator creates a virtual... In the computer Game Boy, Then you can use the actual Game Boy Play games like that .

compiler

By programming the computer , Can complete MRI 、 Voice recognition 、 Planetary exploration and many other complex tasks . It is worth noting that , All the operations performed by the computer are ultimately through a simple CPU Command complete , That is, it comes down to the sum and comparison of numbers . and Web Complex computer programs such as browsers require millions or even billions of such machine instructions .

But we rarely use it directly CPU Instructions to write programs , Nor can we develop a realistic three-dimensional computer game in this way . In order to be more “ natural ” And express commands in a more compact way , People created programming languages . We write code in these languages , The command is then converted to... Through a program called the compiler CPU Machine instructions that can be executed .

We use a simple mathematical analogy to explain the purpose of the compiler . Suppose we ask someone a question , Ask him to calculate 5 The factorial .

5! = ?

But if the respondent doesn't know what factorial is , There is no point in asking such questions . We have to rephrase the problem with simpler operations .

5×4×3×2×1 = ?

however , What if the respondent can only add ? We must further simplify the formulation of the problem .

5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 +5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 = ?

You can see , The simpler the form of expression calculation , The more operations required . The same is true of computer code . The compiler converts complex instructions in the programming language into equivalent instructions CPU Instructions . Combined with powerful external libraries , It can be represented by a relatively few lines of code that contains billions of CPU A complex program of instructions , And these codes are easy to understand and modify .

Alan, the father of computers • Turing discovery , Simple machines have the ability to calculate anything that can be calculated . If the machine has universal computing power , Then it must be able to follow the program containing instructions , In order to :

◎ Read and write the data in the memory ;

◎ Take conditional branch : If the storage address has a given value , Then jump to another point of the program .

We call machines with this general computing power Turing complete . No matter how complex or difficult the calculation is , Can use a simple read / write in / Branch instructions to express . Just allocate enough time and storage space , These instructions can calculate anything .

513a6742e30182beb05ae54b7ede118b.png

People recently found that , One is called MOV( Data transfer ) Of CPU Instructions are Turing complete . This means that only MOV The directive CPU And the whole CPU There is no difference in function : In other words , adopt MOV Instructions can strictly express any type of code .

This important concept is , Simple or not , If the program can be coded in a programming language , It can be rewritten and run in any Turing complete machine . The compiler is a magical program , It can automatically convert code from complex language to simple language .

operating system

essentially , The compiled computer program is CPU Sequence of instructions . As mentioned earlier , Code compiled for desktop computers cannot run in smartphones , Because they use different CPU Architecture . however , Because the program must communicate with the computer's operating system to run , The compiled program may not share the same CPU The architecture is used in two computers .

In order to achieve communication with the outside world , The program must perform input and output operations , If you open a file 、 Display the message on the screen 、 Open network connection, etc . But different computers use different hardware , Therefore, it is impossible for the program to directly support all different types of screens 、 Sound card or network card .

This is why programs depend on the operating system for execution . With the help of the operating system , Programs can easily use different hardware . Programs create special system calls , Request the operating system to perform the required input / Output operation . The compiler is responsible for inputting / The output command is converted to the appropriate system call .

However , Different operating systems often use incompatible system calls . for example , And macOS or Linux comparison ,Windows The system calls used to print information on the screen are different .

therefore , In the use of x86 The processor Windows Program compiled in , Can't use x86 The processor Mac Run in . Except for specific CPU Outside the architecture , The compiled code will also be specific to the specific operating system .

Compile optimization

Good compilers are committed to optimizing the machine code they generate . If the compiler thinks it can improve execution efficiency by modifying part of the code , Will deal with . Before generating binary output , The compiler may try to apply hundreds of optimization rules .

therefore , Make the code easy to read for micro optimization . The compiler will eventually complete all minor optimizations . for example , Some people complain about the following code .

function factorial(n)
if n > 1
return factorial(n - 1) * n
else
return 1

They think the following changes should be made :

function factorial(n)
result ← 1
while n > 1
result ← result * n
n ← n - 1
return result

indeed , Execute... Without recursion factorial Functions consume less computational resources , But there is still no reason to change the code . Modern compilers will automatically rewrite simple recursive functions , Examples are as follows .

i ← x + y + 1
j ← x + y

To avoid twice x+y Calculation , The compiler rewrites the above code as :

t1 ← x + y
i ← t1 + 1
j ← t1

Focus on writing clear and self explanatory code . If there is a performance problem , You can use analysis tools to find bottlenecks in your code , And try to calculate the problematic code in a better way . Besides , Avoid wasting too much time on unnecessary micro operations .

But in some cases , We want to skip compiling , This will be discussed next .

Scripting language

Some languages are not directly compiled into machine code at execution time , These languages are called scripting languages , Include JavaScript、Python as well as Ruby. In scripting languages , The code is interpreted by the interpreter, not CPU perform , The interpreter must be installed on the machine running the code .

The interpreter translates and executes the code in real time , Therefore, it usually runs much slower than the compiled code . But on the other hand , Programmers can run code immediately at any time without waiting for the compilation process .

For large-scale projects , Compilation can take hours .

Google Engineers must constantly compile large amounts of code , Cause programmers to “ Loss ” It took a lot of time ( chart 7-9). Due to the need to ensure that the compiled binary file has better performance ,Google Cannot switch to scripting language . The company has developed Go Language , It compiles very fast , While still maintaining high performance .

ee81f5bfa4a1d086dc933a63dc5bc792.png

Disassembly and reverse engineering

Given a compiled computer program , Cannot recover its source code before compiling . But we can decode binary programs , Will be used to encode CPU The number of instructions is converted into a human readable sequence of instructions . This process is called disassembly .

Next , You can see these CPU Instructions , And try to analyze their use , This is called reverse engineering . Some disassemblers are of great benefit to this process , They can automatically detect and annotate system calls and common functions . By disassembly tools , Hackers know all aspects of binary code like the back of their hands . I Believe , Many of the best IT Companies have secret Reverse Engineering Laboratories , In order to study competitors' software .

Underground hackers often analyze Windows、Photoshop、《 Grand theft auto 》 Binary code in authorization program , To determine which part of the code is responsible for verifying the software license . The hacker modified the binary code , Add an instruction to it , Jump directly to the part of the code executed after verifying the license . When running the modified binary code , It gets the injected... Before checking the license JUMP command , So you can run illegal pirated copies without paying .

In a secret government intelligence agency , There are also for safety researchers and engineers to study iOS、Windows、IE A laboratory for popular consumer software such as browsers . They look for possible security vulnerabilities in these programs , To defend against cyber attacks or intrusion into high-value targets . In such attacks , The most famous is “ Seismic net ” Viruses , It is a network weapon developed by the United States and Israeli intelligence agencies . Infecting computers that control underground fusion reactors ,“ Seismic net ” Delayed Iran's nuclear program .

Open source software

As mentioned earlier , We can analyze the original instructions of the program according to the binary executable , However, the original source code used to generate binary files cannot be recovered .

Without the original source code , Even if the binary can be modified slightly to crack in a smaller way , In fact, you can't make any major changes to the program ( Such as adding new functions ). Some people advocate collaborative code building , So open your source code for others to modify .“ Open source ” This is the main concept of : Software that everyone can use and modify freely . be based on Linux Operating system of ( Such as Ubuntu、Fedora And Debian) It's open source. , and Windows And macOS It's closed source .

One interesting thing about open source operating systems is , Anyone can check the source code for security vulnerabilities . It has been confirmed that , Government agencies through unpatched security vulnerabilities in daily consumer software , Millions of civilians are used and monitored .

But for open source software , Code gets more attention , Therefore, it is difficult for malicious third parties and government agencies to implant monitoring backdoors . Use macOS or Windows when , Users must believe Apple or Microsoft It will not endanger your own safety , And do our best to prevent any serious security vulnerabilities . Open source systems are under public supervision , Therefore, the possibility of security vulnerabilities being ignored is greatly reduced .

Memory hierarchy

We know , The operation of a computer boils down to making CPU Execute simple instructions , These instructions can only be stored in CPU Data operations in registers . However, the storage space of registers is usually limited to 1000 Bytes within , It means CPU Register and RAM There must be continuous data transmission between .

If memory access is too slow ,CPU Will be forced to be idle , Waiting for RAM Complete the data transfer .CPU The time required to read and write data in memory is directly related to computer performance . Increasing the speed of memory helps to speed up the computer , It can also improve CPU The speed of accessing data .CPU At near real-time speed ( Within one cycle ) Access data stored in registers , But visit RAM Much slower .

The clock frequency is 1 GHz Of CPU, The duration of a cycle is about one billionth of a second , This is the time it takes for light to enter the reader's eyes from the book .

The gap between processor and memory

Recent technological developments have made CPU The speed has doubled . Although the memory speed has also improved , But much slower .CPU And RAM This performance gap is called “ The gap between processor and memory ”. We can perform a lot of CPU Instructions , So they are “ cheap ”; And from RAM It takes a long time to get the data , So they are “ expensive ”. As the gap between the two increases , The importance of improving memory access efficiency is becoming more and more obvious .

188dae1aef8220ce09885fc1828e461c.png

Modern computers need about 1000 individual CPU cycle (1 About microseconds ) from RAM get data . This speed has been amazing , But with access CPU Register time is still slower . Reduce the time required for calculation RAM Operating frequency , Is the goal pursued by computer scientists .

Between two face-to-face people , Sound wave propagation takes about 10 Microsecond .

Time locality and space locality

Trying to minimize the impact on RAM During the visit , Computer scientists are beginning to notice two facts .

◎ Temporal locality : When accessing a storage address , You may visit the address again soon .

◎ Spatial locality : When accessing a storage address , You may soon visit the address next to it .

therefore , Save these storage addresses in CPU In the register , It helps to avoid most of RAM Of “ expensive ” operation . But in design CPU Chip time , Industrial engineers have not found a feasible way to accommodate enough internal registers , But they still found out how to make effective use of temporal locality and spatial locality . This will be discussed next .

First level cache

You can build an integration in CPU Internal and extremely fast auxiliary memory , This is the L1 cache . Read data from L1 cache into register , Only slightly slower than getting data directly from registers .

Take advantage of L1 cache , We copy the contents of the storage address that may be accessed to CPU Near the register , In this way, the data can be loaded into... At a very fast speed CPU register . It takes only about... To read data from the L1 cache into registers 10 individual CPU cycle , The speed is from RAM Get nearly a hundred times the data .

through 10 KB Left and right L1 cache , And make rational use of time locality and space locality , More than half of RAM Access calls can be achieved only through caching . This innovation has brought earth shaking changes to computing technology . L1 cache can greatly shorten the time CPU The waiting time of , send CPU Spend more time on actual calculations instead of being idle .

Second level cache

Increasing the capacity of the L1 cache helps to reduce the number of requests from RAM The operation of obtaining data , Thus shortening CPU The waiting time of . however , Increasing the L1 cache also slows it down . The first level cache reaches 50 KB Left and right , Continuing to increase its capacity requires a very high cost . A better solution is to build a cache called L2 cache . The L2 cache is slightly slower , But the capacity is much larger than the L1 cache . modern CPU The L2 cache is about 200 KB, Read data from L2 cache into CPU The register needs about 100 individual CPU cycle .

We copy the most likely addresses to the L1 cache , The addresses that are more likely to be accessed are copied to the L2 cache . If CPU A storage address was not found in the L1 cache , You can still try searching in the L2 cache . Only if the address is not in the first level cache 、 When it is not in the L2 cache ,CPU You need to visit RAM.

at present , Many manufacturers have introduced processors equipped with three-level cache . The third level cache has a larger capacity than the second level cache , Although not as fast as L2 cache , But still more than RAM Much faster . Class A / second level / L3 caching is very important , They occupy CPU Most of the silicon space inside the chip . See the picture 7-11.

08d09a2edeb6e579b13a2fe97c809642.png

Use level 1 / second level / Third level cache can significantly improve the performance of computers . In the 200 KB After the second level cache ,CPU Less than... Of the storage requests issued 10% Must be directly from RAM obtain .

When readers buy computers in the future , For the selected CPU, Remember to compare level one / second level / The capacity of the L3 cache .CPU The better , The larger the cache . Generally speaking , It is recommended to choose one with lower clock frequency but larger cache capacity CPU.

First level memory and second level memory

As mentioned earlier , Computers are equipped with different types of memory , They are arranged in a hierarchy . The best memory has limited capacity and high cost . Down the hierarchy , More and more storage space is available , But access is getting slower .

507650f342b57815eb77d25b24e7ff40.png

In the storage hierarchy , be located CPU Under the register and cache is RAM, It is responsible for storing the data and code of all currently running processes . By 2017 year , The computer is equipped with RAM The capacity is usually 1 GB To 10 GB. But in many cases ,RAM It may not meet the needs of the operating system and all running programs .

therefore , We must delve into the memory hierarchy , Use in RAM The hard disk under . By 2017 year , The computer is usually equipped with a hard disk with a capacity of hundreds of gigabytes , Enough to hold all program data currently running . If RAM Is full , The current free data will be moved to the hard disk to free up some memory space .

The problem lies in , The speed of the hard disk is very slow , It generally requires 100 m CPU cycle (1 millisecond )a On disk and RAM Transfer data between . Accessing data from disk seems fast , But don't forget , visit RAM Only 1000 A cycle , Access to disk requires 100 Ten thousand cycles .RAM It is usually called first level memory , The disk that stores programs and data is called secondary memory .

The standard photo is about 4 Capture light in milliseconds .

CPU Secondary storage cannot be accessed directly . Before executing the program stored in the second level memory , It must be copied to the first level storage . actually , Every time you start the computer , Even the operating system should be copied from disk to RAM, otherwise CPU Unable to run .

Make sure RAM Inexhaustible   During a typical activity , Ensure that all data and programs processed by the computer can be loaded RAM crucial , Otherwise, the computer will be constantly on disk and RAM Data exchange between . Because the speed of this operation is very slow , The performance of the computer will be seriously degraded , Not even available . In this case , Computers have to spend more time waiting for data transmission , And can't actually calculate .

When the computer keeps reading data from disk RAM when , The computer is said to be in jitter mode . The server must be continuously monitored , If the server starts processing, it cannot load RAM The data of , Then jitter may cause the whole server to crash . There will be a long line in front of the bank or cash register , The waiter has no choice but to blame the shaking computer system . Insufficient memory may be one of the main causes of server failure .

External memory and third level memory

We continue down the memory hierarchy . After connecting to the network , The computer can access the memory managed by other computers . They are either on the local network , Or on the Internet ( The cloud ). But accessing this data takes longer : Reading the local disk requires 1 millisecond , It may take hundreds of milliseconds to get the data in the network . It takes about... To transfer network packets from one computer to another 10 millisecond , If transmitted via the Internet, you need 200 Milliseconds to 300 millisecond , Similar to the blink of an eye .

At the bottom of the memory hierarchy is the third level memory , This storage device is not always online and available . On cassette tape or CD The cost of storing millions of gigabytes of data in is low , But when accessing data in such media , You need to insert media into some kind of reading device , This may take minutes or even days ( Try to make IT The Department backs up the data in the tape on Friday night ……). For this reason , Level 3 storage is only suitable for archiving rarely accessed data .

Development trend of storage technology

One side , It is difficult to improve significantly “ Fast ” Memory ( At the top of the storage hierarchy ) The technology used ; On the other hand ,“ Slow down ” The speed of memory is getting faster and faster , Prices are getting lower and lower . For decades, , The cost of hard disk storage has been falling , This trend seems to continue .

New technology has also improved the speed of disks . People are moving from rotating disks to solid state drives (SSD), It has no moving parts , So faster 、 More reliable and power saving .

use SSD Technology disks are becoming cheaper and faster , But it's still expensive . For this reason , Some manufacturers have introduced simultaneous SSD Hybrid disk with magnetic technology . The latter stores more frequently accessed data in SSD in , Less frequently accessed data is stored on slower disks . When you need to frequently access data that you didn't often access , Then copy it to the faster... In the hybrid drive SSD. This is related to CPU Use internal cache to improve RAM The technique of access speed is quite similar .

51a8d4ec1c237dfe07905e175609b341.png

Summary

This paper introduces some basic computer working principles . Anything computable can be represented by simple instructions . To convert complex calculation commands into CPU Simple instructions that can be executed , You need to use a program called a compiler . The reason why computers can perform complex calculations , Just because CPU You can perform a lot of basic operations .

The computer's processor is fast , But the memory is relatively slow .CPU Memory is not accessed randomly , But follow the principles of spatial locality and temporal locality . therefore , More frequently accessed data can be cached in faster memory . This principle is applied to multiple levels of caching : From the first level cache to the third level memory , To name but a few .

The caching principles discussed in this article can be applied to a variety of scenarios . Identify data frequently used by applications , And try to improve the access speed of this part of data , It is one of the most common strategies to shorten the running time of computer programs .

Copyright notice : Source network of this paper , Free delivery of knowledge , The copyright belongs to the original author . If involves the work copyright question , Please contact me to delete .

‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧  END  ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧

 Pay attention to my WeChat official account , reply “ Add group ” Join the technical exchange group according to the rules .
 Click on “ Read the original ” See more sharing , Welcome to share 、 Collection 、 give the thumbs-up 、 Looking at .
原网站

版权声明
本文为[Lixiaoyao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241344281034.html