gpt4 book ai didi

assembly - 关于多核CPU的x86 LOCK问题

转载 作者:行者123 更新时间:2023-12-02 16:09:18 24 4
gpt4 key购买 nike

在执行“LOCK”后面的指令时,x86 ASM“LOCK”命令前缀是否会导致所有内核卡住?

我在一篇博客文章中读到了这个,但它没有意义。我找不到任何表明这是否属实的内容。

最佳答案

这是关于锁定该地址的内存总线。 The Intel 64 and IA-32 Architectures Software Developer's Manual - Volume 3A: System Programming Guide, Part 1告诉我们:

7.1.4 Effects of a LOCK Operation on Internal Processor Caches.

For the Intel486 and Pentium processors, the LOCK# signal is always asserted on the bus during a LOCK operation, even if the area of memory being locked is cached in the processor.

For the P6 and more recent processor families, if the area of memory being locked during a LOCK operation is cached in the processor that is performing the LOCK operation as write-back memory and is completely contained in a cache line, the processor may not assert the LOCK# signal on the bus. Instead, it will modify the memory location internally and allow [its] cache coherency mechanism to insure that the operation is carried out atomically. This operation is called "cache locking." The cache coherency mechanism automatically prevents two or more processors that have the same area of memory from simultaneously modifying data in that area. (emphasis added)

在这里,我们了解到 P6 和更新的芯片足够智能,可以确定它们是否真的必须阻塞总线,或者只能依靠智能缓存。我认为这是一个巧妙的优化。

我在我的博文“How Do Locks Lock?”中对此进行了更多讨论

关于assembly - 关于多核CPU的x86 LOCK问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3339141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com