Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux find out Hyper-threaded core id

Tags:

I spent this morning trying to find out how to determine which processor id is the hyper-threaded core, but without luck.

I wish to find out this information and use set_affinity() to bind a process to hyper-threaded thread or non-hyper-threaded thread to profile its performance.

like image 399
Patrick Avatar asked Sep 01 '11 18:09

Patrick


People also ask

How do I know if my cores are Hyperthreaded?

You can use WMI's Win32_processor class to get this information. The class has a property NumberOfCores that tells you how many cores the processor has. The NumberOfLogicalProcessors will tell you how many logical processors. If it is higher than the cores then hyperthreading is enabled.

How do I see hyperthreading?

From the System Utilities screen, select System Configuration > BIOS/Platform Configuration (RBSU) > Processor Options > Intel (R) Hyperthreading Options. Select a setting. Save your setting.

How do I check virtual cores in Linux?

The way to tell how may cores you have is to look for "cpu cores" in your /proc/cpuinfo file. This line will show up for each virtual processor. If the number of cores shown is less than the number of virtual processors, your system is multi-threading.


1 Answers

I discovered the simply trick to do what I need.

cat /sys/devices/system/cpu/cpu0/topology/thread_siblings_list

If the first number is equal to the CPU number (0 in this example) then it's a real core, if not it is a hyperthreading core.

Real core example:

# cat /sys/devices/system/cpu/cpu1/topology/thread_siblings_list
1,13

Hyperthreading core example

# cat /sys/devices/system/cpu/cpu13/topology/thread_siblings_list
1,13

The output of the second example is exactly the same as the first one. However we are checking cpu13, and the first number is 1, so CPU 13 this is an hyperthreading core.

like image 170
Patrick Avatar answered Sep 22 '22 13:09

Patrick