多核+超线程-线程如何分布? [英] Multicore + Hyperthreading - how are threads distributed?

查看:152
本文介绍了多核+超线程-线程如何分布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读新的Intel Atom 330的评论,他们注意到任务管理器显示了4个核心-两个物理核心,以及另外两个通过超线程模拟的核心.

I was reading a review of the new Intel Atom 330, where they noted that Task Manager shows 4 cores - two physical cores, plus two more simulated by Hyperthreading.

假设您有一个带有两个线程的程序.还要假设这些是在PC上执行任何工作的唯一线程,其他所有线程都是空闲的.操作系统将两个线程放在同一个内核上的机率是多少?这对程序的吞吐量有巨大的影响.

Suppose you have a program with two threads. Suppose also that these are the only threads doing any work on the PC, everything else is idle. What is the probability that the OS will put both threads on the same core? This has huge implications for program throughput.

如果答案不是0%,那么除了创建更多线程之外,还有其他缓解策略吗?

If the answer is anything other than 0%, are there any mitigation strategies other than creating more threads?

我希望Windows,Linux和Mac OS X会有不同的答案.


使用 sk的答案作为Google的草料,然后点击链接,我发现Windows中的 GetLogicalProcessorInformation 函数.它说的是共享资源的逻辑处理器.这种类型的资源共享的一个例子就是超线程方案."这意味着 jalf 是正确的,但这不是一个确定的答案.

I expect there will be different answers for Windows, Linux, and Mac OS X.


Using sk's answer as Google fodder, then following the links, I found the GetLogicalProcessorInformation function in Windows. It speaks of "logical processors that share resources. An example of this type of resource sharing would be hyperthreading scenarios." This implies that jalf is correct, but it's not quite a definitive answer.

推荐答案

Linux有相当复杂的线程调度程序,可以感知HT.它的一些策略包括:

Linux has quite a sophisticated thread scheduler which is HT aware. Some of its strategies include:

被动负载平衡:如果一个物理CPU正在运行多个任务,则调度程序将尝试在第二个物理处理器上运行任何新任务.

Passive Loadbalancing: If a physical CPU is running more than one task the scheduler will attempt to run any new tasks on a second physical processor.

活动负载平衡:如果有3个任务,当第二个物理处理器空闲时,一个物理cpu上有2个任务,另一个物理任务上有1个任务,调度程序将尝试将其中一个任务迁移到该任务.

Active Loadbalancing: If there are 3 tasks, 2 on one physical cpu and 1 on the other when the second physical processor goes idle the scheduler will attempt to migrate one of the tasks to it.

在尝试保持线程亲和力时会这样做,因为当线程迁移到另一个物理处理器时,它将必须重新填充主内存中的所有缓存级别,从而导致任务停顿.

It does this while attempting to keep thread affinity because when a thread migrates to another physical processor it will have to refill all levels of cache from main memory causing a stall in the task.

因此可以回答您的问题(至少在Linux上);给定双核超线程计算机上的2个线程,每个线程将在其自己的物理内核上运行.

So to answer your question (on Linux at least); given 2 threads on a dual core hyperthreaded machine, each thread will run on its own physical core.

这篇关于多核+超线程-线程如何分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