Linux Kernel之flush_cache_all在ARM平台下是如何实现的【转】

简介:

转自:http://blog.csdn.net/u011461299/article/details/10199989

在驱动程序的设计中,我们可能会用到flush_cache_all将ARM cache的内容刷新到RAM,这是因为ARM Linux中cache一般会被设定为write back的。而通常象DMA是访问不了cache,所以如果我们需要启动DMA将RAM中的内容写到Flash中或LCD framebuffer,那么我们就需要调用flush_cache_all将cache中最新的内容刷新到RAM中。如果不这样做在LCD中可能会出现花屏。本文主要分析在ARM平台上到底如何实现的。

1.1                   flush_cache_all在ARM Linux中的实现

在include/asm-arm/cacheflush.h中:

#define flush_cache_all()             __cpuc_flush_kern_all()

#define __cpuc_flush_kern_all            cpu_cache.flush_kern_all

 

在setup_processor():

list = lookup_processor_type(processor_id);

//根据processor id找到对应ARM CPU(常见的如ARM926)相关的信息,存在list中。如果想把事情彻底搞清楚,必然要问processor_id是怎么来。它是在Linux Kernel启动时候从ARM chip中读出来。如果以后有机会大家一起讨论ARM Linux的启动全过程,可以详细分析。

      cpu_cache = *list->cache;

 

而lookup_processor_type定义在arch/arm/kernel/head-comman.S中:相应的assembler code如下:

     .type __lookup_processor_type, %function

__lookup_processor_type:

   adr   r3, 3f

   ldmda       r3, {r5 - r7}

   sub  r3, r3, r7                      @ get offset between virt&phys

   add  r5, r5, r3                      @ convert virt addresses to

   add  r6, r6, r3                      @ physical address space

1:         ldmia        r5, {r3, r4}                    @ value, mask

   and  r4, r4, r9                      @ mask wanted bits

   teq    r3, r4

   beq  2f

   add  r5, r5, #PROC_INFO_SZ            @ sizeof(proc_info_list)

   cmp r5, r6

   blo    1b

   mov  r5, #0                                    @ unknown processor

2:         mov  pc, lr

 

/*

 * This provides a C-API version of the above function.

 */

ENTRY(lookup_processor_type)

   stmfd        sp!, {r4 - r7, r9, lr}

   mov  r9, r0

   bl      __lookup_processor_type

   mov  r0, r5

   ldmfd        sp!, {r4 - r7, r9, pc}

 

/*

 * Look in include/asm-arm/procinfo.h and arch/arm/kernel/arch.[ch] for

 * more information about the __proc_info and __arch_info structures.

 */

   .long          __proc_info_begin

   .long          __proc_info_end

3:         .long          .

   .long          __arch_info_begin

   .long          __arch_info_end

 

它其实就是到__proc_info_begin开始的section中去找到对应当前SOC中用的CPU Cache相关的operation list

再由arch/arm/kernel/vmlinux.lds.S可以__proc_info_begin就是section *(.proc.info.init)的开始地址。

            __proc_info_begin = .;

                   *(.proc.info.init)

            __proc_info_end = .;

而我们知道我们所用是ARM926,所以其定义在arch/arm/mm/proc-arm926.S:

     .section ".proc.info.init", #alloc, #execinstr

     .type       __arm926_proc_info,#object

__arm926_proc_info:

  .long       0x41069260                  @ ARM926EJ-S (v5TEJ)

  .long       0xff0ffff0

  .long   PMD_TYPE_SECT | \

         PMD_SECT_BUFFERABLE | \

         PMD_SECT_CACHEABLE | \

         PMD_BIT4 | \

         PMD_SECT_AP_WRITE | \

         PMD_SECT_AP_READ

  .long   PMD_TYPE_SECT | \

         PMD_BIT4 | \

         PMD_SECT_AP_WRITE | \

         PMD_SECT_AP_READ

  b     __arm926_setup

  .long       cpu_arch_name

  .long       cpu_elf_name

  .long         HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA

  .long       cpu_arm926_name

  .long       arm926_processor_functions

  .long       v4wbi_tlb_fns

  .long       v4wb_user_fns

  .long       arm926_cache_fns

     .size       __arm926_proc_info, . - __arm926_proc_info

arm926_cache_fns定义在同一个文件中,如下:

