m-j-w/CpuId.jl

`CpuId.cpuinfo()` seems to think that hyperthreading is enabled, even when it is not

Closed this issue · 1 comments

CpuId.cpuinfo() seems to think that hyperthreading is enabled, even when I have disabled hyperthreading.

This is on macOS.

We start with hyperthreading enabled. sysctl hw.physicalcpu hw.logicalcpu tells us that we have 2 physical CPUs and 4 logical CPUs, which confirms that hyperthreading is enabled. And CpuId.cpuinfo() tells us the same thing.

$ sysctl hw.physicalcpu hw.logicalcpu
hw.physicalcpu: 2
hw.logicalcpu: 4
$ julia -e 'using CpuId; println(CpuId.cpuinfo())'
| Cpu Property       | Value                                                      |
|:------------------ |:---------------------------------------------------------- |
| Brand              | Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz                   |
| Vendor             | :Intel                                                     |
| Architecture       | :Haswell                                                   |
| Model              | Family: 0x06, Model: 0x45, Stepping: 0x01, Type: 0x00      |
| Cores              | 2 physical cores, 4 logical cores (on executing CPU)       |
|                    | Hyperthreading detected                                    |
| Clock Frequencies  | Not supported by CPU                                       |
| Data Cache         | Level 1:3 : (32, 256, 3072) kbytes                         |
|                    | 64 byte cache line size                                    |
| Address Size       | 48 bits virtual, 39 bits physical                          |
| SIMD               | 256 bit = 32 byte max. SIMD vector size                    |
| Time Stamp Counter | TSC is accessible via `rdtsc`                              |
|                    | TSC runs at constant rate (invariant from clock frequency) |
| Perf. Monitoring   | Performance Monitoring Counters (PMC) revision 3           |
|                    | Available hardware counters per logical core:              |
|                    | 3 fixed-function counters of 48 bit width                  |
|                    | 4 general-purpose counters of 48 bit width                 |
| Hypervisor         | No                                                         |

Now, I open Instruments.app, go to Preferences -> CPUs, and uncheck the Hardware Multi-Threading checkbox.

Now, sysctl hw.physicalcpu hw.logicalcpu reports that we have 2 physical cores and 2 logical cores, which confirms that hyperthreading is disabled. However, CpuId.cpuinfo() still reports that hyperthreading was detected. Furthermore, CpuId.cpuinfo() reports that we have 2 physical cores and 4 logical cores.

$ sysctl hw.physicalcpu hw.logicalcpu
hw.physicalcpu: 2
hw.logicalcpu: 2
$ julia -e 'using CpuId; println(CpuId.cpuinfo())'
| Cpu Property       | Value                                                      |
|:------------------ |:---------------------------------------------------------- |
| Brand              | Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz                   |
| Vendor             | :Intel                                                     |
| Architecture       | :Haswell                                                   |
| Model              | Family: 0x06, Model: 0x45, Stepping: 0x01, Type: 0x00      |
| Cores              | 2 physical cores, 4 logical cores (on executing CPU)       |
|                    | Hyperthreading detected                                    |
| Clock Frequencies  | Not supported by CPU                                       |
| Data Cache         | Level 1:3 : (32, 256, 3072) kbytes                         |
|                    | 64 byte cache line size                                    |
| Address Size       | 48 bits virtual, 39 bits physical                          |
| SIMD               | 256 bit = 32 byte max. SIMD vector size                    |
| Time Stamp Counter | TSC is accessible via `rdtsc`                              |
|                    | TSC runs at constant rate (invariant from clock frequency) |
| Perf. Monitoring   | Performance Monitoring Counters (PMC) revision 3           |
|                    | Available hardware counters per logical core:              |
|                    | 3 fixed-function counters of 48 bit width                  |
|                    | 4 general-purpose counters of 48 bit width                 |
| Hypervisor         | No                                                         |

$ sysctl hw.physicalcpu hw.logicalcpu
hw.physicalcpu: 2
hw.logicalcpu: 4
$ julia -e 'using CpuId; println(CpuId.cpuinfo())'
| Cpu Property       | Value                                                      |
|:------------------ |:---------------------------------------------------------- |
| Brand              | Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz                   |
| Vendor             | :Intel                                                     |
| Architecture       | :Haswell                                                   |
| Model              | Family: 0x06, Model: 0x45, Stepping: 0x01, Type: 0x00      |
| Cores              | 2 physical cores, 4 logical cores (on executing CPU)       |
|                    | Hyperthreading detected                                    |
| Clock Frequencies  | Not supported by CPU                                       |
| Data Cache         | Level 1:3 : (32, 256, 3072) kbytes                         |
|                    | 64 byte cache line size                                    |
| Address Size       | 48 bits virtual, 39 bits physical                          |
| SIMD               | 256 bit = 32 byte max. SIMD vector size                    |
| Time Stamp Counter | TSC is accessible via `rdtsc`                              |
|                    | TSC runs at constant rate (invariant from clock frequency) |
| Perf. Monitoring   | Performance Monitoring Counters (PMC) revision 3           |
|                    | Available hardware counters per logical core:              |
|                    | 3 fixed-function counters of 48 bit width                  |
|                    | 4 general-purpose counters of 48 bit width                 |
| Hypervisor         | No                                                         |
m-j-w commented

The text you're refering to is simply created by comparing logical cores to physical cores. If there is a factor of two between them, then it writes "Hyperthreading detected".

I believe you have other expectations than this package can provide. It uses the hardware cpu instruction 'cpuid' to ask the processor of it's self-reported capabilities. This always only works for the processor this task runs on, and can only provide the answer which the processor reports. If the admin disables certain cores in the BIOS or OS, then the CPU does not report this. Thus, this is outside the scope of this tool.