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.

Heap size configuration

Other Parts Discussed in Thread: SYSBIOS

Hello,

I tried to configure my heap size using a *.cfg file using the following adapted commands below taken from a projekt template example.

I am using bios 6.31.4.27:

/*
** Create a Heap
*/
var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
var heapMemParams = new HeapMem.Params();
// heapMemParams.size = 0xF4240;
heapMemParams.size = 0x300000;
heapMemParams.sectionName = "systemHeap";
Program.global.heap0 = HeapMem.create(heapMemParams);
Memory.defaultHeapInstance = Program.global.heap0;

Program.heap = 0x300000;
Program.stack = 0x2000;



/********************************************************************************************************************
*     Define our Memory Map. We made up the  memory  names LL2RAM, DDR2 and SL2RAM. They do have special meaning.        *
*                                                                                                                    *
*    DDR2 - Anyhting destined for DDR2 always goes into the external RAM on the paltform.                            *
*    LL2RAM - This is data that should be placed into the Local L2 of the core.                                        *
*    SL2RAM - This is data that should go into the shared L2 (if it exists) or could be placed into LL2 if it doesnt.*
*                                                                                                                    *
*    These section names are mapped to specific addresses for a paltform using our custom memroy maps which are         *
*    defined using the Platform Wizard. Examples are custom.hpdpsua.evm6472, etc.,.                                    *
********************************************************************************************************************/
   
Program.sectMap[".vecs"]         = {loadSegment: "LL2RAM", loadAlign:8};    /* CSL per core data structures          */
Program.sectMap[".switch"]         = {loadSegment: "LL2RAM", loadAlign:8};    /* CSL per core data structures          */
// Program.sectMap[".far:EMAC_DRV"]= {loadSegment: "LL2RAM", loadAlign:8};    /* Ethernet core specific data structures*/
// Program.sectMap[".far:NDK_OBJMEM"]= {loadSegment: "LL2RAM", loadAlign: 8}; /* NDK structures                      */
Program.sectMap[".cio"]          = {loadSegment: "LL2RAM", loadAlign:8};    /* per core data structures              */
Program.sectMap[".args"]         = {loadSegment: "LL2RAM", loadAlign:8};    /* per core data structures              */

Program.sectMap["systemHeap"]     = "DDR2";                                /* XDC Heap .. eg mmxxxAlloc() */
Program.sectMap[".far"]         = "DDR2";
Program.sectMap[".cinit"]         = "DDR2";
Program.sectMap[".bss"]            = "DDR2";
Program.sectMap[".const"]        = "DDR2";
Program.sectMap[".text"]        = "DDR2";
Program.sectMap[".code"]        = "DDR2";
Program.sectMap[".data"]        = "DDR2";
Program.sectMap[".sysmem"]        = "DDR2";                                /* malloc heap */
// Program.sectMap[".gBuffer"]        = {loadSegment: "DDR2", loadAlign:8};  /* Upload buffer used by the Web Server*/
// Program.sectMap[".far:WEBDATA"]    = {loadSegment: "DDR2", loadAlign: 8}; /* Web Pages and web server structures */

Program.sectMap[".taskStackSection"]= "SL2RAM";
//Program.sectMap[".stack"]            = "SL2RAM";
Program.sectMap[".stack"]            = "DDR2";
//Program.sectMap["emacComm"]         = {loadSegment: "SL2RAM", loadAlign:128};     /* EMAC Buffer Pool */
// Program.sectMap[".far:NDK_PACKETMEM"]= {loadSegment: "SL2RAM", loadAlign: 128};    /* NDK Buffer Pool */

Using this configuration, I get the following output in the  *_p64P_x.xdl file. Heap is set to zero and all heap settings seem to be ignored. How can this happen?

 

--args 0x200
-heap  0x0
-stack 0x2000

MEMORY
{
    LL2RAM (RWX) : org = 0x800000, len = 0x98000
    SL2RAM (RWX) : org = 0x200000, len = 0xc0000
    DDR2 (RWX) : org = 0xe0000000, len = 0x10000000
}

 

My main goal is just to set the program stack to size x and the heap, that will be used by malloc, to size x.

 

