• 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)

  • 相关阅读:
    c# 控制台应用程序
    x64内核实验5-API进0环
    【新闻稿】Solv 与 zCloak 联合开发跨境贸易场景下可编程数字凭证项目,获得新加坡、加纳两国央行支持...
    VSCode 居然是个娱乐软件?让你 high 到爆的几款插件
    [Dubbo3.0.8源码解析系列]-26-消费者一个服务是如何通过RPC调用到提供者的
    基于小波变换编码的纹理图像分割
    shell编程(五):大小写转换
    3.Vue-在Vue框架中搭建路由
    【XInput】游戏手柄模拟鼠标动作
    微电网优化调度(风、光、储能、柴油机)(Python代码实现)
  • 原文地址:https://blog.csdn.net/qq_35968965/article/details/125619485