Checking if HyperThreading is enabled or not?
I have always just used the following and looked at 'Thread(s) per core:'.
hostname:~ # lscpu
Architecture: x86_64
CPU(s): 24
Thread(s) per core: 2 <-- here
Core(s) per socket: 6
CPU socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 44
Stepping: 2
CPU MHz: 1596.000
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
Note, however, this technique will fail if any logical processor has been turned off with a simple
echo 0 > /sys/devices/system/cpu/cpuX/online
Notes added on July 8, 2014: As Riccardo Murri pointed out, my answer below only shows whether the processor reports to support hyperthreading. Generally, *nix O/S are configured to enable hyperthreading if supported. However, to actually check this programmatically see for instance Nils' answer!
---- Original answer from March 25, 2012:
You are indeed on the right track :) with
dmidecode -t processor | grep HTT
On Linux, I generally just look for "ht" on the "flags" line of /proc/cpuinfo
. See for instance
grep '^flags\b' /proc/cpuinfo | tail -1
or if you want to include the "ht" in the pattern
grep -o '^flags\b.*: .*\bht\b' /proc/cpuinfo | tail -1
(\b
matches the word boundaries and helps avoid false positives in cases where "ht" is part of another flag.)
If the number of logical processors is twice the number of cores you have HT. Use to following script to decode /proc/cpuinfo:
#!/bin/sh
CPUFILE=/proc/cpuinfo
test -f $CPUFILE || exit 1
NUMPHY=`grep "physical id" $CPUFILE | sort -u | wc -l`
NUMLOG=`grep "processor" $CPUFILE | wc -l`
if [ $NUMPHY -eq 1 ]
then
echo This system has one physical CPU,
else
echo This system has $NUMPHY physical CPUs,
fi
if [ $NUMLOG -gt 1 ]
then
echo and $NUMLOG logical CPUs.
NUMCORE=`grep "core id" $CPUFILE | sort -u | wc -l`
if [ $NUMCORE -gt 1 ]
then
echo For every physical CPU there are $NUMCORE cores.
fi
else
echo and one logical CPU.
fi
echo -n The CPU is a `grep "model name" $CPUFILE | sort -u | cut -d : -f 2-`
echo " with`grep "cache size" $CPUFILE | sort -u | cut -d : -f 2-` cache"