Best regards, Carsten

 

  • I'm very sorry for the frustration you've experienced.

    We made a change to how the malloc() heap is configured and managed in BIOS 6.31 that simplifies things for the user but we may have fallen short on communicating this change effectively.

    To set the malloc() heap size to 0x300000, add the following to your config script:

     BIOS.heapSize = 0x300000;

    To place the malloc() heap in a section named "systemHeap", add the following to you config script:

     BIOS.heapSection = "systemHeap";

    These settings will result in BIOS configuring a HeapMem instance with the settings above and installing that HeapMem instance as the Memory.defaultHeapInstance.

    Subsequent runtime calls to malloc() or, preferrably Memory_alloc() will obtain memory from the internally created HeapMem instance.

    Alan

  •  

    Alan,

    I have a problem when I followed the above steps.

     

    I did the heap size specifications as below:

     

    BIOS.heapSize = 0x300000;

    BIOS.heapSection = "systemHeap";

    Program.sectMap["systemHeap"] = "DDR2";

     

    When I looked at _p64P_x.xdl, I do see as below for heap

    -heap 0x0

     

    I don't understand, why it is showing 0x0 size for heap. I am using SysBios version: 6_31_04_27

    Am I missing any steps above?

     

    Thanks,

    Rahul

     

     


  • Rahul,

    SYS/BIOS provides its own malloc() and free() APIs that override the codegen tools RTS implementations. The SYS/BIOS implementations DO NOT USE the memory buffer whose size is defined by "-heap". Instead they internally call Memory_alloc() and Memory_free() which SYS/BIOS internally wires up to use a HeapMem instance created using the BIOS.heapSize setting.

    Consequently, in order to avoid unused memory (ie the memory section defined by -heap and used by the default malloc() and free() implementations), SYS/BIOS sets -heap to zero.

    That said, are you having a runtime problem with malloc() after configuring BIOS.heapSize to be 0x300000? If so, this would either mean your application needs more malloc()-able memory than you thought, or that the default codegen implementations of malloc() and free() are being linked in rather than the ones provided by SYS/BIOS.

    Are you building your application using CCS? Or do you have a custom build flow? Please describe.

    Alan

  • Alan,

    Thank you for your reply. I guess, I misunderstood "BIOS.heapSize" setting. I was expecting "-heap" value to change when I modify "BIOS.heapSize" setting. Also, I am not using Memory_alloc() or Memory_free() functions. I guess I am wrong from what you described.

    Here is my situation:

    I am integrating a library (I don't have access to source code). There is a C++ class "X1class". I have declared a variable like "X1class var1". So, the problem is DSP hangs at this statement. First thing, I started looking at is the memory requirements of that library. The standalone library's linker command file has a heap size like this:  "-heap XXXX". This standalone library doesn't use a SysBIOS. But, my application who links this libray uses SysBIOS 6.31 and CCSv4.

    So, I am trying to achieve "-heap XXXX" to satisfy library's memory requirements. What should I change in my application project settings or sysbios settings to achieve this heap memory?

    I tried below options:

    1. Modified "C/C++ Build -> Tool Settings -> C6000 Linker -> Heap size for C/C++ dynamic memory allocation(--heap_size, -heap) = XXXX " in my application project settings.

    2. Modified "Program.heap = XXXX" in my application sysBios settings.

    But, I still see "-heap 0x0" instead of  "-heap XXXX" in the generated file "----_p64P_x.xdl".

     

    Thanks,

    Rahul

     

     

     

     

  • A simple way to keep SYS/BIOS from setting --heap to zero is to add the following to your config script:

    xdc.useModule('xdc.runtime.HeapStd');

    However, I'm puzzled as to why the X1class constructor isn't using SYS/BIOS-provided malloc() API.

    It seems that somehow the RTS library-provided malloc() function is being linked in instead.

    Can you show me the generated linker command file as well as the final link command line?

     

  • Hello, I seem to have the same problem. I had a program that worked before, on BIOS 6.21.00.13.

    Now I'm trying to use BIOS 6.32.03.43, and when I run my program it says:

    ti.sysbios.heaps.HeapMem: line 296: out of memory: handle=0xe20fed28, size=76

     

    At first I had:

    var heapMemParams = new HeapMem.Params;

    heapMemParams.size = 8192;

    var heap0 = HeapMem.create(heapMemParams);

    Memory.defaultHeapInstance = heap0;

     

    After reading this I changed it to:

    BIOS.heapSize = 0x300000;

    BIOS.heapSection = "systemHeap";

    but the problem persists.

    Also, I get a warning during link, which says:

    warning: creating output section "systemHeap" without a SECTIONS specification.

     

    What can I do to make it work again?

  • Hello Arya,

    If u got the solution for your problem pleas share it as a reply to below link
    e2e.ti.com/.../535987

    As I'm facing the same issue and wanted a solution urgently...!!!