5 Answers
5

This is marketed by Intel as hyperthreading and has been done in various ways over the years by various different manufacturers.

To explain it in its simplest form each CPU core consists of a "core" and various architecture around that core that keeps state and process information for each thread. A single threaded core has the architecture to keep 1 thread worth of state information held at a time, a hyperthreaded core keeps two distinct sets of state information, allowing two separate processes to run at once as long as they require different parts of the core (which is reasonably likely to happen as the core consists of multiple units of multiple different types of processing unit).

To simplify how the CPU is seen to the system each hyperthread is seen as a separate CPU, so a dual core, 2 thread per-core processor appears as a quad core processor.

It is also possible for the operating system to use Core-parking (a feature in newer Intel processors) allows the operating system to suspend one half of a hyperthreaded core so that when the extra processing ability of hyperthreading is not needed then the single thread performance is increased as the core is no longer sharing it's cache across 2 threads and can now fully devote the on-core cache to a single thread.

Thanks for the explanation. So, can we say here that a thread is to a core what a core is to a processor?
–
seriousdevAug 30 '11 at 16:37

2

In a way, yes. The OS sees the processor, knows how many cores are on that processor and in turn how many threads each core supports, from that the CPU usage you are seeing is now "per-thread" rather than "per core". It's not quite that simple (as each thread does actually appear to a non-hyperthreading aware OS as a fully fledged CPU core) but that is the general idea of it.
–
Mokubai♦Aug 30 '11 at 16:46

Things are a lot more complex than they were in the days of one cpu instruction per one clock cycle.

There's now a pipeline for each instruction that consists of a number of steps. I've heard as many as 41, though that was a while ago and I have no idea what current cpu pipelines look like. I do know that if the pipeline is long enough, you can start a new instruction down the pipeline before the last instruction has finished, sometimes in the same clock cycle, so that your single core is effectively doing two things at once.

There's a trick here, though. You can't just use this to speed up the rate at which your processor chews through instructions from a specific program. There's a correctness issue involved: the next instruction might depend on the as-yet-undetermined result of the prior instruction. To take advantage of the long pipeline safely, the chip will present two separate processor cores to the operating system scheduler, and alternate instructions sent to each core so that two instructions to the same "core" are never in the pipeline at the same time. This way it we can be sure that any instructions executed simultaneously will not interfere with each other. This is called hyperthreading.

It's worth noting here that while hyperthreading can significantly increase the amount of work you get out of your cpu, it's nowhere near as good as having that many physical cores. Depending on your work-load, it might means as little at 15% improvement or as much as 40% improvement. In some circumstances, you may even want to disable the feature so that the remaining cores have full exclusive access to the L1/L2 cache for that core (this is sometimes done with dedicated database servers).

When your chip advertises itself as having 2 cores with 4 threads, that means it's a dual core processor that supports hyperthreading.

Why is this? Is it because there are 2 threads per core, dividing the
CPU in 4 processing units?

Putting this simply, the answer is yes. Each core of your cpu can support two independent threads, so 4 in total. But it doesn't mean it has the same performance as a quad-core single-threaded cpu.
practically the performance of a dual-core double-threaded cpu is lower than that of a quad-core single-threaded cpu. Like the AMD Phenom X4.

The reason is that in a double-threaded core the hardware resources (like reorder buffer) is shared between two threads, while in a single-threaded cpu all resources are dedicated to one core. It's worth mentioning that having a mulch-threaded core increases your hardware utilization and throughput, but it's bad for latency. There are many trade-offs involved. So the word "performance" is really vague here. For ordinary people it means the latency of a single thread.
–
aminfarAug 30 '11 at 22:17

The reason is hyperthreading, which your processor supports. Hyperthreading isnt the equivalent of an extra processor, but can really boost performance on multithreaded applications. For each processor core that is physically present, the operating system addresses two virtual processors, and shares the workload between them when possible.

@Keltari actually, there is a physical part to it... Hyperthreading is a hardware component in a CPU core (and can only be disabled on a hardware level). See this Intel whitepaper for details. Basically, it shares a core's resources between two physical execution units. Technically, both cores seen by the OS in a hyperthreaded core are "logical", there isn't both a physical and logical one.
–
BreakthroughAug 30 '11 at 19:53

1

true, hyperthreading is a physical part of the processor, but not a physical core.
–
KeltariAug 30 '11 at 19:55

1

The best way to think of HT is a "core-and-a-half" it shares many more resources with its brother than the seperate cores do. However it is capable of executing a thread "on its own" and the OS treats it as a thread execution unit (which you associated with a core).
–
crasicAug 31 '11 at 0:22