多核 CPU 上的 x86 LOCK 问题 [英] x86 LOCK question on multi-core CPUs

查看:29
本文介绍了多核 CPU 上的 x86 LOCK 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x86 ASMLOCK"命令前缀是否会导致所有内核在LOCK"后面的指令正在执行时冻结?

Is it true that the x86 ASM "LOCK" command prefix causes all cores to freeze while the instruction following "LOCK" is being executed?

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

I read this in a blog post and it doesn't make sense. I can't find anything that indicates if this is true or not.

推荐答案

这是关于锁定该地址的内存总线.英特尔 64 位和 IA-32 架构软件开发人员手册 - 第 3A 卷:系统编程指南,第 1 部分告诉我们:

It's about locking the memory bus for that address. The Intel 64 and IA-32 Architectures Software Developer's Manual - Volume 3A: System Programming Guide, Part 1 tells us:

7.1.4 LOCK 操作对内部处理器缓存的影响.

7.1.4 Effects of a LOCK Operation on Internal Processor Caches.

对于 Intel486 和 Pentium 处理器,LOCK# 信号始终为在 LOCK 期间在总线上断言操作,即使内存区域被锁定缓存在处理器.

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.

对于 P6 和更新的处理器家庭,如果内存区域是在 LOCK 操作期间被锁定是缓存在处理器中执行锁定操作作为回写内存并完全包含在缓存行中,处理器可能不会断言 LOCK#公交车上的信号.相反,它会内部修改内存位置并允许 [its] 缓存一致性确保运行的机制以原子方式进行.这操作称为缓存锁定".缓存一致性机制自动防止两个或更多具有相同面积的处理器同时修改内存该区域的数据.(强调)

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 和更新的芯片足够智能,可以确定它们是否真的必须屏蔽总线或仅依靠智能缓存.我认为这是一个巧妙的优化.

Here we learn that the P6 and newer chips are smart enough to determine if they really have to block off the bus or can just rely on intelligent caching. I think this is a neat optimization.

我在我的博客文章如何锁定锁?"

这篇关于多核 CPU 上的 x86 LOCK 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