• Xilinx cache刷新使用的问题


    前言

    PL和 PS 的高效交互是 zynq soc 开发的重中之重,我们常常需要将 PL 端的大量数据实
    时送到 PS 端处理,或者将 PS 端处理结果实时送到 PL 端处理,常规我们会想到使用 DMA 的
    方式来进行,但是各种协议非常麻烦,灵活性也比较差,本节讲解如何Cache
    来读写 PS 端 ddr 的数据。

    为什么引进Cache

    PS与PL都是独立运行的,PS通过DDR控制器来对DDR存储器进行访问。为了加速,常常将32字节数据缓存到Cache中,而不是针对一个数据进行缓存,;Xilinx成为一行,即Line。优势:可以加速访问的速度。劣势:就是Cache中的数据发生了变化,不能迅速反应到DDR4中实际的数据。 同样当DDR4中的数据发成了更新也不能快速的反映到cache中。因此当PL或是PS不同的核通过DMA修改了DDR4数据时,PS端使用的CPU还不能及时获取发生的东西,拿到的数据仍然是Cache中没有修改过的数据。

    解决Cache刷新不一致方法

    禁用Cache

    #include “xil_cache.h”
    void Xil_DCacheDisable(void);
    xixlinx 默认在硬件平台层会把cache打开,若需禁用需调用上述的函数。这样CPU将直接访问内存,读写都是直接的。问题:这样极大的降低了CPU的性能,大大降低了读写速度。

    使用Cache刷新技术

    Cache Flush

    Flush就是把Cache里的数据流放出去,清空Cache,也就是将Cache的内容推到DDR中去。
    使用的示例:
    #include “xil_cache.h”
    /****************************************************************************

    • @brief Flush the Data cache for the given address range.
    •        If the bytes specified by the address (adr) are cached by the
      
      • 1
    •        Data cache, the cacheline containing that byte is invalidated.
      
      • 1
    •        If the cacheline is modified (dirty), the written to system
      
      • 1
    •        memory first before the before the line is invalidated.
      
      • 1
    • @param Addr: Start address of range to be flushed.
    • @param Len: Length of range to be flushed in bytes.
    • @return None.

    ****************************************************************************/
    Xil_DCacheFlushRange(Addr, Len)

    刷新一行数据

    注意事项:刷新必须是32b的整数倍。
    Xil_DCacheFlushLine((INTPTR)&PCTransmit_RingBuffer_Acore);

    刷新一段数据

    Xil_DCacheFlushRange((INTPTR)pTransmitBuffer,sizeof(TransmitBuffer_Type));

    Cache Invalidate

    Invalidate表示当场宣布Cache里的内容无效,需要从DDR中重新加载,即把数据从DDR中拉到Cache中来。
    /****************************************************************************
    *

    • @brief Invalidate the Data cache for the given address range.
    •       If the bytes specified by the address (adr) are cached by the
      
      • 1
    •       Data cache, the cacheline containing that byte is invalidated.
      
      • 1
    •       If the cacheline is modified (dirty), the modified contents are
      
      • 1
    •       lost and are NOT written to system memory before the line is
      
      • 1
    •       invalidated.
      
      • 1
    • @param Addr: Start address of ragne to be invalidated.
    • @param Len: Length of range to be invalidated in bytes.
    • @return None.

    ****************************************************************************/

    无效一行数据

    Xil_DCacheInvalidateLine((INTPTR)&PCTransmit_RingBuffer_Rcore);

    无效一段数据

    Xil_DCacheInvalidateRange(Addr, Len)

  • 相关阅读:
    ​vmware虚拟机ubuntu系统配置静态ip​
    线程间实现通信的几种方式
    Java 基于 SpringBoot 的校园疫情防控系统
    501. 二叉搜索树中的众数
    Java调用Web Service接口
    ssm人事管理系统
    别再羊了个羊了,大家都在玩刷了个题——LeetCode刷题第3周小结
    priority_queue 模拟实现
    mysql数据库重启、登录mysql数据库、通过命令执行mysql的sql脚本等命令
    图片叠加_图片压缩
  • 原文地址:https://blog.csdn.net/qq_35968965/article/details/125619485