先决条件 – 缓存一致性
缓存一致性:
在多处理器系统中,每个处理器都可以有自己的缓存,当允许处理器更新各自缓存块的数据时,数据将处于不一致状态。这个问题称为缓存一致性。
缓存一致性协议:
为了保持数据一致,使用了缓存一致性协议。这些协议更新多处理器系统中的缓存副本。在总线侦听机制中,处理器侦听(监视)总线并对相关事件(数据更新)采取适当的行动,以确保数据的一致性。
通常用于更新缓存副本的 2 个协议是 –
- 写更新协议
- 写无效协议
写更新协议:
使用此协议,如果处理器更新其缓存数据,它也会立即更新所有其他缓存副本。广播机制用于将新数据块发送到所有具有副本的缓存。
写无效协议:
这里,没有立即将更新的缓存块发送到另一个缓存。简单地说,一个无效命令被发送到所有其他缓存副本以及共享内存中的原始版本,以便它们的所有数据副本都变为无效。它由“I”表示,I 指定无效/脏数据。
如果现在任何其他处理器(更新其缓存数据的更新处理器除外)想要读取数据(缓存副本),则更新处理器向其提供更新的数据。 write-invalidate 方法用于多处理器系统,例如 Pentium 4 和 PowerPC。
写入无效协议和写入更新协议之间的区别:
Write invalidate protocol | Write Update Protocol | |
1. | One initial invalidation is required when multiple writes to the same word is done with no intervening reads. | Multiple write broadcasts are required when multiple writes to the same word is done with no read is done in between. |
2. | With multiword cache blocks, only the first write to any of the word in the block need to generate an invalidate. This protocol works on cache blocks. | A write broadcast is required when each word is written in a cache block with multiword cache blocks. This protocol works on individual words.(bytes) |
3. | Longer time is taken (by the other non-updating processor) because any read to invalidate data requires you to fetch a new copy of data from the updating processor(its cache has updated data). | Less time is taken to read the data because the data written by the updating processor is immediately updated in another cache as well. (reading processor should have a data copy beforehand) (Although updating all the cache copies may take some time initially) |
4. | Since the written data is not instantly updated in the reader’s cache, the delay between writing a word in one processor and reading the written value in another processor is larger than the write Update. | Since the written data is instantly updated in the reader’s cache, the delay between writing a word in one processor and reading the written value in another processor is normally shorter in a write update scheme. |
5. | Updated data is given to the processor who requires it. | Updated data is given to the processors who contain the same cache block copy that was updated. |
6. | Whenever a processor modifies data frequently, updated data is sent to the processor who requires it. No need to broadcast again & again after every modification in the data. | Whenever a processor modifies data frequently, for every modification, write broadcast is required to be done . Write broadcast is done as many times as modifications are done. |