Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Looking for ways to detect Hyper Threading

missing__zlw
Beginner
303 Views

Hi,

I am loking for ways to detect hyper threading in c++ program on Linux. I don't intent to read /proc/cpuinfo file.

I have tried cpuid and then edx value, somehow, it returns the same value on machines with HT and without HT.

It seems some cpucounter program on web is not working for intel64. 

I am using 64 bit Linux machine with :

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 45
model name : Intel(R) Core(TM) i7-3960X CPU @ 3.30GHz

...

Thank you.

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
303 Views
The question becomes: Do you want completely portable code? IOW to older generations of Intel and non-Intel (AMD?) archetectures than your Intel(R) Core(TM) i7-3960X CPU Also, there is a potential issue should you have a multi-socket system where some sockets have HT (enabled) and others do not. You might start by consulting Google: "detecting multi-core processor topology" site:intel.com format:.pdf *** open the.PDF file link(s) not the non-pdf file (html) link *** the Intel site has wrong hyperlinks in (bmunged up in update) Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
303 Views
GRIPE Unable to post comments with simple formatting such as blank lines and white space on left side for indentation And NO I am not willing to accept having to type in HTML tags. This is a general purpose programmers forum (e.g. C++, FORTRAN, etc), not a web designer/programmer forum (HTML, HTML6). Jim Dempsey
0 Kudos
SergeyKostrov
Valued Contributor II
303 Views
>>...I have tried cpuid and then edx value, somehow, it returns the same value on machines with HT and without HT... I have two test-cases that use CPUID instruction and I didn't have any problems with detecting HTT: ... const RTuint _HTT_FEATURE_BIT = 0x10000000; // 00010000000000000000000000000000 ... MOV eax, 1 CPUID MOV uiFeatureRegCX, ecx MOV uiFeatureRegDX, edx if( ( uiFeatureRegDX & _HTT_FEATURE_BIT ) { return ( RTbool )RTtrue; } ... Did you check a 28th bit of EDX register?
0 Kudos
Reply