How can I check if hyperthreading is enabled on a Linux machine, using a perl script to check for it?
I'm trying the following way:
dmidecode -t processor | grep HTT
Let me know if I'm on right track.
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
On Linux, I generally just look for "ht" on the "flags" line of
or if you want to include the "ht" in the pattern
You can check HT capability of CPU with this command
You can list physical and logiciel CPU seen by Kernel with the following command:
It gives this output on a single-core HT enabled CPU:
You can read the result like this:
If the number of logical processors is twice the number of cores you have HT. Use to following script to decode /proc/cpuinfo:
The above examples show if the CPU is capable of HT, but not if it is being used.
The last method works but not dual socket servers and VMs tested on
I found this to be the easiest and less code way, which also worked on all my test environments. but requires
I believe this will work on all platforms, and will tell you if its CPU is capable, and if it is enabled. May be a little messy, I'm a beginner at scripting though. I tested with centos XENSERVER vm, Ubuntu, and Openfiler (rpath)
I have a similar cool script here, would like to see what you think?
This one liner seems to do the trick for me (requires root privileges):
The output is:
Thread count is double the core count, therefore I have hyperthreading enabled.
Or if you really want your perl script, as requested...