缓存一致性的要点是什么? [英] What's the point of cache coherency?

查看:202
本文介绍了缓存一致性的要点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像x86这样的提供缓存一致性的CPU上,从实际的角度来看,这有什么用?我理解这个想法是使内存更新在一个核上立即在所有其他内核上可见。这是一个有用的属性。然而,如果不使用汇编语言编写,则不能太依赖它,因为编译器可以将变量分配存储在寄存器中,而不会将其写入存储器。这意味着,还必须采取明确的步骤,以确保在其他线程中完成的东西在当前线程中可见。因此,从实际角度来看,缓存一致性是如何实现的?

On CPUs like x86, which provide cache coherency, how is this useful from a practical perspective? I understand that the idea is to make memory updates done on one core immediately visible on all other cores. This is a useful property. However, one can't rely too heavily on it if not writing in assembly language, because the compiler can store variable assignments in registers and never write them to memory. This means that one must still take explicit steps to make sure that stuff done in other threads is visible in the current thread. Therefore, from a practical perspective, what has cache coherency achieved?

推荐答案

b

lock(); //some synchronization primitive e.g. a semaphore/mutex
globalint = somevalue;
unlock();

如果没有缓存一致性,最后 unlock c $ c>必须确保 globalint 现在可以随处可见,使用缓存coherance所有你需要做的是将它写入内存,让硬件做的魔法。软件解决方案会保留哪些内存存在于哪些缓存,哪些核心,并以某种方式确保它们原子级同步。

If there were no cache coherence, that last unlock() would have to assure that globalint are now visible everywhere, with cache coherance all you need to do is to write it to memory and let the hardware do the magic. A software solution would have keep tack of which memory exists in which caches, on which cores, and somehow make sure they're atomically in sync.

你会赢得如果您能找到一个软件解决方案,跟踪缓存中存在的所有内存,需要保持同步,这比当前的硬件解决方案更高效。

You'd win an award if you can find a software solution that keeps track of all the pieces of memory that exist in the caches that needs to be keept in sync, that's more efficient than a current hardware solution.

这篇关于缓存一致性的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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