一个CPU核上可以同时运行两个进程吗?

发布于 2024-12-27 20:26:30 字数 492 浏览 2 评论 0原文

两个进程可以同时运行在一个具有超线程的CPU核心上吗?我从互联网上学习。但是,我没有看到明确的直接答案。

编辑: 感谢讨论和分享!我在这里提出问题并不是为了讨论并行计算。它太大了,无法在这里讨论。我只是想知道多线程应用程序是否比多进程应用程序更能从超线程中受益。经过进一步阅读,我有以下作为我的学习笔记。

1) 启用超线程技术的 CPU 核心有两组 CPU 状态和中断逻辑。同时,它只有一组执行单元和缓存。 (我还没有研究什么是管道)

2)仅当某些执行的线程中发生延迟时,多线程才能从超线程中受益。我认为这一点可以准确地映射到软件程序员为什么以及何时使用多线程的常见原因。如果多线程应用已经优化。它可能无法从 Hypter 线程中获得任何好处。

3)如果CPU状态映射到进程状态,我相信Marc是正确的,多进程应用程序甚至可以从超线程技术中受益更多。

4)当CPU供应商说“线程”时,看起来他们的“线程”与我作为java程序员所知道的线程不同?

Can two processes simultaneously run on one CPU core, which has hyper threading? I learn from the Internet. But, I do not see a clear straight answer.

Edit:
Thanks for discussion and sharing! My purse to post my question here is not to discuss about parallel computing. It will be too big to be discussed here. I just want to know if a multithread application can benefit more from hyper threading than a multi process application. After further reading, I have following as my learning notes.

1) A Hyper-Threading Technology enabled CPU Core has two set of CPU state and Interrupt Logic. Meanwhile, it has only one set of Execution Units and Cache. (I have not study what is pipeline yet)

2) Multi threading benefits from Hyper Threading only if there is latency happen in some executed thread. I think this point can exactly map to the common reason for why and when software programmer use multi thread. If the multi thread application has been optimized. It may not gain any benefit from Hypter threading.

3) If the CPU state maps to process state, I believe Marc is correct that multiple process application can even benefit more from hyper threading technology.

4) When CPU vendor says "thread", it looks like their "thread" is different from thread that I know as a java programmer?

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

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

发布评论

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

评论(3

够运 2025-01-03 20:26:30

不,超线程 CPU 核心仍然只有一个执行管道。尽管对于上层操作系统来说它看起来像是两个 CPU,但在任何给定时间仍然只执行一条指令。

超线程的目的是允许 CPU 继续执行一个线程,而另一个线程则停止等待资源或其他操作完成,而不会留下太多管道空无用的阶段。这可以追溯到 Pentium 4 天,其管道长得离谱——停顿对于效率和吞吐量来说本质上是灾难性的,而超线程允许英特尔在清理停顿的同时让 CPU 忙于做其他事情。

No, a hyperthreaded CPU core still only has a single execution pipeline. Even though it appears as two CPUs to the overlying OS, there's still only ever one instruction being executed at any given time.

Hyperthreading was intended to allow the CPU to continue executing one thread while another thread was stalled waiting for a resource or other operation to complete, without leaving too many stages of the pipeline empty and useless. This goes back to the Pentium 4 days, with its absurdly long pipeline - a stall was essentially catastrophic for efficiency and throughput, and hyperthreading allowed Intel to keep the cpu busy doing other things while it cleaned up from the stall.

傲鸠 2025-01-03 20:26:30

虽然 Marc B 的回答几乎是 HT 如何工作的明确总结,但我只是想通过链接这篇文章做出一点贡献,这篇文章应该可以澄清有关 HT 的很多事情: intel.com/en-us/articles/performance-insights-to-intel-hyper-threading-technology/" rel="nofollow">http://software.intel.com/en-us/articles/performance-insights-to-intel-hyper-threading-technology/

While Marc B's answer is pretty much the definitive summary of how HT works, I just want to make a small contribution by linking this article, which should clear up a lot of things about HT: http://software.intel.com/en-us/articles/performance-insights-to-intel-hyper-threading-technology/

三生殊途 2025-01-03 20:26:30

简短的回答是,是的。

一个单核CPU(处理器),可以同时运行2个或更多线程。这些线程可能属于一个程序,或者它们可能属于不同的程序并因此属于不同的进程。这种类型的多线程称为同步多线程(SMT)。

声称 CPU 核心在任何给定时间只能执行一条指令的信息也是不正确的。现代CPU 通过复制管道资源(例如2 个ALU 而不是1 个)来利用指令级并行性(ILP)。这种类型的管道称为“超标量”管道。

同时多线程的维基百科页面:

同时多线程

Short answer, yes.

A single core cpu(a processor), can run 2 or more threads simultaneously. These threads may belong to the one program, or they may belong different programs and thus processes. This type of multithreading is called Simultaneous MultiThreading(SMT).

Information that claims cpu core can execute only one instruction at any given time is also not true. Modern CPUs exploit Instruction Level Parallelism(ILP) by duplicating pipeline resources(e.g 2 ALUs instead of 1). This type of pipeline is called "superscalar" pipeline.

Wikipedia page of Simultaneous Multithreading:

Simultaneous multithreading

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