关于SMP cpu cache同步的问题请教大虾
首先说一下我对SMP cpu cache同步的理解,如有不对,请大虾指正:当某个cpu将自己cache里的数据写入内存时,其他cpu都被通知到这个情况,如果这些cpu中有某个cpu的cache中有这些数据的备份,则该cpu更新自己的cache。如果我以上的认识是正确的的话,那么是不是在释放spinlock时系统都会保证释放自旋锁的cpu会将自己的cache中的数据写入内存,从而使引用该内存的其他cpu也能更新自己的cache?因为我感觉如果不是的话,每个cpu都仅仅使用自己的cache而又不同步,那么spinlock的存在就没有意义。 Intel、AMD、IBM、SUN、ARM的各不相同。 我想了解intel和arm的,能详细讲讲吗?谢谢。 在ULK3里找着答案了。
Multiprocessor systems have a separate hardware cache for every processor, and therefore they need additional hardware circuitry to synchronize the cache contents. As shown in Figure 2-11, each CPU has its own local hardware cache. But now updating becomes more time consuming: whenever a CPU modifies its hardware cache, it must check whether the same data is contained in the other hardware cache; if so, it must notify the other CPU to update it with the proper value. This activity is often called cache snooping . Luckily, all this is done at the hardware level and is of no concern to the kernel. 如果俩CPU同时操作cache line里面的不同部分,A CPU操作了以后,改变了内容,会导致B CPU的cache失效,然后B CPU又会重新刷一份,同步一下. 关于缓存一致性,建议楼主google一下request for owner。有些文档说的比较详细,当然说的最详细的还是CPU手册。:-)
缓存一致性在不同的CPU上有不同的实现,不过具体这些实现细节,只要我们不涉及汇编,或者说不涉及MMU,核间通讯或者DMA操作之类的底层实现,基本上不用管。楼主提到的自旋锁其实主要还是原子操作的问题(当然也和缓存一致性有些关系,但是不用考虑的那么底层),建议你看看关心的体系架构的原子操作的实现就明白了。
页:
[1]