支持超线程的系统上的 CPU 编号

发布于 2024-08-10 23:57:28 字数 362 浏览 5 评论 0原文

我试图找出操作系统(Windows、Linux)如何在启用超线程的环境中为逻辑 CPU 分配编号。 ?

两个操作系统是否首先连续为物理 CPU 分配编号,然后开始对逻辑 cpu 进行编号,或者是否遵循其他规则?例如,在具有超线程的 2 个物理 cpu 系统中,操作系统是否将数字 0,2 分配给第一个物理 cpu,然后将 1,3 分配给第二个物理 cpu ..?

任何参考将不胜感激。

提前致谢。

问候,-杰伊。

编辑:回应艾伦的问题:我需要知道这一点,因为在我的工作中,我需要将各种线程绑定到特定的 CPU 以避免上下文切换,并且我想确保某些任务(线程)绑定到单独的< /em> 物理 CPU。谢谢

I am trying to find out how an OS (Windows, linux) assigns numbers to logical cpus in a Hyper threading enabled environment. ?

Does both the OSs first serially assign numbers to the Physical CPUs and then start numbering the logical cpus or is there some other rule followed.. ? e.g. in 2 physical cpu system with hyper threading , does an OS assign number 0,2 to the first physical cpu and then 1,3 to second physical cpu .. ?

Any references would be really appreciated.

Thanks in advance.

Regards, -Jay.

Edit: Responding to Alan's question : I need to know this because, In my work I need to bind various threads to specific CPUs to avoid context switches and I want to make sure that certain Tasks( THreads ) are bound to separate physical cpus. Thanks

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

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

发布评论

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

评论(2

空‖城人不在 2024-08-17 23:57:28

据我所知,这取决于CPU如何暴露他的核心。启用 HT 后,不会暴露任何物理 CPU,而是每个物理 CPU 有两个逻辑 CPU,因此如果您在任一逻辑 CPU 上运行线程,则没有区别。唯一重要的是每个物理 CPU 属于哪些逻辑 CPU 对。

对于单核处理器(例如具有 HT 的 Pentium 4),它非常简单,因为您只有一对 - 所以它是 (0, 1)。对于四核处理器(如 Nehalem),逻辑核心对为 (0,4)、(1,5)、(2,6) 和 (3,7)。拥有每对的所有前半部分,然后拥有所有后半部分的模式应该可以与具有更多内核的未来 CPU 进行扩展。

真正的问题是为什么你需要知道配对安排?让操作系统的调度程序为正确的线程选择正确的核心 - 它做得相当不错。

From what I know, it depends on how the CPU exposes his cores. When HT is enabled, there are no exposed physical CPUs, but rather two logical CPUs per physical CPU, so there is no difference if you run a thread on either logical CPU. The only thing that does matter is what pairs of logical CPUs belong to each physical CPU.

With single core processors (like the Pentium 4 with HT), it's pretty straight forward, since you only have one pair - so it's (0, 1). With quad core processors (like Nehalem), the logical cores pairs are (0,4), (1,5), (2,6) and (3,7). The pattern of having all the first halves of each pair then having all the second halves shuold scale with future CPUs that have even more cores.

The real question is why do you need to know the pair arrangement? Let the OS's scheduler pick the right cores for the right threads - it does a pretty decent job.

牛↙奶布丁 2024-08-17 23:57:28

您可以在 /sys/devices/system/cpu/ 中查找有关 CPU 的信息。内核的布局及其超线程对可以在 /sys/devices/system/cpu/cpuN/topology/thread_siblings_list 中找到。

You can look in /sys/devices/system/cpu/ to find the information about the CPUs. The layout of the cores and their hyperthreaded pairs can be found in /sys/devices/system/cpu/cpuN/topology/thread_siblings_list.

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