Why does the performance become bad after enabling hyperthread?

flypen picture flypen · May 15, 2012 · Viewed 14.8k times · Source

I port Linux kernel 2.6.32 to Intel(R) Xeon(R) CPU E31275 @ 3.40GHz. If I enable hyperthread in BIOS, I can see 8 CPU cores (CPU0 ~ CPU7). Most of interrupts occur in CPU 4, and the CPU usage of this core is much higher than others (almost twice than others). I don't understand it very well, because I think I didn't set any IRQ binding operations.

If I disable hyperthread in BIOS, then everything is OK. The IRQs have been balanced, and the CPU usage of all cores (CPU0 ~ CPU3) are nearly balanced, too.

Can someone explain it? Is it BIOS related? Should I do some special settings in kernel?

Answer

K1773R picture K1773R · May 15, 2012

Some programs get a negative effect from HT (Hyper Threading), to explain this you have to understand what HT is. As you said you saw 7 (0-7 is altough 8) cpu cores, this is not true, u have 4 cores in your CPU, the 8 cores are virtual cores, so one core has 2 threads (and acts like he is 2 cores). Usually HT helps for running programs faster due to the fact the CPU/OS is able to run (doing what ever these programs do) 8 programs at the same time, without HT you can only run 4 at the same time. You dont have to set any settings since you cant change this appearance, if you are the developer of this program you should recheck the code and optimize it for HT if you want, or you can just disable HT.

Another information due to some bullshit peoples are talking: HT is increasing the power of the CPU this is NOT true! even when u see 8 cores with lets say 4GHz (GHz says nothing, should be measured in flops) you got the same power as when u turn HT of and got 4 cores with 4GHz. If you got HT on the 2 virtual cores are sharing 1 physical core from ur CPU.

Here some more informations about HT: http://www.makeuseof.com/tag/hyperthreading-technology-explained/

I couldnt find my old link to a very nice site where there are code snippets who shows bad code for HT and good code (in the meaning bad of being slower than without HT and the opposite).

TL;DR: not every program benefetis from HT due to its development.