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.

Utils_memAlloc_cached() cost too much time

Dear expert,

My customer report that the Utils_memAlloc_cached() cost too much time on DM8148's DSP(C674+). 

Their test on 20K memory shows:

alloc & free memory for 50 times: 19ms

alloc  memory only,   for 50 times: 9ms

Free  memory only,   for 50 times: 5ms


My question is, is this benchmark really shows an abnormal situation? What can we suggest customer do?

Thanks & Best Regards,

Eason

  • What RDK is this ? I don't see such an API in DVR RDK. Anyhow alloc and free should take insignificant time essentially. Utils_memAlloc does memset of the allocated memory if

    gUtils_memClearBuf[<heap_id>] is set to TRUE (by default it is set to TRUE).

    First try setting it to FALSE in

    /dvr_rdk/mcfw/src_bios6/utils/src/utils_mem.c

    Int32 Utils_memClearOnAlloc(Bool enable)
    {
        UInt32 i;

        for (i=0; i<UTILS_MEM_NUM_SHARED_REGION_HEAP; i++)
        {
            gUtils_memClearBuf[i] = FALSE;
        }
        return 0;
    }

    This will confirm if the time taken is due to clearing memory. Even so Utils_memFree will not take any time unless some Cache operation is done on the freed memory.

    If you still see large time even after disabling memory clear it means alloc/free is itself taking lot of time which can happen only if there is contention for the GateMP lock when trying to allocate or free memory.

     

  • Hi,Badri Narayanan

    what's the difference between Utils_memAlloc and  Utils_memAlloc_cached?

    It seems the difference is as the name mean,memory alloc by  Utils_memAlloc_cached are cached.

    but the code of them are almost same.

    why?

    thank you.

  • As I mentioned I don't see such an API in DVR RDK 4.0 release so I don't know what the function is doing. Usually memAlloc_cached will allocate from a SharedRegion where caching is enabled. If you can paste the code of both the fucntions I can confirm.

  • thanks you.

    i'm using DM8127 IPNC RDK 3.5.

    Ptr Utils_memAlloc(UInt32 size, UInt32 align)
    {
        Ptr addr;
        Error_Block ebObj;
        Error_Block *eb = &ebObj;

        Error_init(eb);

        #ifdef UTILS_MEM_DEBUG
        Vps_printf(" UTILS: MEM: Alloc'ing from FRAME BUF. (required size = %d B, free space = %d B)\n",
            size,
            Utils_memGetBufferHeapFreeSpace()
            );
        #endif

        /* allocate memory */
        addr = Memory_alloc(gUtils_heapMemHandle[UTILS_MEM_VID_FRAME_BUF_HEAP], size, align, eb);

        if(addr==NULL)
        {
            /* if memory allocation in Frame buf heap failed, then try in tiler buf heap
                But tiler needs to be disabled for this to work
            */
            if (SystemTiler_isAllocatorDisabled())
            {
                #ifdef UTILS_MEM_DEBUG
       SystemCommon_TilerGetFreeSize tilerFreeSize;
       SystemTiler_getFreeSize(&tilerFreeSize);
                Vps_printf(" UTILS: MEM: Alloc'ing from TILER BUF. (required size = %d B, free space = %d B)\n",
                    size,
                    tilerFreeSize.freeSizeRaw
                    );
                #endif

                Error_init(eb);
                addr = SystemTiler_allocRaw(size, align);
            }
            else
            {
                #ifdef UTILS_MEM_DEBUG
                Vps_printf(" UTILS: MEM: TILER is ENABLED, will try BITS BUF (required size = %d B)\n", size);
                #endif
            }

            if(addr==NULL)
            {
                #ifdef UTILS_MEM_DEBUG
                Vps_printf(" UTILS: MEM: Alloc'ing from BITS BUF. (required size = %d B, free space = %d B)\n",
                    size,
                    Utils_memGetBitBufferHeapFreeSpace()
                    );
                #endif

                Error_init(eb);
                addr = Memory_alloc(gUtils_heapMemHandle[UTILS_MEM_VID_BITS_BUF_HEAP], size, align, eb);
            }

        }

        #ifdef UTILS_MEM_DEBUG
        Vps_printf(" UTILS: MEM: FRAME ALLOC, addr = 0x%08x, size = %d bytes \n",
                    addr, size
                   );
        #endif

        if (!Error_check(eb)
            &&
            (addr != NULL)
            &&
            gUtils_memClearBuf[UTILS_MEM_VID_FRAME_BUF_HEAP])
        {
            memset(addr, 0x80, size);
        }

        return addr;
    }

    Ptr Utils_memAlloc_cached(UInt32 size, UInt32 align)
    {
        Ptr addr;
        Error_Block ebObj;
        Error_Block *eb = &ebObj;

        Error_init(eb);

        #ifdef UTILS_MEM_DEBUG
        Vps_printf(" UTILS: MEM: Alloc'ing from FRAME BUF. (required size = %d B, free space = %d B)\n",
            size,
            Utils_memGetBufferHeapFreeSpace()
            );
        #endif

        /* allocate memory */
        addr = Memory_alloc(gUtils_heapMemHandle[UTILS_MEM_VID_BITS_BUF_HEAP], size, align, eb);

        #ifdef UTILS_MEM_DEBUG
        Vps_printf(" UTILS: MEM: FRAME ALLOC, addr = 0x%08x, size = %d bytes \n",
                    addr, size
                   );
        #endif

        if (!Error_check(eb)
            &&
            (addr != NULL)
            &&
            gUtils_memClearBuf[UTILS_MEM_VID_BITS_BUF_HEAP])
        {
            memset(addr, 0x80, size);
        }

        return addr;
    }

    A issue about algorithm on dsp in the McFW mechanism(like VaLink),after the algorithm is normally called only once.

    the system (or only dsp) is seem dead after continuely printing infomation as following and streams on Web GUI  are stopped.

    Unable to determine our source address: This computer has an invalid IP address: 0.0.0.0

    Unable to determine our source address: This computer has an invalid IP address: 0.0.0.0 ...

    would you give me some advice about this?

    thanks again.

  • The difference between the two functions is the heap used to allocate memory

    gUtils_heapMemHandle[UTILS_MEM_VID_BITS_BUF_HEAP] is placed in cacheable memory region

    gUtils_heapMemHandle[UTILS_MEM_VID_FRAME_BUF_HEAP] is placed in non-cacheable memory region

    hence Utils_memAllocCached allocates from UTILS_MEM_VID_BITS_BUF_HEAP.

    I don't have idea about the IPNC RDK analytics issue you mentioned sorry.