This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/AM5728:PRU 代码优化

Guru**** 3040470 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/864957/ccs-am5728-pru-code-optimization

器件型号:AM5728

工具/软件:Code Composer Studio

我现在正在使用 C++来进行 PRU,并遇到了一个问题,IMEM (指令内存,12KB) 令人不知所措

我应该如何优化我的代码。 这是  我的 PRU 代码的映射(由于.text 已加载到 IMEM 中,因此只有.text 部分), 任何建议都将得到感谢。

我想知道 为什么 Vla_alloc.c.obj 会占用如此多的 IMEM 空间

.text 0 0000001c 00002f68
0000001c 00000770 main.obj (.text:main)
0000078c 00000244 rtspruv3_le.lib:vla_alloc.c.obj (.text:__Vla_alloc)
000009d0 00000200 rruner.obj (.text:_ZN8Rtruner13handle_normalev)
00000bd0 000001dc wdbuf.obj (.text:_ZN5wdbuf12wdbuf_createEPKcj)
00000dac 000001d4. rtspruv3_le.lib:memory.c.obj (.text:realloc)
00000f80 000001bc. rruner.obj (.text:_ZN8Rtruner19ence_Write_TO_RcsEi)
0000113c 00000168 rruner.obj (.text:_ZN8RtrunerC1Ev)
000012a4 00000154 rtspruv3_le.lib:memory.c.obj (.text:malloc)
000013f8 00000128 UART_COMM.obj (.text:_ZN8UARTComm4readEP13BufferFromDSPi)
00001520 00000124 rcs_comm.obj (.text:_ZN7RCSComm4readEP13BufferFromRCS)
00001644 00000120 rruner.obj (.text:_ZN8Rtruner19ence_Write_TO_Dspei)
00001764 0000011c rruner.obj (.text:_ZN8Rtruner20generateDspWritebuffei)
00001880 00000114 rfrter.obj (.text:_ZN8Rtruner18generateIniBufToWdEi)
00001994 000000e8. rrunter.obj (.text:_ZN8Rtruner16handle_server_stoEv)
00001a7c 000000e0 rwdevice_wd.obj (.text:_ZN2Wd5writeEPKhRKj)
00001b5c 000000e0 rruner.obj (.text:_ZN8Rtruner18ence_Write_TO_WdEv)
00001c3c 000000dc rwdevice_wd.obj (.text:_ZN2Wd4readEPhRKj)
00001d18 000000d8 rtspruv3_le.lib:vla_alloc.c.obj (.text:_Z21free_deate_allocationsPv$33)
00001df0 000000d8 rpmsg_lib.lib:PRU_rpmsg.object (.text:PRU_rpmsg_send)
00001ec8 000000c4 :PRU_rpmsg.object (.text:PRU_rpmsg_receive)
00001f8c 000000c0 route_list.obj (.text:_ZN9RouteList5popUpEPhj)
0000204c 000000b8 rtspruv3_le.lib:vla_alloc.c.obj (.text:__Vla_dealloc)
00002104 000000b0 rwdevice_rpmsg.obj (.text:_ZN5Rpmsg4initEPv)
000021b4 000000b0 route_list.obj (.text:_ZN9RouteList8pushBackEPKhj)
00002264 000000a8 rtspruv3_le.lib:memory.c.obj (.text:free)
0000230c 000000a0 rwdevice_wd.obj (.text:_ZN2WdD1Ev)
000023ac 00000094 rwdevice_rpmsg.obj (.text:_ZN5Rpmsg4readEPhRKj)
00002440 00000088 route_list.obj (.text:_ZN9RouteList7getDataEPhj)
000024c8 00000070 rwdevice_UART.obj (.text:_ZN4Uart5writeEPKhRKj)
00002538 00000064 rwdevice_rpmsg.obj (.text:_ZN5Rpmsg5writeEPKhRKj)
0000259c 00000060 rruner.obj (.text:_ZN8RtrunerD1Ev)
000025fc 00000060 rpmsg_lib.lib:PRU_rpmsg.object (.text:PRU_rpmsg_init)
0000265c 00000060 :PRU_virtqueue.object (.text:PRU_virtqueue_get_ave_buf)
000026bc 00000060 :pru_virtqueue.object (.text:pru_virtqueue_init)
0000271c 0000005c rwdevice_UART.obj (.text:_ZN4Uart4initEPv)
00002778 0000005c rpmsg_lib.lib:PRU_rpmsg.object (.text:PRU_rpmsg_channel)
000027d4 0000005c :PRU_virtqueue.object (.text:PRU_virtqueue_add_used_buf)
00002830 00000054 Buffer_from_rc.obj (.text:_ZN13BufferFromRCSC1Ev)
00002884 00000054 crc.obj (.text:_ZN3CRC9crc_ccittEPKhi)
000028d8 00000050 rwdevice_UART.obj (.text:_ZN4Uart4readEPhRKj)
00002928 00000044 PRU_LIST.obj (.text:_ZN7PruList8pushBackEPKhj)
0000296c 00000044 route_list.obj (.text:_ZN9RouteList7freeMemEv)
000029b0 0000003c Buffer_TO_DSP.obj (.text:_ZN11BufferToDSP7setDataEPKhjj)
000029ec 0000003c Buffer_TO_DSP.obj (.text:_ZN11BufferToDSPD1Ev)
00002a28 0000003c Buffer_TO_RC.obj (.text:_ZN11BufferToRCS7setDataEPKhjj)
00002a64 0000003c Buffer_TO_RC.obj (.text:_ZN11BufferToRCSD1Ev)
00002aa0 0000003c Buffer_from_dsp.obj (.text:_ZN13BufferFromDSPD1Ev)
00002adc 0000003c Buffer_from_rc.obj (.text:_ZN13BufferFromRCSD1Ev)
00002b18 00000038 rwdevice_wd.obj (.text:_ZN2Wd4initEPv)
00002b50 00000038 Buffer_TO_RC.obj (.text:_ZN9RWBufBase10updateDataEPKhj)
00002b88 00000034 Buffer_TO_DSP.obj (.text:_ZN11BufferToDSPC1Ev)
00002bbc 00000034 Buffer_TO_RC.obj (.text:_ZN11BufferToRCSC1Ev)
00002bf0 00000034 Buffer_from_dsp.obj (.text:_ZN13BufferFromDSPC1Ev)
00002c24 00000034 rtspruv3_le.lib:memcpy.asm.obj (.text)
00002c58 00000030 pru_counter_operation.obj (.text:_Z19Restart_PRU_counv)
00002c88 00000028 rcs_comm.obj (.text:_ZN7RCSCommC1Ev)
00002cb0 00000028 route_list.obj (.text:_ZN9RouteListC1Ev)
00002cd8 00000028 route_list.obj (.text:_ZN9RouteListD1Ev)
00002d00 00000028 rpmsg_lib.lib:PRU_virtqueue.object (.text:PRU_virtqueue_kick)
00002d28 00000024 Buffer_TO_DSP.obj (.text:_ZN11BufferToDSP11setRoutePosEPKhj)
00002d4c 00000024 Buffer_TO_DSP.obj (.text:_ZN11BufferToDSP14setControlFlagEPKhj)
00002d70 00000024 rtspruv3_le.lib:mpyi.c.obj (.text:_pruabi_mpyi)
00002d94 00000020 wdbuf.obj (.text:_Z6strcpyPcPKc$24)
00002db4 00000020 rwdevice_wd.obj (.text:_ZN2WdC1Ev)
00002dd4 00000020 rtspruv3_le.lib:new.c.obj (.text:_Znwj)
00002df4 0000001c PRU_LIST.obj (.text:_ZN7PruListC1Ev)
00002e10 00000018 rtspruv3_le.lib:typeinfo.c.obj (.text:_ZN10__cxxabiv117__class_type_infoD0Ev)
00002e28 00000018 :typeinfo.c.obj (.text:_ZN10__cxxabiv120__si_class_type_infoD0Ev)
00002e40 00000018 rwdevice_UART.obj (.text:_ZN4UartC1Ev)
00002e58 00000018 UART_COMM.obj (.text:_ZN8UARTCommC1Ev)
00002e70 00000018 prulogger.obj (.text:_ZN9PruloggerC1Ev)
00002e88 00000018 rtspruv3_le.lib:error.c.obj (.text:_abort_execution)
00002ea0 00000018 :memset.c.obj (.text:memset)
00002eb8 00000014 prulogger.obj (.text:_ZN9PruloggerD1Ev)
00002ecc 00000010 pru_counter_operation.obj (.text:_Z21get_PRU_counter_valueev)
00002edc 00000010 Buffer_from_rcs.obj (.text:_ZN13BufferFromRCS14getControlFlagEv)
00002eec 00000010 Buffer_from_rcs.obj (.text:_ZN13BufferFromRCS5getIDEv)
00002efc 00000010 Buffer_from_rcs.obj (.text:_ZN13BufferFromRCS8getParamEv)
00002f0c 00000010 rtspruv3_le.lib:delete.c.obj (.text:_ZdlPv)
00002f1c 0000000c Buffer_from_dsp.obj (.text:_ZN13BufferFromDSP12getTimestampEv)
00002f28 0000000c Buffer_from_dsp.obj (.text:_ZN13BufferFromDSP13getServoBrakeEv)
00002f34 0000000c Buffer_from_dsp.obj (.text:_ZN13BufferFromDSP6getAckEv)
00002f40 0000000c Buffer_from_dsp.obj (.text:_ZN13BufferFromDSP6getPosEv)
00002f4c 00000008 rrunger.obj (.text:_ZN8Rtruner7getdiffEhh)
00002f54 00000008 rfrter.obj (.text:_ZN9RWBufBase10getDataPtrEv)
00002f5c 00000008 Buffer_TO_RC.obj (.text:_ZN9RWBufBase13getDataLengthEv)
00002f64 00000008 route_list.obj (.text:_ZN9RouteList11getRouteLenEv)
00002f6c 00000008 rtspruv3_le.lib:exit.c.obj (.text:abort)
00002f74 00000008 :exit.c.obj (.text:loader_exit)
00002f7c 00000004 :typeinfo.c.obj (.text:_ZN10_cxxabiv117__class_type_infoD1Ev)
00002f80 00000004 :typeinfo.c.obj (.text:_ZN10__cxxabiv120__si_class_type_infoD1Ev) 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    程序必须使用可变长度数组。  有些东西像...

    int example_function (int length)
    {
    int array[length];/*可变长度 array */
    ... 

    这是通过调用 RTS 中名为__VLA_alloc 的函数来实现的。  如您所见、该函数占用大量代码空间。

    您最好的解决方案可能是将代码更改为不使用可变长度数组。

    谢谢、此致、

    乔治

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    George 您好:

    我已经尝试使用 可变长度数组来删除代码。 但是 、__VLA_alloc 仍然占用很大一部分代码空间。

    我可以随意地看到 、pru_virio_ring.h 使用了大量 可变长度数组、由 TI 集团维护。  

    如下面所示的环[]

    struct vring_avail{
    uint16_t flags;
    uint16_t idx;
    uint16_t ring [];
    };
    
    // u32在此处用于填充 ID。 //
    struct vring_used_elem{
    //已用描述符链起始索引。 //
    uint32_t id;
    //使用的描述符链的总长度(写入)*/
    uint32_t len;
    };
    
    struct vring_used{
    uint16_t flags;
    uint16_t idx;
    struct vring_used_elem ring [];
    }; 

     

    谢谢、此致、

    Philos

     

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这些结构定义不一定意味着使用了 VLA。   

    我假设您使用 Code Composer Studio (CCS)构建和运行项目。  请使用菜单选择 View | Stack Usage 查看调用图。  在其中搜索 _VLA_alloc 以查找对该函数的调用。  查看呼叫者。

    谢谢、此致、

    乔治