ENTRY(arm926_cache_fns)

  .long       arm926_flush_kern_cache_all

  .long       arm926_flush_user_cache_all

  .long       arm926_flush_user_cache_range

  .long       arm926_coherent_kern_range

  .long       arm926_coherent_user_range

  .long       arm926_flush_kern_dcache_page

  .long       arm926_dma_inv_range

  .long       arm926_dma_clean_range

  .long       arm926_dma_flush_range

 

它所对应的struct的定义:(include/asm-arm/cacheflush.h)

struct cpu_cache_fns {

  void (*flush_kern_all)(void);

  void (*flush_user_all)(void);

  void (*flush_user_range)(unsigned long, unsigned long, unsigned int);

 

  void (*coherent_kern_range)(unsigned long, unsigned long);

  void (*coherent_user_range)(unsigned long, unsigned long);

  void (*flush_kern_dcache_page)(void *);

 

  void (*dma_inv_range)(const void *, const void *);

  void (*dma_clean_range)(const void *, const void *);

  void (*dma_flush_range)(const void *, const void *);

};

所以其实flush_cache_all 在我们的项目中就是arm926_flush_kern_cache_all:其实现在同一个文件中:

/*

 *   flush_kern_cache_all()

*  Clean and invalidate the entire cache.

 */

ENTRY(arm926_flush_kern_cache_all)

  mov r2, #VM_EXEC

  mov ip, #0

__flush_whole_cache:

#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH

  mcr  p15, 0, ip, c7, c6, 0              @ invalidate D cache

#else

1:      mrc  p15, 0, r15, c7, c14, 3   @ test,clean,invalidate

  bne  1b

#endif

  tst   r2, #VM_EXEC

  mcrne     p15, 0, ip, c7, c5, 0              @ invalidate I cache

  mcrne     p15, 0, ip, c7, c10, 4            @ drain WB

  mov pc, lr

 

最后我们它不仅仅flush 所有的cache(包括ICache和DCache),也flush了Write Buffer。

















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5896366.html ,如需转载请自行联系原作者

相关文章
|
5天前
|
SQL Linux 调度
Timeplus Enterprise 3.0 (Linux, macOS) - 流处理平台
Timeplus Enterprise 3.0 (Linux, macOS) - 流处理平台
34 2
Timeplus Enterprise 3.0 (Linux, macOS) - 流处理平台
|
1月前
|
安全 Linux API
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
73 0
|
Unix Linux iOS开发
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
52 0
|
4月前
|
Ubuntu Linux Shell
Linux环境下VSCode快速安装终极指南:debian/ubuntu/linux平台通用
以上就是在Linux环境下安装VSCode的终极指南,抛开繁复的专业词汇,以平易近人的文字、形象生动的比喻让你轻松学会这一过程。别忘了,你的小伙伴VSCode已经在应用菜单里等你了!
939 23
|
5月前
|
Java 关系型数据库 MySQL
在Linux平台上进行JDK、Tomcat、MySQL的安装并部署后端项目
现在,你可以通过访问http://Your_IP:Tomcat_Port/Your_Project访问你的项目了。如果一切顺利,你将看到那绚烂的胜利之光照耀在你的项目之上!
302 41
|
5月前
|
安全 前端开发 Linux
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
165 3
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
|
4月前
|
Dart Linux iOS开发
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
232 0
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
|
7月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
9月前
|
机器学习/深度学习 边缘计算 PyTorch
PyTorch团队为TorchAO引入1-8比特量化,提升ARM平台性能
PyTorch团队推出创新技术,在其低精度计算库TorchAO中引入低位运算符支持,实现1至8位精度的嵌入层权重量化及8位动态量化激活的线性运算符。该技术通过模块化设计和高效硬件利用,优化了资源受限环境下的深度学习计算,提升了计算效率并降低了资源消耗。新内核与PyTorch生态系统无缝集成,支持即时执行、编译优化及边缘计算,为开发者提供全方位性能优势。测试结果显示,多层次量化策略显著提升了计算效率,保持了模型精度。这一突破为深度学习框架优化开辟了多个研究方向,推动了人工智能在边缘计算等领域的广泛应用。
262 11
PyTorch团队为TorchAO引入1-8比特量化,提升ARM平台性能
|
9月前
|
前端开发 Java 编译器
阿里巴巴生态应用在Arm平台性能优化实践
本次方案的主题是阿里巴巴生态应用在 Arm 平台性能优化实践,分别从背景介绍、编译优化实践、总结和展望三个方面介绍了本主题。 1. 背景介绍 2. 编译优化实践 3. 总结和展望
176 3