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

What? One core executes two threads at the same time?

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 O

Time Hi in CPU, long time no see, I am Ah Q from CPU No.1 workshop, if you don't know me, you can have a look: it's over! CPU keeps asking that something is going to happen!

We haven't seen each other for a long time. There is a saying that one day in heaven, one year on earth, but in our world, we don't know how many years it will take for a human day.

In the CPU factory where I work, the concept of time is a little different. There is a big clock hanging in the central square outside the factory gate. The residents of the whole computer world can live on it. You humans call it the crystal oscillator.

This clock tells the hour every 66000000 of a second, which is faster than the human clock.

It was enough in the early years, but with the continuous improvement of the production efficiency of our CPU factory, we repeatedly proposed to Jingzhen to improve the accuracy of the time, hoping to make him report the Times faster, but all of them were rejected. The reason given to us is that the memory guy took the lead in opposing with other units on the motherboard, saying that they were subject to conditions and could not be as fast as we were.

It is better to rely on others than to rely on yourself. for this reason, our factory has set up a special department called frequency multiplier to further subdivide this time, reaching 1 / 3600000000 of a second, as the clock cycle of our factory's internal work and rest. This number is really too long. In order to remember, human beings chose a name called the main frequency, which represents the number of times in 1 second, that is, 3.6GHz.

I accidentally went too far. I want to tell you one thing this time.

Instructions rely on the task of our factory is to constantly implement the program instructions written by human beings. There are eight workshops in our factory. When we have full horsepower, we can execute eight threads at the same time. That speed is called a fast one.

However, the boss of the factory still thought that we were not fast enough. That day, he even told us to execute two threads in each workshop to achieve eight cores and sixteen threads, in order to squeeze our labor force to the extreme! We're all full of complaints.

The cause of the matter is this.

On one occasion, the group of four in our No. 1 workshop took advantage of the opportunity to fight the landlord again, and suddenly the leader came to inspect it.

"Why are you playing again? is the workload not saturated?" When we see a few of us idle, the leader is unhappy.

I hastened to explain, "Sorry, Leader, we just executed an instruction that needed a piece of data in memory, which happened to be not in the cache, so we went to the guy in memory for the data. As you know, that guy is always very slow. We were idle, so we relaxed a little bit."

After listening to my words, the leader frowned. "give me back the sophistry, isn't the out-of-order execution technology used in the factory now? if you have this spare time, you can carry out the following instructions first."

"of course we know that. You see, we also dealt with the last few instructions, and now we stopped when we encountered an instruction that could not be executed in advance."

The leader looked at it and asked, "Why can't that article be implemented in advance?"

"that's an addition instruction, and the addition depends on the result of the instruction being processed right now, so the memory guy doesn't get a message, so we have to put it on hold," I continued.

After hearing this, the leader left with an unhappy look on his face.

After a few days of idle resources, the leader came to our No.1 workshop again, and I don't know what happened. There are obviously eight workshops, and the leader always likes to run to us.

But this time, instead of fighting the landlords, we are working hard.

At that time, I was performing a floating-point operation, and the leader came over to have a look, patted me on the shoulder and said, "Yo, Ah Q, I'm busy. What are you doing?"

I smiled and said, "good leader, I have just done a floating-point multiplication with a floating-point arithmetic circuit unit, and I am waiting for the result of the calculation."

The leader nodded, looked around, pointed to a pile of equipment and asked, "what is this pile?"

"Oh, that's an integer operation circuit unit. You don't need it for this instruction."

The leader nodded again and left thoughtfully.

A few days after the hyperthreading technology, a meeting was held in the factory, and representatives from all eight workshops attended.

At the meeting, the leader said: "some time ago, I visited various workshops and found that the waste of resources in our factory is very serious!"

Huzi in the No.2 workshop couldn't sit still as soon as he heard this. "Leader, we all work very hard, where is there any waste?"

The leader glanced and continued: "on the one hand, the computing resources-circuit equipment in the factory are not fully utilized, on the other hand, because of slow memory reading, instruction dependence and other reasons. Waste too much time waiting."

The representative of the eighth workshop has always been brown-nosing, and then the leader asked, "what are the instructions from the leader?" our No. 8 workshop is absolutely supportive! "

"after discussion, several of our management have decided to change your workshop from one thread to two threads!"

As soon as the leader said this, the meeting room whispered one after another. Tiger whispered to me, "this capitalist can't change the nature of exploitation, and it's squeezing too hard!"

The leader coughed a few times, and the meeting quieted down again.

I got up and asked, "Leader, how can we execute two threads in a workshop? there is only one set of registers in each workshop. Isn't it messy to use it?"

"you don't have to worry about that. We'll give each workshop two sets of registers!"

As soon as the representative of the No. 5 workshop heard, "Why don't you give us some more manpower, so the efficiency will certainly improve quickly!"

The leader laughed and said, "more manpower?" would you like some more computing equipment? then I might as well add a few more workshops, why hold this meeting? the theme of this meeting is how to make the best use of our existing resources and reduce waste! "

The meeting was once in an awkward and tense atmosphere.

Or Huzi broke the silence, "Leader, how to carry out the work of these two threads, we do not count ah!"

The leader smiled with satisfaction: "this is the question you should ask!" Each workshop goes back and redistributes the work, divides into two sets of teams, each maintains a set of registers, and claims that you are two different physical cores, but each workshop still has only one set of cache and computing resources. You coordinate internally and make full use of the waiting time to execute instructions from another thread when executing code instructions, so that you don't have to worry about instruction dependency. "

Everyone was listening while taking notes.

"also, if you encounter idle resources, you can also execute instructions from two threads at the same time. For example, if a thread executes integer operation instructions and a thread executes floating-point operation instructions, we can work together to make full use of the factory's computing resources and not to be idle."

Seeing that we all took notes carefully, the leader smiled with satisfaction, "remember it all, we have a cool name for this revolutionary technology, called hyperthreading technology!"

After the meeting, everyone complained one after another, forcing everyone so hard that it seemed impossible to fish at work in the future. This day is really getting harder and harder.

There is mixed praise for hyperthreading, but if you complain, you still have to follow the new rules.

Soon, the factory on the ground of this technology, we a workshop transformed into two, our original eight-core eight-thread CPU into eight-core sixteen threads. The operating system people were deceived by us and thought we were sixteen-core CPU!

However, after all, there is only one share of computing resources, and when two threads have to use the same computing unit, they still have to queue up and spend time on the coordination work before the two threads, so the overall work efficiency is not twice as high at all. in most cases, it would be nice to increase by 20% and 30%.

Not only that, after the transformation of the workshop, a new logic circuit unit has been added, the power consumption of our CPU factory is also higher, and the huge fan at the factory gate has to increase its horsepower to cool us down.

Opposition to the technology began to be heard in the factory.

But then something happened that forced people to turn off the technology. Hearing the news, we all blossomed with delight, and it seems that we can continue to fish again.

Whenever a network packet arrives, the guy in the network card tells us to deal with it by interrupting CPU.

But we obviously have eight workshops, and it has to keep interrupting our workshop, so that we can't work well.

Finally, I can't help it.

To predict what will happen in the future, please pay attention to the wonderful future.

Description:

Hyper-threading technology actually appeared earlier than multicore technology. This story is only for narrative convenience and does not represent the true order of development of the two.

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