Hyperthreading vs. SMP

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
How does the hardware communicate to the OS that the second "CPU" is not actually another processor, but instead hyperthreading is being used?

On a related note, could an OS like XP Home be tricked into believing that a computer with dual CPUs is actually a hyperthreaded single-processor system?
 

sao123

Lifer
May 27, 2002
12,656
207
106
I believe that a P4 with hyperthreading (and a hyperthread supported Mobo + Bios) actually reports it as 2 processors.
At least a screenshot I saw on xbitlabs.net showed WinXP pro as doing so.
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
AFAIK, sao123's reply is correct. As far as the OS knows (except maybe some very low-level HAL libraries in WinXP/NT), it's running on two processors. The hardware in the P4 itself handles all the internal scheduling.
 

Sunner

Elite Member
Oct 9, 1999
11,641
0
76
Originally posted by: Matthias99
AFAIK, sao123's reply is correct. As far as the OS knows (except maybe some very low-level HAL libraries in WinXP/NT), it's running on two processors. The hardware in the P4 itself handles all the internal scheduling.

The OS scheduler need to be SMT aware to schedule optimally, this becomes more apparent with 2+ CPUs(physical CPUs).
So it's not transparent.
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
But my point is that the scheduler doesn't care if it's running on 2 actual, honest-to-god physical CPUs, or one CPU that's pretending to be two. Or at least it doesn't *have* to. Of course, you can probably squeeze a few more % out of a HyperThreading-based system by scheduling things intelligently (for instance, trying not to schedule two threads that both need ALU access simultaneously), but this is (generally speaking) difficult if not impossible, as the OS often has no clue what a thread is about to do when it resumes. In most real-world situations, an optimal scheduler for two physical CPUs is also an optimal scheduler for one HT CPU core pretending to be two physical CPUs.
 

Sunner

Elite Member
Oct 9, 1999
11,641
0
76
It makes a big difference if the OS knows about virtual vs physical CPU's.
The most obvious reason is that if it has to execute two threads, the HT aware OS will let each physical CPU take care of one thread, while a non-HT aware OS might as well give the two threads to the two virtual CPU's on one of the physical CPU's.

There's a good post from Ingo Molnar here(kerneltrap.org on the subject.
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
Sorry, should have been more specific (I misunderstood what you meant by the last sentence in your first post). I agree that with *multiple* HT-enabled CPUs (ie, 4+ logical CPUs but fewer physical ones), these scheduling issues become more important. However, with just one HT-enabled processor, it makes little difference.
 

Sunner

Elite Member
Oct 9, 1999
11,641
0
76
Originally posted by: Matthias99
Sorry, should have been more specific (I misunderstood what you meant by the last sentence in your first post). I agree that with *multiple* HT-enabled CPUs (ie, 4+ logical CPUs but fewer physical ones), these scheduling issues become more important. However, with just one HT-enabled processor, it makes little difference.

Agreed :)