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.

TMS320C6746: Issue on DDR memory allocation using HeapBuf_alloc function

Part Number: TMS320C6746

Sys bios used   :6:33.4.39

Summary: We have noticed  issue in  allocating memory blocks in external DDR memory

HeapBuf_alloc function  is used to allocate memory in DDR for Bios Queue . We are allocating memory only when if it has free space. In some instant this function returns zero even though it has enough free size. Based on E2E  , we have changed HeapBuf_alloc function with Memory_alloc , But no improvements. Next step we tried to move this Buffer memory section from DDR to Processor IRAM , this memory section changes fix the issue. We don’t want to keep this it in IRAM, since IRAM doesn’t have enough memory . We have used similar memory allocation in another Queue handling , we didn’t find any issue with that. Only difference is this problem  Queue will be called by multiple thread in same time.,  Please provide your thoughts and your inputs are highly appreciated.

 

E2E Reference Link : https://e2e.ti.com/support/legacy_forums/embedded/tirtos/f/355/t/464797

 

  • Hi,

    What are you passing for the Error_Block in the Memory_alloc. Did you initialize it?

    When you get NULL back from Memory_alloc, how do you know there is actually memory in the heap?

    I don't think this is a multi-thread issue since it looks in IRAM and we have not had any issues with HeapBuf for years.

    Todd

  • Hi,

    Thanks for your response

    Error block variable is declared but not initialized, will it be an issue?

    Available free space is checked as below before allocating memory

  • Thanks for the code snippet. I see a few things

    1. Please use Memory_alloc instead of directly calling HeapBuf_alloc.

    2. Please initialize the Error_Block before using it. Here is how to do it.

    Error_init(&eb);

    3. Are you seeing DataPkt be NULL?

    4. Your code is not thread-safe. You could see there is memory present (via the HeapBuf_getStats), but then before you call the alloc, a higher priority thread runs and allocates all the memory from the heap. Then when the above task returns, there is no memory. Could this be happening? I'm assuming you are only allocating memory from tasks. You can put a Task_disable before you get the stats and Task_restore after you allocate the memory (and in the if no memory case).

    5. You are using TLMBuffer in the HeapBuf_getStats and Buffer in HeapBuf_alloc...are these two the same thing?

    Todd

  • Hi ,

    Thanks for your great findings and find my answer's  in Pink   

    Please find below changes as per your recommendation, please review and let us know if we missed anything, We will stat testing this changes soon.

    1.Please use Memory_alloc instead of directly calling HeapBuf_alloc.

    Veera: I tired Memory_alloc, but no help, any way i will try once again along with all changes as per your recommendation .

    2. Please initialize the Error_Block before using it. Here is how to do it.

    Veera: We will add this initialization, How this will impact

    3. Are you seeing DataPkt be NULL?

    Veera : Yes

    4. Your code is not thread-safe. You could see there is memory present (via the HeapBuf_getStats), but then before you call the alloc, a higher priority thread runs and allocates all the memory from the heap. Then when the above task returns, there is no memory. Could this be happening? I'm assuming you are only allocating memory from tasks. You can put a Task_disable before you get the stats and Task_restore after you allocate the memory (and in the if no memory case).

    Veera: I agree and it is very much valid point, We will try to accommodate in our code and test it .

    5. You are using TLMBuffer in the HeapBuf_getStats and Buffer in HeapBuf_alloc...are these two the same thing?

    Veera: this is a typo error, I edited original variable name because we were trying to not to disclose original variable name.. Sorry.

     

    Thanks 

    Veera

    Uint8 QueueDataPacket(UpdatePacket *CurrPacket){ UpdatePacket *DataPkt; Error_Block eb; Memory_Stats stats; Error_init(&eb); Uint32 key; key=Task_disable(); /* Get the un-Used buffer count */ HeapBuf_getStats(Buffer,&stats); /* If no buffer is free, return */ if (stats.totalFreeSize < TLM_BUF_BLOCKSIZE) { return FALSE; } /* Allocate buffer from the Event Buffer pool */ DataPkt=(UpdatePacket *)Memory_alloc(xdc_runtime_IHeap_Handle(Buffer),BUF_BLOCKSIZE,8,&eb);
    /* Copy the Current packet into the buffer */ memcpy(DataPkt,CurrPacket, sizeof(TlmUpdatePacket)); Task_restore (key); /* Queue the packet */ Queue_put(TQue,(Queue_Elem *)DataPkt);
    return TRUE;}

  • Make sure to add the Task_restore in the "if" case also (before you return FALSE).

  • yes i did that 

    Thanks and I really appreciate your response 

    Veera

  • Hi 

    We have tested as we discussed , but problem remains same.

    one more point i want to add earlier Discussion, 

     We have added code to skip the Queuing if it returns Null pointer,  But Memory_alloc function continuously returns null pointer once this condition occur.it can recover only when if we reset the processor.

    Thanks & Regards

    Veera

  • veerakumar Bose1 said:
    We have added code to skip the Queuing if it returns Null pointer,  But Memory_alloc function continuously returns null pointer once this condition occur.it can recover only when if we reset the processor.

    When do you free the allocated memory?

    Have you look at HeapBuf in CCS->Tools->ROV?

    Just to make sure...since you added the thread-safety, does the Memory_getStats say there is memory, but then the Memory_alloc return NULL?

    Todd

  • Hi,

    Please find my answers

    When do you free the allocated memory?

    Veera: Freeing of allocated memory is handled is another function. That function free the allocated space once buffered data is sent to other module.

    Have you look at HeapBuf in CCS->Tools->ROV?

    Veera: This condition is not occurring when we run the code in debug mode

    Just to make sure...since you added the thread-safety, does the Memory_getStats say there is memory, but then the Memory_alloc return NULL?

    Veera : yes

    Thanks

    Veera

  • Hi Veera,

    Can you get any debug information when the case is hit? Memory browser? I'd like to see the HeapBuf instance when this occurs.

    Todd

  • Hi

    As i said earlier this issue will not come when we run the code in debug mode

    Veera

  • But can you get any information? For example, dump the HeapBuf instance memory to something persistent that you can look at later. If not, I'm not sure if there is anything else I can do.

    Todd