超线程 - 当两个线程都准备好时,哪个线程运行

时间:2021-09-24 21:02:18

The idea behind Intels hyperthreading is (as far as I understand) that one core is used for two threads in a time-multiplexed manner.

英特尔超线程技术背后的想法(据我所知),一个核心以时间复用的方式用于两个线程。

The HW support this by having the state-related resources doubled and time-sharing other resources. If the running thread stalls (e.g. because it has to fetch new data from RAM), the other thread gets access to the shared resources. The result is a better utilization of the shared resources.

硬件支持这一点,通过使状态相关的资源加倍并分时其他资源。如果正在运行的线程停止(例如,因为它必须从RAM获取新数据),则另一个线程可以访问共享资源。结果是更好地利用共享资源。

So if one thread isn't ready, the other thread is allowed to run. In other words - a thread switch can happen when the executing thread stalls.

因此,如果一个线程没有准备好,则允许另一个线程运行。换句话说 - 当执行的线程停止时,可能发生线程切换。

I've tried to find out what will happen if both threads are ready for a long time but I haven't been able to find the information.

我试图找出如果两个线程已经准备好很长时间会发生什么,但我无法找到这些信息。

What happens if the running thread doesn't stall?

如果正在运行的线程没有停止会发生什么?

Will the running thread continue as long as it is ready?

只要准备就绪,正在运行的线程会继续吗?

Will the core switch to the other thread after some time? If so - what is the criteria for the switch? Is it controlled by HW or SW?

一段时间后核心会切换到另一个线程吗?如果是这样 - 交换机的标准是什么?它是由HW还是SW控制?

1 个解决方案

#1


Hyperthreading is simultaneous multithreading (SMT). So it doesn't just switch back and forth on some relatively coarse-grain scale (like stalls), in the case of Sandy Bridge and newer, the fetcher and the decoder alternate between the threads. Execution units are shared competitively, so even if neither thread is stalling they can still together achieve a better utilization than if they ran alone (but that's not typical). So the problems you identified don't apply, because it doesn't work like that in the first place.

超线程是同时多线程(SMT)。所以它不仅仅是在一些相对粗粒度(如档位)上来回切换,在Sandy Bridge和更新的情况下,提取器和解码器在线程之间交替。执行单元是竞争性共享的,因此即使两个线程都没有停止,它们仍然可以共同实现比单独运行时更好的利用率(但这不是典型的)。因此,您发现的问题不适用,因为它首先不起作用。

#1


Hyperthreading is simultaneous multithreading (SMT). So it doesn't just switch back and forth on some relatively coarse-grain scale (like stalls), in the case of Sandy Bridge and newer, the fetcher and the decoder alternate between the threads. Execution units are shared competitively, so even if neither thread is stalling they can still together achieve a better utilization than if they ran alone (but that's not typical). So the problems you identified don't apply, because it doesn't work like that in the first place.

超线程是同时多线程(SMT)。所以它不仅仅是在一些相对粗粒度(如档位)上来回切换,在Sandy Bridge和更新的情况下,提取器和解码器在线程之间交替。执行单元是竞争性共享的,因此即使两个线程都没有停止,它们仍然可以共同实现比单独运行时更好的利用率(但这不是典型的)。因此,您发现的问题不适用,因为它首先不起作用。