52

I've heard the term hyper-threading thrown around a bit recently, what exactly is hyper-threading and why is it important?

1
48

Hyper-threading is where your processor pretends to have 2 physical processor cores, yet only has 1 and some extra junk.

The point of hyperthreading is that many times when you are executing code in the processor, there are parts of the processor that is idle. By including an extra set of CPU registers, the processor can act like it has two cores and thus use all parts of the processor in parallel. When the 2 cores both need to use one component of the processor, then one core ends up waiting of course. This is why it can not replace dual-core and such processors.

3
  • 7
    +1 should add that hyper-threading is specific to Intel's implementation of SMT e.g. the SPARC processor has a different form of SMT implemented but with similar goals. – sybreon Mar 22 '10 at 2:20
  • 1
    @Earlz are you suggesting that the processor is running two threads by dividing the cores in two? or is it looks like parallelism made in reality hyperthreading is causing processor to switch from one thread to another? – Doopy Doo Oct 13 '12 at 11:17
  • 5
    @DoopyDoo neither. Basically the processor has two "execution cores", which is the pipeline for instructions and such and it also has two sets of registers and other essential things.. The difference between hyper-threading and regular dual-core though is that some things are NOT duplicated. For instance, there may only be one ALU. So, this would mean while a dual-core processor can add two separate sets of numbers together at the same time, for a hyper-threading processor will have to make one of the virtual-cores wait until it's turn with the ALU.. Of course, this is a simplified example – Earlz Oct 13 '12 at 18:05
16

Hyper-Threading is where two threads are able to run on one single-threaded core. When a thread on the core in question is stalling or in a halt state, hyper-threading enables the core to work on a second thread instead.

Hyper-threading makes the OS think that the processor has double the number of cores, and often yields a performance improvement, but only in the region of 15-30% overall - though in some circumstances, there may actually be a performance hit (=<20%).

Currently, most Atom chips and all i7 (and Xeon-equivalent chips) have hyper-threading, as did some older P4s. In the case of the Atoms, it's a desperate attempt to improve performance without increasing power consumption much; in the case of i7s, it differentiates them from the i5 range of chips.

Complex processing work won't benefit much from HT, but certain (simple, highly multi-threaded) tasks, such as video encoding, benefit from HT. In reality, there is not a lot in it...

1
  • 1
    95% correct. If a normal core = A + B then a hyper-threading core is more like A + 2 x B. They CAN execute two threads simultaneously as long as both threads don't need A. – Vincent Vancalbergh Jul 5 '13 at 15:08
9

To expand on what's already been said, hyperthreading means that a single CPU core can maintain two separate execution contexts and quickly switch between them, effectively emulating two cores at a hardware level.

You get a modest speed benefit for multi-threaded workloads when compared to a normal, single core. However, it is nowhere near the benefit of having two independent cores. In terms of performance you're best to think of it as a small boost in multi-threaded performance over a single core rather than as having performance approaching two cores. The size of the speed boost varies according to workload - indeed for some workloads the performance boost is quite decent.

The hyperthreaded core only has one main execution unit, but certain other parts of a CPU associated with readying instructions for processing and maintaining an execution state are duplicated.

Processor cores have an instruction pipeline - a queue of future instructions to be executed, that is constantly being updated, ready for the CPU to execute the instruction at the head of that queue. CPUs use these to optimise execution speed by looking at these future instructions and doing some simple, low-level pre-processing on them where possible (such optimisations include "out of order execution" and "branch prediction").

Hyperthreaded cores have dual instruction pipelines, and this - along with a second set of registers - is where you get the speed benefit for multithreaded workloads.

Let's say your system is running a number of different threads at once. Your system allocates each thread to a virtual processor, and that thread will share the virtual processor with other threads, but each time the virtual processor switches between these threads, it has to basically discard that thread's whole execution context and load up another thread's.

But with hyper-threading, instead of your core only being able to retain one thread's state at any given time, you gain the ability for that core to retain two threads' execution states at once, so you can switch between those two with much less penalty because it does not throw out the pipeline or registers, and the pipeline and registers for the other thread remains ready and "hot" so they can be switched to and used immediately. If you are running more threads than virtual processors, you still need to do hard switching, but less often since you have a greater number of threads at a given time whose execution state is preserved.

6

When a Single Core can act as a Dual Core

it is Hyperthreading

In Detail

Intel’s implementation of Simultaneous Multi-Threading is known as Hyper-Threading Technology, or HT Technology.

HT Technology makes a single processor appear, from software’s
perspective, as multiple logical processors. This allows operating systems and applications to schedule multiple threads to logical processors as
they would on multiprocessor systems.


Hyperthreading allows a Single Processor to execute two threads simultaneously, but not on all conditions.

Hyperthreading does not double the performance of a system, it can increase performance by better utilizing idle resources leading to greater throughput for certain important workload types. An application running on one logical processor of a busy core can expect slightly more than half of the throughput that it obtains while running alone on a non-hyperthreaded processor. Hyperthreading performance improvements are highly application-dependent, and some applications might see performance degradation with hyperthreading because many processor resources (such as the cache) are shared between logical processors.

Intel Hyper-Threading technology makes each core can have two logical processors which share most of the core's resources, such as memory caches and functional units

Main function

of Hyperthreading is to increase the number of independent instructions in the pipeline; it takes advantage of superscalar architecture, in which multiple instructions operate on separate data in parallel

Intel says that hyper-threading is highly efficient because it uses resources that would otherwise be idle or underutilised.

Links:

Wikipedia
StackOverflow
Multi-Core Programming Digital_Edition pg #8

enter image description here

Intel Image

-1

As I understand it, let's look at a little example, which isn't really true to life, but emphasises the point...

Say we have a CPU, who shall be referred to as Todd from now on.

Todd also has several arms, let's say four (much like Tom Woodruff Jr. Goro). These are Todd's version of a CPU's logic gates.

Finally, Todd only has one ear, so can only hear one command at a time. This is Todd's life without hyperthreading, so one core is still just one core.

Todd, being the clever thing he is, can carry out four independent tasks simultaneously, one task with each of his four arms, but as he only has one ear, he can only hear one instruction at a time.

Now, some instructions might require him to use all of his limbs to complete the task, but quite a lot of instructions might just need him to use his upper-left arm. That's pretty inefficient! The other arms are just sitting idle most of the time.

If we give Todd a second ear (so he looks nice and symmetrical now), he can receive two instructions at a time.

This is great, because if one instruction only wants him to use his upper-left arm, but another instruction needs him to use both of his right arms, then he can complete both operations simultaneously! That's doubled his efficiency at completing tasks! Awesome!

Now... I know what you might be thinking; what about if one instruction wants him to use all of his arms, and a second instruction wants him to use both left arms?

Well, unfortunately Todd was gifted an extra ear, but no extra arms, so in this case the second instruction will have to wait, and he's no more (or less) efficient than when he only had one ear.

So there you have it, the story of how Todd, our mutant CPU impersonator can artificially improve efficiency (i.e., performance), without being given any extra arms.

Not the answer you're looking for? Browse other questions tagged or ask your own question.