# hyperthreading

## nizar

Hello,

Is there any way to tell if hyperthreading is enabled or not?

thanks.

----------

## evoweiss

 *nizar wrote:*   

> Hello,
> 
> Is there any way to tell if hyperthreading is enabled or not?
> 
> thanks.

 

Type in cat /proc/cpuinfo. If you see it listing two processors (0 and 1), it's enabled.

Best,

Alex

----------

## nizar

 *evoweiss wrote:*   

>  *nizar wrote:*   Hello,
> 
> Is there any way to tell if hyperthreading is enabled or not?
> 
> thanks. 
> ...

 

And what if I really have two physical CPUs?!

----------

## The Unlimited

If you have two physical CPUs which support hyperthreading than it should say that you have 4 CPUs.

----------

## nizar

 *The Unlimited wrote:*   

> If you have two physical CPUs which support hyperthreading than it should say that you have 4 CPUs.

 

Yes I know that, I'm looking for more!!!

1st situation:

A machine with one PHYSICAL CPU with hyperthreading enabled, /proc/cpuinfo will report about 2 CPUs.

2nd situation:

A machine with two physical CPUs without hyperthreading disabled, /proc/cpuinfo will report about 2 CPUs.

I need to know how many physical CPUs in the system!

----------

## niltonvolpato

nizar,

See this page: http://www.intel.com/support/processors/sb/cs-009861.htm.

Using the cpuid instruction you can tell if the processor is ht capable and has ht enabled.

You must call cpuid with eax=1 and if ebx[23:16] > 1 then ht is enabled.

See this C example code:

```
int main() {

   int op = 1;

   int _eax, _ebx, _ecx, _edx;

   asm ("cpuid"

   : "=a" (_eax),

   "=b" (_ebx),

   "=c" (_ecx),

   "=d" (_edx)

   : "a" (op));

   printf("ht capable: %d\n", (_edx & (1<<28)) >> 28 );

   printf("number of logical cpus: %d\n", (_ebx & 16711680) >> 16);

}

```

Tell me if it works, cheers,

-- NiltonLast edited by niltonvolpato on Thu Jun 16, 2005 7:47 pm; edited 1 time in total

----------

## nizar

 *niltonvolpato wrote:*   

> nizar,
> 
> See this page: http://www.intel.com/support/processors/sb/cs-009861.htm.
> 
> Using the cpuid instruction you can tell if the processor is ht capable and has ht enabled.
> ...

 

The link leads to nowhere!

I still don't understand the code since I don't know what asm is(Do you have  a good reference?), but here is the output from different systems:

1- Two physical CPUs with HT enabled(proc reports on 4)

ht capable: 1

number of logical cpus: 2

2- Two physical CPUs with HT disabled(proc reports on 2)

ht capable: 1

number of logical cpus: 2

3- 1 physical CPU with HT enabled(proc reports on 2)

ht capable: 1

number of logical cpus: 2

4- 1 physical CPU with HT disabled(proc reports on 2)

ht capable: 1

number of logical cpus: 1

So...!

thanks for the help.

----------

## kill

 *nizar wrote:*   

> The link leads to nowhere!

 

Delete the . at the end of it. That period is part of his sentence not the url.

----------

## niltonvolpato

I corrected the link.

I'm working on a code that will detect if HT is enabled. When it's finished I'll post it here.

The keyword asm is for inline assembly in gcc c/c++ code. See this, for example: http://www-106.ibm.com/developerworks/library/l-ia.html

-- Nilton

----------

## niltonvolpato

 *niltonvolpato wrote:*   

> I'm working on a code that will detect if HT is enabled.

 

In the meantime I think that this script script will detect if HT is enabled:

```
#!/bin/bash

NUMBER_LOGICAL_CPUS=$(cat /proc/cpuinfo | grep 'processor' | uniq | wc -l)

NUMBER_PHYSICAL_CPUS=$(cat /proc/cpuinfo | grep 'physical id' | uniq | wc -l)

if [ $NUMBER_LOGICAL_CPUS -ne $NUMBER_PHYSICAL_CPUS ]; then

   echo "HT enabled"

else

   echo "HT disabled"

fi
```

Hope this works,

-- Nilton

----------

## Travers

Hyperthreading? Look in your BIOS, stupid! =)

----------

## codergeek42

```
$ grep flags /proc/cpuinfo
```

If "ht" appears as one of the flags that means it can support HyperThreading(tm). /proc/cpuinfo should also tell you if what physical and logical CPU ID(s) are there. 

Cheers.

----------

## nizar

 *Travers wrote:*   

> Hyperthreading? Look in your BIOS, stupid! =)

 

It's stupid to reboot, insane =)

----------

## magic919

Try dmesg | grep Physical

For two processors HT you'll get

CPU: Physical Processor ID: 0

CPU: Physical Processor ID: 0

CPU: Physical Processor ID: 3

CPU: Physical Processor ID: 3

So you'll know it's 2 CPU all HT.

One CPU HT:

CPU: Physical Processor ID: 0

CPU: Physical Processor ID: 0

Etc

Easy  :Smile: 

----------

