BUFFERABLE CACHEABLE

根据程序的局部性原理,在主存与CPU之间设置的一个高速的容量较小的存储器,叫做cache。

ARM cache架构由cache存储器和写缓冲器(write-buffer)组成。其中Write_buffer是cache按照FIFO原则向主存写的缓冲器。

cache可以分为Dcache,Icache。分别cache data和 instruction。其中Dcache必须在MMU开启后才能在CP15寄存器中使能,Icache在MMU未使能的情

                                             况下,也是可以使能的。

在armv6版本之前的memory attribute:

一般会在使能MMU的过程中,规定MMU page table的definition。其中20bit表示每一page的memory attributes。12位表示每一page的基地址。一共32

                                    位。每一page都会设置两个属性,cacheable,bufferable。其中每一page的memory attribute有

                                    strong ordered,

                                    Outer and inner write-back, write allocate,

                                    Outer and inner write-through, no write allocate,

                                    Outer and inner write-through, no write allocate,shared Device.

                                    Shared Device.

                                    non-cacheable.

 

MMU_CACHE:

                            .word            0x5000_0000|strong ordered;(其中strong order由20bit来表示)

其中arm的基本memory attribute有四种:

                                    NCNB(Non-cacheable,non-bufferable,Strongly-ordered),

                                    NCB(Non-cacheable,bufferable,Device),

                                    Write-Through Cacheable bufferable,

                                    Write-Back Cacheable bufferable

Write-Through方式:CPU向cache写入数据时,同时也向memory写一份,使得cache和memory的数据保持一致,缺点是每次都要访问memory,速度较

                                    慢。

Write-Back方式:CPU更新cache时,只是把更新的cache区标记一下,并不同步更新memory,只有在cache区被新进入的数据取代时,才更新memory。

                                    会引起memory和cache的一致性问题。

Write-allocate方式:在cache miss的情况下,先对存储器进行read操作,将操作数读入cache,在进行读写,这样便cache hit。 

 

Bufferable与non-bufferable的区别,主要表现在ack信号的返回上,bufferable--将结果写入buffer(某个component)便返回ack,

                                                                                         non-bufferable等到结果写入外存,返回ack。

 

  1. #define pgprot_noncached(prot) __pgprot(pgprot_val(prot) & ~(L_PTE_CACHEABLE | L_PTE_BUFFERABLE))
  2. #define pgprot_writecombine(prot) __pgprot(pgprot_val(prot) & ~L_PTE_CACHEABLE)


再结合网上的资料(不过我感觉那文章写的有些问题,我修改了一下),由上面代码可以看出,两个函数都调用了__dma_alloc函数,区别只在于最后一个参数。

dma_alloc_coherent 在 arm 平台上会禁止页表项中的 C (Cacheable) 域以及 B (Bufferable)域。而 dma_alloc_writecombine 只禁止 C (Cacheable) 域.

 C 代表是否使用高速缓冲存储器, 而 B 代表是否使用写缓冲区。

这样,dma_alloc_writecombine 分配出来的内存不使用缓存,但是会使用写缓冲区。而 dma_alloc_coherent  则二者都不使用。

C B 位的具体含义
0 0 无cache,无写缓冲;任何对memory的读写都反映到总线上。对 memory 的操作过程中CPU需要等待。
0 1 无cache,有写缓冲;读操作直接反映到总线上;写操作,CPU将数据写入到写缓冲后继续运行,由写缓冲进行写回操作。
1 0 有cache,写通模式;读操作首先考虑cache hit;写操作时直接将数据写入写缓冲,如果同时出现cache hit,那么也更新cache。
1 1 有cache,写回模式;读操作首先考虑cache hit;写操作也首先考虑cache hit。

这样,两者的区别就很清楚了。 

A = dma_alloc_writecombine(struct device *dev, size_t size,dma_addr_t *handle, gfp_t gfp);

含义:
A          : 内存的虚拟起始地址,在内核要用此地址来操作所分配的内存
dev      : 可以平台初始化里指定,主要是用到dma_mask之类参数,可参考framebuffer
size      : 实际分配大小,传入dma_map_size即可
handle: 返回的内存物理地址,dma就可以用。

A和hanle是一一对应的,A是虚拟地址,而handle是总线地址。对任意一个操作都将改变写缓冲区内容。

posted on 2022-05-31 11:43  tycoon3  阅读(1049)  评论(0)    收藏  举报

导航