1.Flush does write back the contents of cache to main memory,
and invalidate does mark cache lines as invalid so  that future reads go to main memory.

If your device changes an area of main memory, it is imperative that any processor caches covering that area be
invalidated; otherwise the processor may work with an incorrect image of main memory,
and data corruption results. Similarly, when your device uses DMA to read data
from main memory, any changes to that memory residing in processor caches must be
flushed out first.

 when will combine flush and invalidate operations for cache sync?

 if the device was updating a block of memory: the flush would ensure that the device had the latest contents, and the invalidate would then ensure that when the device had finished that the CPU would read the new contents from memory

=============================================================

1.Cache的两个类型
    --Write Through
    当写数据进Cache时,也同时更新了相应的Memory里的内容
    --Write back
    只是写到Cache里,Memory的内容要等到cache保存的要被别的数据替换或者系统做cache flush时,才会被更新。
2.Cache的两个函数
    --Flush
    把Cache内容写回Memory,当Cache为Write through,不需要Flush
    --Invalidate
    把Cache内容直接丢掉不要。
3.Cache的使用场合
    当有DMA在使用memory的时候,一般要用到cache的处理。因为DMA在访问memory时是不经过cache的。比较典型的比如在 Ethernet,wireless,USB等driver里,DMA会操作descriptors和packet buffers,Driver要做这些处理
    --如果driver使用descripter和packet buffer的地址都是cache的地址,那么
    a).Driver在读descripter里一些状态比如Owned by CPU/DMA,有没有收到包时,要对descripter当前结构里的内容做cache invalidate,收到packet后,也要对packet buffer做cache invalidate
    b).Driver在写descripter里一些状态比如Owned by DMA,要发送包时,要对descripter当前结构里的内容做cache flush,发送packet时,也要对packet buffer做cache flush
    --有些driver会对descripter使用uncache 地址,那么上面两种情况里invalidate/flush就不用做了。一般很少会对packet buffer也用uncache地址的,因为对packet内容的处理将会很频繁,使用uncache会很慢。而descripter一般由于结构比较小,如果也使用cache地址的话,做invalidate

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 horace papa 的頭像
    horace papa

    Horace papa's life

    horace papa 發表在 痞客邦 留言(0) 人氣()