超线程有效吗?

发布于 2024-11-14 13:10:51 字数 270 浏览 6 评论 0原文

我在我的 PC 上运行一些相当处理器密集型的东西,并注意到我的 CPU 使用情况看起来很奇怪。我的电脑是四核 i7-870,据说有八个虚拟核心。
我在 .NET 4 中使用任务并行库,因此期望所有核心都能得到很好的利用,但我从进程监视器中获取如下信息:

CPU 使用率

核心 6 和 8 几乎没有受到影响,除了短暂的突发之外,核心 4 也没有受到影响。
这是我应该期待的吗?

I'm running some fairly processor-intensive stuff on my PC, and notice my CPU usage looks pretty odd. My PC is a quad-core i7-870, which supposedly has eight virtual cores.
I'm using the Task Parallel library in .NET 4, so expect all cores to be nicely utilised, but am getting information like this from Process Monitor:

CPU usage

Cores 6 and 8 are hardly getting touched, and apart from a brief burst, 4 isn't either.
Is this what I should expect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷荒 2024-11-21 13:10:52

在大多数情况下,是的,我认为这看起来很合理。请记住,超线程实际上只是伪造两个核心。每个物理核心都有两个前端,因此它可以并行读取两个指令流。但它们仍然共享相同的执行单元。因此,当一个 HT 核心繁忙时,执行单元就会被占用,因此它的“双”核心将能够完成很少的工作。

这似乎就是您在前两个核心上看到的情况(特别是第二个核心,这一点非常明显)

除此之外,您几乎永远无法获得完美的 CPU 利用率。有时,核心必须停止等待内存。有时它会执行成本高昂的非流水线指令,从而有效地阻塞该物理核心上的执行单元可能数十甚至数百个周期。

有时,指令之间的依赖关系可能仅仅意味着您没有任何东西可供一个或多个内核执行。

除此之外,您会看到 8 个图表,而您只有 4 个核心,所以是的,超线程当然正在工作。 ;)

For the most part, yes, I think this looks reasonable. Keep in mind that hyperthreading really just fakes two cores. Each physical core is given two frontends, so it can read two streams of instructions in parallel. But they still share the same execution units. So when one HT core is busy, the execution units are taken, and so its "twin" core will be able to do very little work.

That seems to be what you're seeing on the first two cores (the second in particular makes it very obvious)

Apart from this, you'll almost never be able to get perfect CPU utilization. Sometimes, a core just has to stall waiting for memory. Sometimes it's executing a costly non-pipelined instruction, effectively blocking the execution units on that physical core for perhaps tens or even hundreds of cycles.

And sometimes, dependencies between instructions might just mean that you don't have anything for one or more cores to execute.

Apart from that, you see 8 graphs, and you only have 4 cores, so yes, of course hyperthreading is working. ;)

猛虎独行 2024-11-21 13:10:52

简而言之

  1. ,是的,它可以工作(当然)
  2. 配置它
  3. YMMV - 超线程不是多核,因此在很大程度上取决于指令加载的类型和缓存饱和度等。不了解您的代码的任何信息(除了它是 C#,真的)您可能会寻找可以直接制作成结构的System.Array的“小对象”集合(通用List<>也将在内部使用数组并优化对于结构元素类型)

0.02 美元

In short

  1. yes it works (of course)
  2. profile it
  3. YMMV - hyperthreading is not multi-coring and as such depends heavily on the type of instruction load and cache saturation etc. Not knowing anything about your code (except that it is C#, really) you might look for collections of 'small objects' that could be made into straight System.Array's of structs (A generic List<> will also use an Array internally and optimize for struct element types)

$0.02

慕烟庭风 2024-11-21 13:10:52

这一切都取决于您的算法实现。 TPL 将根据算法中的数据依赖性使用适当数量的内核

It all depends on your algorithm implementation. TPL will use proper number of cores depending upon the data dependency in your algorithm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文