一. 如何判断你的CPU支持超线程技术
Intel introduced Hyper-Threading Technology (HT) in its line of Xeon processors in 2002.
HT Technology enables multiprocessor servers to act as if they had twice as many processors installed.
Intel’s HT Technology allows a single processor to handle two independent sets of instructions at the same time.
In essence, HT Technology converts a single physical processor into two virtual processors.
Currently HT is present in other Intel CPUs besides the high level Xeons, like Pentium 4 (with 800MHz CPU bus speed) or Pentium 4 Extreme Edition and the dual-core Pentium Extreme Edition.
For more details see Intel’s site:
In order to make use of Hyper-Threading in Linux, you will need Hyper-Threading enabled in kernel.
But how can you find out if your CPU supports HT?
We can get the information from our running Linux system about its CPU by looking into /proc.
For example, bellow you can see the output taken from a Xeon system:
# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 3.20GHz
stepping : 3
cpu MHz : 3201.940
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm pni monitor ds_cpl cid cx16 xtpr
bogomips : 6404.17
Inside the flags section we are looking for a “ht” flag.
If it is present, this means that the system supports HT.
Let’s look on another sample taken from a Pentium4 CPU (the un-needed infos were removed):
model name : Intel(R) Pentium(R) 4 CPU 3.20GHz
cpu MHz : 3192.092
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
Again this system also supports HT.
If you don’t see the HT flag, then your system doesn’t support HT.
Obviously this will not be available on AMD processors as this is an Intel technology (this might not be true anymore with newer AMD CPUs).
Here is an example from an AMD Opteon system:
model name : AMD Opteron(tm) Processor 242
cpu MHz : 1593.326
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
If your CPU supports HT, then you can take advantage of this technology only if HT support is enabled in your running kernel.
You can either install a kernel provided by your Linux distribution with HT support (one that has *SMP* inside its name for ex.) or you can compile your own kernel and include HT support.
Once you are running a HT enabled kernel your should normally see the virtual CPU as a regular extra CPU (you will see 2 CPUs on a single CPU system, 4 CPUs on a dual processor system, etc.).
You can easily check this with:
# cat /proc/cpuinfo
If you still see only one CPU even after you have installed a HT enabled kernel, then you might want to check:
1. HT is not disabled in BIOS.
2. APCI is enabled in BIOS.
INTEL的官方文档对/proc/info里面的ht标志的解释:
"ht" in 'flags' field of /proc/cpuinfo indicate that the processor supports the Machine Specific
Registers to report back HT or multi-core capability.
Best way to check Hyper-threading feature in Linux
Run "dmidecode -t processor" and grep for the entry "HTT" from the result.
Sample output:
[root@server10 ~]# dmidecode -t processor | grep HTT
HTT (Hyper-threading technology)
HTT (Hyper-threading technology)
[root@server10 ~]#
So if Hyper-threading is enabled, the count of Logical Processors would be double the number of CPU cores that you got on the server.
To find the number of CPU cores, you either use "dmidecode -t processor" command or check the number of Physical IDs from "/proc/cpuinfo" output.
Please be aware the “ht” entry in /proc/cpuinfo output is a confusing flag.
It may be definite for CPU with single core but not for multi-core CPU. Enabling HT should be done at BIOS level.
当cpu是单核的时候, ht标志可以确切地表示该cpu支持超线程, 如果是多核的cpu, ht标志不一定表示这个cpu支持超线程!
INTEL官方文档的具体解释:
2. Detecting Hardware Multi-threading and Multi-core topology in 2.6 Linux
Multiple logical threads (HT) or execution cores (MC) in a physical package appear to the operating system as multiple logical processors (similar to SMP environment).
For example, Dual-Core Intel Xeon? processor 7100 series provides four logical processors for each physical package in the platform, as it is a dual-core processor with HT Technology enabled.
Linux kernel exports the multi-threading and multi-core topology to the applications using two mechanisms.
Applications can use the topology information for number of purposes such as application licensing, binding application threads/processes to a specific group of threads/cores/physical packages to achieve peak throughput.
2.1 Exporting through ‘proc’ file system:
/proc/cpuinfo contains information about the different CPUs in the system.
This proc file also exports the multi-threading and multi-core topology information as seen by the OS.
This is the legacy mechanism of exporting topology information to the user, which started initially when Hyper-threading got introduced.
"ht" in 'flags' field of /proc/cpuinfo indicate that the processor supports the Machine Specific Registers to report back HT or multi-core capability.
Additional fields (listed down below) in the CPU records of /proc/cpuinfo will give more precise information about the CPU topology as seen by the operating system.
"physical id" Physical package id of the logical CPU
"siblings" Total number of logical processors(includes both threads and cores) in the physical package currently in use by the OS
"cpu cores" Total number of cores in the physical package currently in use by the OS
"core id" Core id of the logical CPU
Legacy HT optimized applications parse "ht" flag and "physical id", "siblings" fields in /proc/cpuinfo for identifying physical packages in the system.
This package identification will be used for example in application licensing purposes or in binding a process to a specific physical package.
These applications require no change and will work as it is on a multi-threaded and/or multi-core system if they require only the logical CPU to a physical package mapping.
To identify if the physical package is purely multi-threaded or purely multi-core capable or both, then in addition to the "ht" flag, applications need to parse all the above mentioned fields.
Following logic can be used to identify the CPU capabilities as seen by the OS.
"siblings == cpu cores >= 2"
- Indicates that the physical package is multi-core capable and is not Hyper-threading capable
"siblings >= 2" && "cpu cores == 1"
- Indicates that the physical package is Hyper-threading capable and has one cpu core
"siblings > cpu cores > 1"
- Indicates that the physical package is both Hyper-threading and multi-core capable
To build the complete topology of which logical cpus belong to which CPU core and/or physical package, application need to parse "physical id" and "core id" fields.
For two logical cpus, if both these ids are same, then they belong to same core (Hyper-Threading siblings).
If they have same physical package id and different core id, then they belong to same physical package (core siblings).
2.2 Exporting through ‘sysfs’ file system
More recent Linux Kernels [LK] (like 2.6.17) have the CPU topology exported in sysfs as well.
This mechanism is simpler and faster compared to the previously mentioned /proc interface.
Below listed fields exported under /sys/devices/system/cpu/cpuX/topology/ provide the complete topology information.
physical_package_id Physical package id of the logical CPU
core_id Core id of the logical CPU
core_siblings Siblings mask of all the logical CPUs in a physical package
thread_siblings Siblings mask of all the logical CPUs in a CPU core
Hamming Weight (number of bits set) of siblings mask will give the physical package capabilities. (“哈明权”(Hamming weight)。这指代码中1的个数。如01110的哈明权为3。)
“HW(core_siblings) == HW(thread_siblings) >= 2”
- Indicates that the physical package is Hyper-threading capable and has one cpu core
“HW(core_siblings) >= 2” && “HW(thread_siblings) == 1”
- Indicates that the physical package is multi-core capable and is not Hyper-threading capable
“HW(core_siblings) > HW(thread_siblings) > 1”
- indicates that the physical package is both Hyper-threading and multi-core capable
二. 如何启用超线程?
1. bios里面打开ht
2. bios里面打开APIC
3. 内核支持ht(SMP内核)
阅读(898) | 评论(0) | 转发(0) |