多核x86系统,是互斥使用LOCK'd指令实现? [英] On multicore x86 systems, are mutexes implemented using a LOCK'd instruction?

查看:356
本文介绍了多核x86系统,是互斥使用LOCK'd指令实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在86装配有可以被应用到一个指令,使之原子一个LOCK preFIX。这是原子在所有核心?什么是平常延迟为何?对于常规的互斥体,是什么指令是它那是锁着的?

In x86 assembly there is a LOCK prefix that can be applied to an instruction to make it atomic. Is this atomicity across all cores? What is the usual delay involved? For a regular mutex, what instruction is it that's locked?

感谢。
PS:我被教导上缺乏这样互斥仍然可以做到的指令系统,但它是更费力。我不知道是否有人不这么认为了。

Thanks. PS: I was taught that on systems that lack such an instruction that mutexes can still be done but it is more laborious. I wonder if anyone does it that way any more.

推荐答案

在86锁定preFIX锁定所有核心和允许原子。对于在其他系统上执行本无锁,CMPXCHG循环使用或重试逻辑试图东西值设置为预期值紧密循环。正如你所看到的第二个方法是更不利在大多数情况下,它只是不断循环试图设置的值(和一直这样做,直到它完成)。对于x86延迟是最小的,因为它取决于多少争没有为可能的范围从停止指令流水线或冲洗,然后以原子执行该指令(通常几个cylces的),第二方法不能真正被估计需要值以原子修改。对于互斥的,我相信,它是必须获得的一个标志值(检查互斥未获取不断等到互斥的争夺然后尝试原子改变旗号获取它)。

On x86 lock prefix locks all cores and allows atomicity. For implementing this on other systems without LOCK, CMPXCHG loops are used or tight loops with retry logic that attempt to set the value of something to the expected value. As you can see the 2nd way is more detrimental in most cases as it's just constantly looping trying to set the value (and keeps doing so until it's done). For x86 the delay is minimal and might range from halting the instruction pipeline or flushing it and then executing that instruction atomically (typically a couple of cylces), the 2nd method can't really be estimated as it depends how much contention there is for the value that needs to be modified atomically. For mutex's I believe that it's a flag value that must be acquired (check that the mutex isn't acquired and continuously wait until the mutex is up for grabs then attempt to atomically change a flag to acquire it).

据我所知IBM处理器使用第2种方法在Linux内核上我发现了原子递增的功能使用它(也许这只是老年处理器)工作时。在x86平台仍然采用

AFAIK IBM processors use the 2nd method as when working on the linux kernel I found that the atomic increment function uses it (maybe it's only for older processors). The x86 platform still uses

锁ADDL ...;

lock addl ...;

我会承认,虽然它已经一年左右,因为我在内核中的这一部分工作,所以我可能是错的一些要点。

I will admit though that it's been about a year since I worked in this part of the kernel so I could be wrong on some points.

这篇关于多核x86系统,是互斥使用LOCK'd指令实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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