Jump to content

Hyper-threading

From Wikitech

A great way to troll Ops is to bring up Hyper-threading. So let's document the debate and situation.

History

Once upon a time, HT was a new feature which Linux did not support well, due to the similarities and differences between SMP and HT. For this reason the conventional wisdom has been to disable HT in the BIOS.

However that was over 10 years ago, HT is now well supported on Linux, and the question becomes one of suitability to a workload.

Security

A security issue was raised back in 2005 concerning HT. FreeBSD disabled HT in the kernel to mitigate the issue. The Linux kernel community did not. Interesting discussion in:

https://web.archive.org/web/20121230034701/http://kerneltrap.org/node/5120

The original security disclosure is in:

http://www.daemonology.net/hyperthreading-considered-harmful/

Performance claims

HT is said to increase performance of multi-threaded code by doubling the number of threads executed in parallel. That claim is regularly contested though:

http://www.extremetech.com/computing/133121-maximized-performance-comparing-the-effects-of-hyper-threading-software-updates
http://www.pugetsystems.com/blog/2014/07/02/Hyper-Threading-may-be-Killing-your-Parallel-Performance-578/

Drawbacks

HT is said to decrease performance of HPC-style compute-intensive workloads such as floating point calculations. Links above apply as well for this.

Current practice

  • Most clusters have a mix of HT enabled/disabled hosts. This is a defect.
  • Platform-specific documentation continues to say to disable HT during initial setup, but doesn't explain why

Checking

Slow:

 sudo lshw -class cpu | grep config

Better:

 cat /sys/devices/system/cpu/cpu0/topology/thread_siblings | grep -q ',00000001$' && echo DISABLED || echo ENABLED

More detail:

 #!/bin/bash
 
 CPUFILE=/proc/cpuinfo
 test -f $CPUFILE || exit 1
 
 # get number of physical CPUs
 NUMPHY=`grep "physical id" $CPUFILE | sort -u | wc -l`
 # get number of logical CPUs
 NUMLOG=`grep "processor" $CPUFILE | wc -l`
 # get number of cores per physical
 NUMCORE=`grep "core id" $CPUFILE | sort -u | wc -l`
 # calculate number of logical cores per physical core
 let NUMHTS=$NUMLOG/$NUMPHY/$NUMCORE
 
 if [ $NUMHTS -gt 1 ] ; then
   echo "HT=ON ($NUMLOG logical / ($NUMPHY physical * $NUMCORE cores each) = $NUMHTS logical per core)"
 else
   echo "HT=OFF ($NUMLOG logical / ($NUMPHY physical * $NUMCORE cores each) = $NUMHTS logical per core)"
 fi

Potentially this Puppet Facter Fact could also be extended to report HT status:

See also