Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++/Assembly Programatically detect if hyper-threading is active on Windows, Mac and Linux [duplicate]

I can already correctly detect the number of logical processors correctly on all three of these platforms.

To be able to detect the number of physical processors/cores correctly I'll have to detect if hyperthreading is supported AND active (or enabled if you prefer) and if so divide the number of logical processors by 2 to determine the number of physical processors.

Perphaps I should provide an example:

A quad core Intel CPU's with hyperthreading enabled has 4 physical cores, yet 8 logical processors (hyperthreading creates 4 more logical processors). So my current function would detect 8 instead of the desired 4.

My question therefore is if there is a way to detect whether hyperthreading is supported AND ENABLED?

like image 394
HTASSCPP Avatar asked May 25 '10 11:05

HTASSCPP


People also ask

How do I know if Hyper Threading is enabled?

If the number of logical processors is greater than physical processors (cores), then hyperthreading is enabled.

Is Hyper Threading concurrent or parallel?

The main function of hyper-threading is to increase the number of independent instructions in the pipeline; it takes advantage of superscalar architecture, in which multiple instructions operate on separate data in parallel.

How do I enable multithreading in Linux?

Use the hyptop command to obtain utilization data for threads while Linux runs with multithreading enabled. You can use the smt= and nosmt kernel parameters to control multithreading. By default, Linux in LPAR mode uses multithreading if it is provided by the hardware.

Is hyperthreading enabled by default?

It's enabled by default, but it can be switched on and off from the BIOS environment by setting “Hyper-Threading Technology” to “Enable” or “Disable”. Note that Intel® Hyper-Threading Technology is only available on some enthusiast CPUs: see the full list here.


1 Answers

On Windows 2003 Server and Windows XP SP3 and later, you can determine this information using the GetLogicalProcessorInformation system call.

like image 94
Ken Bloom Avatar answered Sep 24 '22 13:09

Ken Bloom