Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
for dmidecode you have to be root. – Nils Mar 5 '12 at 20:50
I like how everyone ignored the "perl script" bit ;-) – SamB May 30 '14 at 20:32
up vote 13 down vote accepted

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.)

share|improve this answer
This will only tell you if the processor is HT capable, not if HT is actually being used. – Riccardo Murri Apr 23 '14 at 18:00
the HTT field does not indicate that the processor is actually having hyperthreading in its cores. check the value of 'siblings' and 'cpu cores' in /proc/cpuinfo – Silver Moon Jun 29 '14 at 9:05
@Silver-Moon Can you explicate? dmidecode reads the SMBIOS and should tell the capabilities of the processor. It does not tell whether hyper-threading is seen or used by the O/S. But this has already been commented on. See also Nils answer – xebeche Jul 3 '14 at 19:09
@xebeche on my system dmidecode output shows "HTT (Multi-threading)" but my processor is "core 2 quad Q8400" which does not have hyperthreading. check intel specifications. – Silver Moon Jul 4 '14 at 3:13
@SilverMoon Then you should report a bug against dmidecode. – xebeche Jul 5 '14 at 13:41

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
share|improve this answer
This is the best answer yet. It requires no reading of the tea leaves, lots of helpful information, and no grepping required. – MrMas Dec 11 '15 at 19:48

If the number of logical processors is twice the number of cores you have HT. Use to following script to decode /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 ]
    echo This system has one physical CPU,
    echo This system has $NUMPHY physical CPUs,
if [ $NUMLOG -gt 1 ]
    echo and $NUMLOG logical CPUs.
    NUMCORE=`grep "core id" $CPUFILE | sort -u | wc -l`
    if [ $NUMCORE -gt 1 ]
        echo For every physical CPU there are $NUMCORE cores.
    echo and one logical CPU.
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"
share|improve this answer
If $NUMCORE > $NUMLOG we can say that hyperthreading is enabled, right? It fact it would be 2 * $NUMCORE = $NUMLOG, is this always true or some CPUs might have 4x more cores? – Tombart Mar 13 at 17:24
@Tombart Currently HT is factor 2. I can imagine that it might be more in the future. A core is noted as physical. The number of cores per socket can be derived from siblings. – Nils May 5 at 21:22

You can check HT capability of CPU with this command

# grep ht /proc/cpuinfo

You can list physical and logiciel CPU seen by Kernel with the following command:

# egrep -i "processor|physical id" /proc/cpuinfo

It gives this output on a single-core HT enabled CPU:

processor   : 0
physical id : 0
processor   : 1
physical id : 0

You can read the result like this:

processor   : 0 (CPU 0, first logical)
physical id : 0 (CPU 0 is on the first physical)
processor   : 1 (CPU 1, second logical)
physical id : 0 (CPU 1 is on the first physical)
=> It means I have HT enabled
share|improve this answer
This will only tell you if the processor is HT capable, not if HT is actually being used. Nodes whose processor is HT-capable but where HT is not enable will still advertise ht in the CPU flags. – Riccardo Murri Apr 23 '14 at 18:01
@RiccardoMurri As far as I know, when HT is disabled, ht flag does not appear in /proc/cpuinfo – Coren Apr 24 '14 at 9:48
I'm pretty sure it's not. I have both HT-enabled and HT-disabled servers, and all of them show the ht flag. – Riccardo Murri Apr 25 '14 at 10:32
If you have a Xeon processor with 4 cores, it will show as one physical id and four processors. So you can have multiple processors per physical id without hyperhtreading. – Andomar Nov 9 '14 at 11:39
I've got a 2 socket machine, and the physical id seems to represent the socket/chip. The core id seems to point to the same physical core – Heartinpiece Jul 8 '15 at 3:11

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 Xenserver where it doesn’t display Physical CPU, since there are none.

I found this to be the easiest and less code way, which also worked on all my test environments. but requires bc.

echo "testing ################################### "

nproc=$(grep -i "processor" /proc/cpuinfo | sort -u | wc -l)

phycore=$(cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l)

if [ -z "$(echo "$phycore *2" | bc | grep $nproc)" ]


echo "Does not look like you have HT Enabled"

if [ -z "$( dmidecode -t processor | grep HTT)" ]


echo "HT is also not Possible on this server"


echo "This server is HT Capable,  However it is Disabled"



   echo "yay  HT Is working"


echo "testing ################################### "

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?

share|improve this answer

This one liner seems to do the trick for me (requires root privileges):

dmidecode -t processor | grep -E '(Core Count|Thread Count)'

The output is:

Core Count: 2
Thread Count: 4

Thread count is double the core count, therefore I have hyperthreading enabled.

Or if you really want your perl script, as requested...

perl -e 'print grep(/Core Count/ || /Thread Count/, `dmidecode -t processor`);'
share|improve this answer
I have HT turned off on an Intel based HT capable system, yet Thread Count returned with dmidecode is twice the Core Count. Looks like it shows if the CPU is HT capable, not if HT is enabled or not. – Dmitri Chubarov Dec 16 '15 at 13:58
@Dmitri Weird. I just ran this on an HT-capable server (has two Intel Xeon E5-2670 v3's) with hyperthreading disabled, and the core and thread count were the same. I'm not sure what would cause the difference in behavior. I'll have to look further into it. – billyw May 26 at 17:10
perl -ne'
  $i++ if /^\s*$/;
  push @{$x[$i]}, [/^(.+?) \s*:\s* (.+)/x] if /core|sibling|physical id/; }{
  $r= shift @x; 
  for $i (0..$#$r) {
    $$r[$i][1] .= " ".$$_[$i][1] for @x;
    printf "%-15s: %s\n", @{$$r[$i]};
' /proc/cpuinfo

This result indicates that HT is enabled as siblings number (12) is greater than cpu cores (6)

physical id    : 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1
siblings       : 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
core id        : 0 1 2 8 9 10 0 1 2 8 9 10 0 1 2 8 9 10 0 1 2 8 9 10
cpu cores      : 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
share|improve this answer

Here's a python based approach - it also suggests ways to disable it if needed.

import re    

total_logical_cpus = 0
total_physical_cpus = 0
total_cores = 0

logical_cpus = {}
physical_cpus = {}
cores = {}

hyperthreading = False

for line in open('/proc/cpuinfo').readlines():
    if re.match('processor', line):
        cpu = int(line.split()[2])

        if not logical_cpus.has_key(cpu):
            logical_cpus[cpu] = []
            total_logical_cpus += 1

    if re.match('physical id', line):
        phys_id = int(line.split()[3])

        if not physical_cpus.has_key(phys_id):
            physical_cpus[phys_id] = []
            total_physical_cpus += 1

    if re.match('core id', line):
        core = int(line.split()[3])

        if not cores.has_key(core):
            cores[core] = []
            total_cores += 1


if (total_cores * total_physical_cpus) * 2 == total_logical_cpus:
    hyperthreading = True

print("  This system has %d physical CPUs" % total_physical_cpus)
print("  This system has %d cores per physical CPU" % total_cores)
print("  This system has %d total cores" % (total_cores * total_physical_cpus))
print("  This system has %d logical CPUs" % total_logical_cpus)

if hyperthreading:
    print("  HT detected, if you want to disable it:")
    print("  Edit your grub config and add 'noht'")
    print("  -OR- disable hyperthreading in the BIOS")
    print("  -OR- try the following to offline those CPUs:")

    for c in cores:
        for p, val in enumerate(cores[c]):
            if p > 0:
                print("    echo 0 > /sys/devices/system/cpu/cpu%d/online" % (val))
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.