Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hyperthreading vs. changing ProcessorAffinity?

I have noticed that several of my multi-threaded calculations run faster if I disable hyper-threading in the BIOS.

I have also learnt that I can programmatically disable the (logical) CPU:s by modifying the processor affinity for the current process, for example like this in C#:

// using System.Diagnostics;
var current = Process.GetCurrentProcess();
var affinity = current.ProcessorAffinity.ToInt32();
current.ProcessorAffinity = new IntPtr(affinity & 0x5555);

At least from a performance point of view, will disabling every second (logical) CPU by changing processor affinity have the same effect as disabling hyperthreading altogether?

like image 979
Anders Gustafsson Avatar asked Jun 07 '12 11:06

Anders Gustafsson


People also ask

Is hyperthreading worth disabling?

There has been some speculation that hyperthreading on Intel CPU can make your system vulnerable to hacks. Intel claims that this is not the case. But regardless of security issues, it's best to disable this feature if you want to avoid straining from your CPU.

Does disabling hyperthreading improve performance?

There is no definitive answer to this question as it depends on the game and the system that it is being played on. Some games may see a slight increase in performance when hyperthreading is disabled, while others may not see any difference.

Does disabling hyperthreading reduce temps?

For multithreaded workloads that completely use all cores, HT will make the CPU about 20% faster and also use about 20% more power. In that case disabling it will reduce temperatures.

Is enabling hyperthreading good?

Will Hyperthreading Boost The Performance? For a single socket system, hyper-threading can boost system performance by up to 30%. For dual socket systems, hyper-threading can boost performance by up to 15%. For quad-socket (or higher) systems, performance testing with and without hyper-threading enabled is recommended.


1 Answers

You can try utilizing the NUMA APIs, or manually discover CPU topology with the CPUID instruction... But IMHOthe best solution is doing some sane defaults, and let the end-user tweak threading settings. Unless you have a specific hardware target, there's a fair amou t of possible scenarios to handle - logical vs. physical cores, hyper-threading or not, single- vs. multi-socket systems, cache and memory topology.

like image 181
snemarch Avatar answered Sep 30 '22 17:09

snemarch