如何决定是否使用超线程?

How to decide whether to use hyperthreading or not?

超线程会损害某些应用程序的性能,因此不应使用。来自 Microsoft 网站 (https://msdn.microsoft.com/en-us/library/cc615012%28BTS.10%29.aspx):

It is critical hyper-threading be turned off for BizTalk Server computers. Hyper-threading makes the server appear to have more processors/processor cores than it actually does; however hyper-threaded processors typically provide between 20 and 30% of the performance of a physical processor/processor core. When BizTalk Server counts the number of processors to adjust its self-tuning algorithms; the hyper-threaded processors cause these adjustments to be skewed which is detrimental to overall performance.

Process Lasso 程序允许为某些进程禁用超线程:

You can use programs like Process Lasso (free) to set default CPU affinities for critical processes, so that their threads never get allocated to logical cores. We call this feature HyperThreaded Core Avoidance.

我有一些执行大量数学计算的旧程序。如果他们可以使用 4 个核心,那么看到他们使用一个核心是令人沮丧的。我想重写它们以使用多个线程。他们使用大的连续内存块,因此缓存未命中的次数最少。我的问题如下:

基本上,它归结为配置执行 CPU 工作负载的并发线程数。 OS 知道超线程,并且会将线程分配给物理核心,直到用完为止,只有当线程数多于物理核心时,它才会开始将工作分配给逻辑核心。

要确定最佳线程数是物理内核数还是逻辑内核数,测量实际任务的性能是最好的方法。综合基准​​可以告诉您有关超线程如何工作的一些信息,但不会告诉您什么最适合您的特定指令组合。

控制线程数的确切方法取决于您使用的多线程构造——如果您自己创建线程,这是显而易见的,但线程池和自动并行框架(如 OpenMP)也提供了调整线程数的方法。

我不知道 Process Lasso 是否适用于 "disabling HyperThreading"。对于那个特定的应用程序,你能做的最好的事情就是将 DLL 注入到系统的每个进程中,调用 SetProcessAffinityMask 只是猜测,禁用所有其他核心,希望 OS 将避免调度到超线程逻辑内核。

猜测和希望,Windows API 中没有任何东西可以肯定地做到这一点。这回答了你的第三个要点。

您可以将超线程禁用为 BIOS 级别(通常)。

我无法评论 Microsoft 关于为 BizTalk 禁用 HT 的建议,your linked article,因为我找不到这篇文章的日期。唯一有趣的一点是关于 "Assigning interrupt affinity to logical processors...",对我来说是新的。该文章中关于 HT 的唯一其他建议相当薄弱。

更重要的是:我不知道你为什么要问超线程,而你通常应该关心多线程。如果您担心多个线程争用同一共享资源...那么请不要在您的应用中使用线程。

说句幽默的话:同一家公司还销售一种名为 SmartTrim 的产品,让人想起 90 年代流行的 RAM-doublers