曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 5029|回复: 0
打印 上一主题 下一主题

[X86] LOCK 操作(加锁操作)对处理器内部缓存的影响

[复制链接]

4917

主题

5879

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34382
跳转到指定楼层
楼主
发表于 2011-3-19 13:57:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是 <<Intel Architecture Software Developer's Manual3>> 中 7.1.4 节的翻译:

对于 Intel486 和 Pentium (奔腾处理器), 在对总线进行加锁操作,总会宣告一个 LOCK# 信号,即使被锁定的内存区域已经缓存到了处理器中。

对于 P6 家族处理器,如果在 LOCK 操作期间被锁定的内存区域被缓存到正在执行回写(write-back)内存加锁操作的处理器中,并且已经完全包含在缓存行(cache line)中,处理器可能不需要在总线上宣告一个 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.
For the P6 family processors, 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 it’s cache coherency mecha-
nism 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 cached the same area of memory from simultaneously modifying data in that area.


对于上面的原理,可以这么理解:

假设内存地址 A0 -- A31 对应于缓存行 X 。这块内存区同时被缓存到 CPU1 和 CPU2 中。

对于不是 P6 家族的处理器而言(Pentium4以前的处理器),为了原子性的访问这片内存区域,需要在访问这片内存区之前进行锁定(LOCK#)操作。比如 CPU1 和 CPU2 都要回写这片内存区,不管是 CPU1 还是 CPU2 谁先访问这片区域,它们都需要在访问前宣告一个 LOCK# 信号,以阻止对方和自己同时进入到其中。

对于 P6 家族的处理器,它们不需要在总线上宣告一个 LOCK# 信号,而是利用缓存锁定技术(cache locking,也就是缓存的相干性)达到原子访问的目的。比如 CPU1 要先回写内存,CPU2 后回写内存,那么 CPU2 会先锁定自己的那片缓存区,不让其和 CPU1 的回写产生竞争关系,当 CPU1 回写完毕后,自己才会回写。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-4-29 22:22 , Processed in 0.079843 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表