Linux 为什么启用超线程后性能变差?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10593313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:19:35  来源:igfitidea点击:

Why does the performance become bad after enabling hyperthread?

linuxlinux-kernelschedulingintelhyperthreading

提问by flypen

I port Linux kernel 2.6.32 to Intel(R) Xeon(R) CPU E31275 @ 3.40GHz. If I enable hyperthread in BIOS, I can see 8 CPU cores (CPU0 ~ CPU7). Most of interrupts occur in CPU 4, and the CPU usage of this core is much higher than others (almost twice than others). I don't understand it very well, because I think I didn't set any IRQ binding operations.

我将 Linux 内核 2.6.32 移植到 Intel(R) Xeon(R) CPU E31275 @ 3.40GHz。如果我在 BIOS 中启用超线程,我可以看到 8 个 CPU 内核(CPU0 ~ CPU7)。大部分中断发生在CPU 4,这个核心的CPU使用率比其他核心高很多(几乎是其他核心的两倍)。我不是很明白,因为我认为我没有设置任何IRQ绑定操作。

If I disable hyperthread in BIOS, then everything is OK. The IRQs have been balanced, and the CPU usage of all cores (CPU0 ~ CPU3) are nearly balanced, too.

如果我在 BIOS 中禁用超线程,则一切正常。IRQ 已经平衡,所有内核(CPU0 ~ CPU3)的 CPU 使用率也接近平衡。

Can someone explain it? Is it BIOS related? Should I do some special settings in kernel?

有人可以解释一下吗?和BIOS有关吗?我应该在内核中做一些特殊的设置吗?

采纳答案by K1773R

Some programs get a negative effect from HT (Hyper Threading), to explain this you have to understand what HT is. As you said you saw 7 (0-7 is altough 8) cpu cores, this is not true, u have 4 cores in your CPU, the 8 cores are virtual cores, so one core has 2 threads (and acts like he is 2 cores). Usually HT helps for running programs faster due to the fact the CPU/OS is able to run (doing what ever these programs do) 8 programs at the same time, without HT you can only run 4 at the same time. You dont have to set any settings since you cant change this appearance, if you are the developer of this program you should recheck the code and optimize it for HT if you want, or you can just disable HT.

一些程序会受到 HT(超线程)的负面影响,要解释这一点,您必须了解 HT 是什么。正如您所说,您看到了 7 个(0-7 是 8 个)cpu 内核,这不是真的,您的 CPU 中有 4 个内核,8 个内核是虚拟内核,因此一个内核有 2 个线程(就像他是 2核)。通常 HT 有助于更快地运行程序,因为 CPU/OS 能够同时运行(执行这些程序所做的一切)8 个程序,没有 HT,您只能同时运行 4 个。您不必设置任何设置,因为您无法更改此外观,如果您是此程序的开发人员,您应该重新检查代码并根据需要针对 HT 对其进行优化,或者您可以仅禁用 HT。

Another information due to some bullshit peoples are talking: HT is increasing the power of the CPU this is NOT true! even when u see 8 cores with lets say 4GHz (GHz says nothing, should be measured in flops) you got the same power as when u turn HT of and got 4 cores with 4GHz. If you got HT on the 2 virtual cores are sharing 1 physical core from ur CPU.

由于一些胡说八道的人在谈论另一个信息:HT 正在增加 CPU 的功率,这不是真的!即使当您看到 8 个内核时可以说 4GHz(GHz 什么也没说,应该以触发器来衡量),您也获得了与您关闭 HT 并获得 4 个 4GHz 内核时相同的功率。如果您在 2 个虚拟内核上获得 HT,则您的 CPU 将共享 1 个物理内核。

Here some more informations about HT: http://www.makeuseof.com/tag/hyperthreading-technology-explained/

这里有一些关于 HT 的更多信息:http: //www.makeuseof.com/tag/hyperthreading-technology-explained/

I couldnt find my old link to a very nice site where there are code snippets who shows bad code for HT and good code (in the meaning bad of being slower than without HT and the opposite).

我找不到我的旧链接到一个非常好的网站,那里有代码片段显示 HT 的坏代码和好的代码(意思是比没有 HT 慢,反之亦然)。

TL;DR: not every program benefetis from HT due to its development.

TL;DR:并非每个程序都因 HT 的发展而受益。