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

标签 assembly locking x86 cpu multicore

在执行“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/

相关文章:

assembly - MIPS 汇编乘法并将 Hi 和 Lo 移入寄存器

assembly - BIOS INT 13H 问题(从驱动器读取扇区)

assembly - mov r64,m64是一个周期还是两个周期的延迟?

asp.net - HttpApplicationState - 如果线程安全,为什么会存在竞争条件?

java - 没有同步顺序的程序

assembly - Skylake 在一个周期内可以执行多少个 1 字节的 NOP

c++ - GCC 内联汇编错误 : junk `(%ebp)+4' after expression

python - Python线程未释放锁

c - 函数返回局部变量的地址,但仍在c中编译,为什么?

gcc - GCC 生成的 ARM 和 x86 汇编代码的区别