linux kernel中cache代码解读

1、 在kernel中调用__dma_flush_range,底层是如何操作的呢?

/* remove any dirty cache lines on the kernel alias */
	__dma_flush_range(ptr, ptr + size);
/*
 *	__dma_flush_range(start, end)
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 */
ENTRY(__dma_flush_range)
	dcache_line_size x2, x3    //获取cache line size, 保存在x2中
	sub	x3, x2, #1			//x3=x2-1,用于对其的Mask
	bic	x0, x0, x3			//地址对齐,x0就是__dma_flush_range(ptr, ptr + size)中的ptr虚拟地址
1:	dc	civac, x0			// invalid一行cache line,下面这一段是一个循环
	add	x0, x0, x2			//x0 = x0 + cache line size
	cmp	x0, x1				//比较x0和__dma_flush_range(ptr, ptr + size)中的ptr+size
	b.lo	1b
	dsb	sy
	ret
ENDPIPROC(__dma_flush_range)
/*

 * dcache_line_size - get the minimum D-cache line size from the CTR register.
 */
	.macro	dcache_line_size, reg, tmp
	mrs	\tmp, ctr_el0			// read CTR
	ubfm	\tmp, \tmp, #16, #19		// cache line size encoding
	mov	\reg, #4			// bytes per word
	lsl	\reg, \reg, \tmp		// actual cache line size

附上civac的寄存器和指令:
linux kernel中cache代码解读

最后总结一下,__dma_flush_range(ptr, ptr+size)其实就是 invalid cache这一段虚拟地址

上一篇:树莓派4B 汇编实现串口打印


下一篇:MATLAB拟牛顿法之DFP与BFGS算法