How does hyperthreading work?

hotelmariofan

Honorable
May 14, 2012
94
0
10,630
From what I understand, the different between two CPUs of the same kind, with one capable of hyperthreading, is that the amount of data feeding into the hyperthreaded CPU is doubled. It does not affect the amount of calculations taking place. Am I correct in thinking that or am I way off? Thanks in advanced.
 
Solution
Hyperthreading takes advantage of the highly modular nature of modern CPUs and the fact that, for most workloads, they have a surplus of resources.

For example, a CPU core may have several "modules" (execution units) for doing basic integer (whole number) maths and logic, several for doing more advanced maths, several more for loading and storing data from/to memory and so on.

Without hyperthreading, the core will read in the program from memory on demand and attempt to make best use of as many of those modules as possible by analysing the program code to try and determine which parts of it can be done at the same time and which parts depend on the outcome of others and have to wait until the other parts have been completed. The usual...

ThomasJ93

Honorable
Apr 10, 2013
597
0
11,160
Hyperthreading is a technology that allows a core of a CPU to handle two threads or processes at the same time. In a way you could see a quadcore CPU with HT as an octacore. The virtual cores provided by HT aren't as fast as an actual core though.
 

molletts

Distinguished
Jun 16, 2009
475
4
19,165
Hyperthreading takes advantage of the highly modular nature of modern CPUs and the fact that, for most workloads, they have a surplus of resources.

For example, a CPU core may have several "modules" (execution units) for doing basic integer (whole number) maths and logic, several for doing more advanced maths, several more for loading and storing data from/to memory and so on.

Without hyperthreading, the core will read in the program from memory on demand and attempt to make best use of as many of those modules as possible by analysing the program code to try and determine which parts of it can be done at the same time and which parts depend on the outcome of others and have to wait until the other parts have been completed. The usual result is that some of the execution units end up sitting idle because, in most cases, it is not possible to split the work into sufficient pieces of the right kinds of tasks to use all of the modules.

With hyperthreading, the core will present itself to the OS as two virtual cores. This allows it to read in two programs from memory (effectively) simultaneously. The two streams are analysed in the same way as before but, because they are separate programs that don't depend on each other's immediate outcomes, there are more opportunities to share out the work and do things at the same time. This way, more of the core's execution units can be kept busy.

A single core with hyperthreading will not be as quick as two real physical cores because there will be times when both programs want to use the same part of the core and the available resources will end up being split between them but in many cases, the variety of different operations that are performed in normal programs means that these "collisions" (resource contention) don't hurt performance too much. Modern HT-capable processors have very good schedulers and are heavily over-provisioned with resources so even when two similar tasks are being run, the performance penalty is relatively small. Older CPUs, such as the Pentium 4 HT, suffered a greater penalty from resource contention and had other disadvantages when HT was enabled, such as splitting the cache between the two threads rather than having a single shared cache and dividing a single register file (the processor's "short term memory") between them instead of having separate dedicated register files.

It is possible to optimise for hyperthreading if performance is a real issue (high-performance computing, for example) by advising the OS scheduler that certain tasks should be run on certain virtual cores to ensure that, for example, of the two virtual threads on one core, one is mostly doing integer maths and the other is mostly doing floating-point maths. This is generally not worth the effort for everyday workloads, though, as it can end up having the opposite effect and reducing performance unless the code is written with this kind of strategy in mind.
 
Solution