Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

It's over! CPU keeps asking that something is going to happen.

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >

Share

Shulou(Shulou.com)11/24 Report--

This article comes from the official account of Wechat: programming Technology Universe (ID:xuanyuancoding), author: Xuanyuan Wind

My name is Ah Q. I am an employee in the No.1 workshop of CPU. The CPU I work in has eight cores and eight workshops.

In my No.1 workshop, in addition to being responsible for executing instructions, I also have Xiao A, who is responsible for fetching instructions, Xiao Pang, who is responsible for analyzing instructions, and Lao K, who is responsible for writing back results.

Every workshop in CPU has a pile of boxes, which people call registers, and my No.1 workshop is no exception. Our daily job is to carry out instructions, and then toss about these boxes to store things and get things in them.

As a result of the excellent work of the four of us, the No.1 workshop made outstanding achievements and won the best CPU core award many times at the annual meeting.

Cache We have to deal with memory every day, but because the memory guy is so slow, we waste a lot of time waiting for him to transmit data to us.

Finally, one day, the above gave us an order that our competitor CPU is catching up with us, and let us find a way to improve our work efficiency. This baffled us. We are never lazy in our usual work. We can only blame the memory guy, who is holding us back.

One night, the four of us had dinner together, and we all sighed when we discussed the above order.

At a time when he was at his wit's end, Lao K put forward an idea: "Brothers, I have found a phenomenon that when we are dealing with memory, if we access the data of a certain address, the data around it will most likely be accessed later." at this point, Old K paused.

As I listened, I thought, Xiao A spoke first: "and then what do you mean?"

Old K continued: "every time we look for memory, it's too slow. I want to draw an area in our workshop, combined with the phenomenon I found, and let the memory give us the data near the target area at once. We have this area." later, when you need to use it, you will go here to look for it. Isn't it convenient to find memory again? "

Listening to Lao K's description, it felt reliable, and I hastened to agree: "good idea!" you see, this memory is always holding us back, but this guy won't be able to get up fast for a while. Why don't we try this first to see if we can speed up the work efficiency and give an explanation to the top? "

We soon put it into practice, and we named this technology caching, and the effect was surprisingly good. Later, in order to further optimize, we divided the cache into two pieces, one very close to the register is called first-level cache, and the rest is called second-level cache. The first level cache is further divided into two parts: instruction cache and data cache.

The work efficiency of our workshop has improved by leaps and bounds, but I don't know who leaked the news. Several other workshops also knew about this technology and followed suit.

On this day, for the sake of performance, we decided to add the third-level cache, and this time we made the space a little bigger, but our workshop site was a little cramped and could not be put down. We secretly gave feedback to the leaders above and wanted them to help us coordinate.

The leader agreed, but told us that he had to balance the interests of each workshop. However, the space in our factory is also limited, so it is impossible to allocate so much space to each workshop, so we decided to arrange a large area in the factory and let each workshop share it. There was no way, so we had to agree.

Now that we have used the three-tier cache technology, the slow-down phenomenon of the guy in memory has been alleviated a lot, and we can find the data we need from this three-tier cache for a considerable part of the time.

Disorderly execution with the development of technology, the performance of our CPU factory is also rising, slowly, we began to idle down again, because we are so fast, although we have a cache, but we still have a lot of leisure time.

On this day, as usual, Xiao A took orders, and we knew it would take some time, so I fought with Xiao Pang and the three of us.

After playing several times, Xiao A came back out of breath, "Xiao Pang, it's your turn to instruct the analysis, you get up and let me play a few." Xiao Pang hurriedly got up to work and put Xiao An on the table.

In this way, several of us took turns working and kept the landlord table for three all the time.

Unexpectedly, before long, the leaders of the factory came to inspect and happened to see several of us playing cards and reprimanded us severely.

"you guys are having a good time at work," said the leader's face.

"Leader, we are not lazy. The steps of getting instructions, decoding, executing, and writing back have to be carried out step by step, but we work too fast, the memory can't keep up with us, and we wait for boredom to pass the time," I explained.

"waiting for you can also do some preparatory work ahead of time, do not waste time, let production efficiency please climb to another tall building," the leader said and left, leaving us to look at each other.

However, what the leader said was like a heavy hammer on my head. Yes, if we have time to play cards, we might as well do the preparation of the follow-up instructions in advance, which will certainly improve a lot of efficiency.

I began to organize several brother discussions, "guys, most of our time is wasted waiting for in-memory data. If we can prepare the data needed for subsequent instructions into the cache in advance during the waiting time, that will save a lot of time. You don't have to wait that long every time."

After listening to this, Lao K appreciated my idea and added: "not only the preparatory work, but also some instructions, such as addition, if the data involved in the addition does not depend on the results of the previous instructions, we can execute the addition instructions in advance. Save the results in the cache, and then write the cached results to memory when it's really the instruction's turn to execute, won't it also save time?"

People began to brainstorm, there were so many things that could be done before, but now they have to take the initiative to attack, because if they are out of order, they will execute the following instructions in advance. We call this technology out of order.

Everyone should keep it a secret this time. We can't let the workshop next door know about our discussion. I reminded you before the end of the meeting.

The branch predicted that according to the results of the discussion at this meeting, we were going to implement it the next day, but we ran into trouble at the very beginning.

According to the plan, in our spare time, we will do what can be done by the instructions to be executed in advance, but the trouble is that we encounter a judgment instruction, because we do not know whether the final result is true or false, we have no way to know whether we should execute the instructions of branch An or branch B. Don't dare to act rashly, for fear of doing useless work for a while.

Everyone had to give up the idea of making preparations in advance and take it one step at a time.

But we soon found that we often executed this judgment instruction, and each time the result was to execute branch A, never been to branch B.

So several of us discussed and invented a technology called branch prediction. when a branch jumps, according to previous experience, if a branch is often executed, there must be a high probability of going to this branch later. in this way, we predict that we will go to this branch in the future, and we will do the work that can be done by the instructions behind this branch in advance.

Sure enough, after the use of branch prediction and out-of-order execution, the efficiency of our workshop has been greatly improved, praised us again at the collective meeting of the factory, and promoted our advanced technology to the whole factory.

Not finished to be continued

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

IT Information

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report