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.

SYSBIOS 6.33.6.50 rewrite the following cfg code with c code

Other Parts Discussed in Thread: SYSBIOS

hello everyone,

I want to rewrite the following cfg code  with c code:

var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
var heapMemParams = new HeapMem.Params();
heapMemParams.size = 0x3200000;
heapMemParams.sectionName = "systemHeap";
heapMem0Params.instance.name = "heapMem01";
Program.global.heap0 = HeapMem.create(heapMemParams);

/* This is the default memory heap. */
Memory.defaultHeapInstance = Program.global.heap0;

here is my c code:

HeapMem_Params g_HeapParams[8] = {0};
HeapMem_Handle g_HeapHandle[8] = {0};

int g_CoreMemory[8]  = {0x80000000, 0x83200000, 0x86400000, 0x89600000, 0x8C800000, 0x8FA00000, 0x92C00000, 0x95E00000 };

Error_Block eb;

Error_init(&eb);
HeapMem_Params_init(&g_HeapParams[DNUM]);
g_HeapParams[DNUM].size = 50*1024*1024;
g_HeapParams[DNUM].buf = (Ptr)g_CoreMemory[DNUM];
g_HeapParams[DNUM].instance->name = "heapMem01";
g_HeapHandle[DNUM] = HeapMem_create(&g_HeapParams[DNUM], &eb);

 I can't find the sectionName field in the  HeapMem_Params struct, but the cfg file has this filed.

And I also want to set the g_HeapHandle[DNUM]  as the default heap in current core, and I don't know how to rewrite  "Memory.defaultHeapInstance = Program.global.heap0;" with c code.

I just wan to dynamic create heap every core, and  I set each heap‘s start address, and set a heap as a default heap

if current core has multi heaps.

Best Regards,

Si

  • Hi Si,

    I don't believe there is a way to set the default heap at run time.  I only see that it can be done at config time.

    The following topic may be useful to you:

    http://rtsc.eclipse.org/docs-tip/Using_xdc.runtime_Memory#Runtime_heap_creation


    Steve

  • Hi Steve,

    I want to run the same project on every core in c6678. If there is no way to set the default heap at run time, then is there any way to implement my requirements?

    Best Regards,

    Si

  • Si,

    Memory_alloc() takes a heap handle as a parameter.  Since your g_HeapHandle[] array contains the list of Heap handles, I'm wondering if you can use that in your allocation calls.  Something like:

        Memory_alloc(g_HeapHandle[DNUM], ...);

    Since DNUM will give you the number of the current core, I think it should index to the correct heap for the core you are on at run time.

    Steve

  • Steve,

    I think you don't get my idea, my project use other's lib, the lib has used malloc, and it uses the default heap, so I can't use the  heap handle parameter. I need to set one heap as a default heap.

    I just want to know a way how to set one of some heaps as a default heap. 

    Because I want to run NDK on every core at the same time. NDK will use default heap on every core.

    Si

  • Steve,

    I have a idea, I can modify the Memory_alloc and Memory_free function in Memory.c in xdc/rumtime, 

    here is the define.

    Ptr Memory_alloc(IHeap_Handle heap, SizeT size, SizeT align, Error_Block *eb)
    {
    Ptr block;
    Bool prior = Error_check(eb);

    /* if align == 0, use default alignment */
    if (align == 0) {
    align = Memory_getMaxDefaultTypeAlign();
    }

    /* allocate using a non-NULL appropriate heap */
    block = Memory_HeapProxy_alloc(heap ? heap : Memory_defaultHeapInstance ,
    size, align, eb);

    /* if the allocator returned NULL and either
    * the error was already set or
    * it didn't set the error
    */
    if (block == NULL && (prior || !Error_check(eb))) {
    Error_raise(eb, Error_E_memory, (IArg)heap, (IArg)size);
    }

    return (block);
    }

     

    when the heap is NULL, it uses the Memory_defaultHeapInstance, here I can set the Memory_defaultHeapInstance as the heap g_HeapHandle[DNUM]  which I have created  in main. So all malloc from   app layer will use g_HeapHandle[DNUM] .

    Then I rebuild the xdc pacakges to  generate boot.ae66e and ti.targets.rts6000.ae66e, but after I rebuild my project ,

    and load, find that it can't run to main  symbol,it always runs whiout stopping before main.

    I don't know what 's wrong, can't I  just replace the Memory_defaultHeapInstance  with g_HeapHandle[DNUM]?

    Hope this problem can be resolved, thanks.

     

    Best Regards,

    Si

  • Steve,

    below is the stack status when I stop running.

  • Steve,

    I have found that the xdc_runtime_Startup_startMods__I is in Startup.c , and xdc_runtime_Startup_startMods__I

    is called by _auto_init or _auto_init_elf function in autoinit.c, maybe my config.bld file is  uncorrect which leads to use the wrong function.

    here is my  config.bld, I want to generate c66 elf big endian lib:

    /* specify the compiler installation directory for the targets we need */
    var C66_big_endian = xdc.useModule('ti.targets.elf.C66_big_endian');
    C66_big_endian.rootDir = "C:/ti/C6000_Code_Generation_Tools_7_4_6";

    /* specify the target(s) to use when building source files */
    var Build = xdc.module("xdc.bld.BuildEnvironment");
    Build.targets = [C66_big_endian]; /* only build using C64P target */

    Si

  • Si,

    We have just had a holiday weekend in the US, so no one was responding to the forums.

    While you do have the code to modify XDC tools, that code is complex and I would only recommend this as a last resort.

    Let me speak with a colleague of mine about setting/changing the default heap at run time and get back to you.

    Steve

  • Steve,

    Thanks for your response, if there is another way to set the default heap at run time, I will not modify the xdc tools, after all, it's not a good idea to modify the xdctool. Waiting for the reply from your colleague.

     

    Best Regards,

    Si

  • Si,

    Which version of the NDK are you using?

    I spoke to my colleague and there is no API to set the default heap at run time.  The reason is that XDC needs that to be set very early in the application run (before any user code is run).

    si cheng said:
    I think you don't get my idea, my project use other's lib, the lib has used malloc, and it uses the default heap, so I can't use the  heap handle parameter. I need to set one heap as a default heap.

    si cheng said:
    Because I want to run NDK on every core at the same time. NDK will use default heap on every core.

    Is the default heap problem you are experiencing entirely due to the NDK's use of the default heap for dynamic memory allocation calls?

    It may be easier for you to modify the NDK and then rebuild the "other's libs" (which sound like they use NDK).

    NDK used to have an API to change the heap it allocates from, but it was not added for the SYS/BIOS implementation of the NDK.

    If modifying and rebuilding the NDK is possible for your scenario, then you can find the code in the file:

    ti/ndk/os/mem.c

    The two functions are:

    1. mmBulkAlloc()
      1. calls Memory_alloc(NULL, Size, 4, &eb);
      2. (default heap allocation)
    2. _mmBulkAllocSeg()
      1. currently does nothing, but you can modify it to set the heap to the one you want

    You could change the Memory_alloc() call (that's in mmBulkAlloc()) to use your heap handle array (assuming it's globally accessible):

    Memory_alloc(g_HeapHandle[DNUM], ...);

    Or you could modify _mmBulkAllocSeg()to set the appropriate heap ID and then reference that setting in the Memory_alloc() call in mmBulkAlloc().

    ---

    If there is some other code that's referencing malloc() and causing you problems (besides NDK), another option is to redefine malloc()/free() locally (i.e. in your main.c file).

    You could redefine them by copying their current implementations out of BIOS and pasting into your main.c file.  You could then modify them appropriately to allocate from the heap that you want.  This is a bit of a hack, though, but it should work.

    Steve

  • Steve,

    Thanks for you reply,I use the ndk_2_23_00_00, change the Memory_alloc() call (that's in mmBulkAlloc()) to use my heap handle array is a good idea, and I will have a try, another way you said

    "modify _mmBulkAllocSeg()to set the appropriate heap ID and then reference that setting in theMemory_alloc() call in mmBulkAlloc()."

    How can I get a heap id, and when I call the _mmBulkAllocSeg() to modify the heap, after my heap create?

    I have  read the ndk _mmBulkAllocSeg() code, it defines as:

    void _mmBulkAllocSeg( uint segId )
    {
    /*
    * For BIOS 6, the default Heap will be used for allocations. If the user
    * wishes to change the Heap for mmBulkAlloc(), this should be done using
    * BIOS or XDC APIs as appropriate.
    uint CritState;

    CritState = OEMSysCritOn();

    if( !mmBulkCalls )
    BulkSegId = segId;

    OEMSysCritOff( CritState );
    */
    }

    I can't find the define of BulkSegId, where it wil be used to change the heap that mmBulkAlloc used.

    Si

     

  • Steve,

    I modify the Memory_alloc(NULL, Size, 4, &eb) in mmBulkAlloc(), I change NULL as g_HeapHandle[DNUM], and also 

    change the Memory_free(NULL, (Ptr)ptr, *(ptr+1)); in mmBulkFree, and rebuild all the ndk successfully, when I use

    the client_evmc6678l demo, and modify the memory section like below:

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');

    var heapMemParams = new HeapMem.Params();
    heapMemParams.size = 0x4000;
    heapMemParams.sectionName = "systemHeap";
    Program.global.heap0 = HeapMem.create(heapMemParams);


    /* This is the default memory heap. */
    Memory.defaultHeapInstance = Program.global.heap0;
    Program.sectMap["sharedL2"] = "L2SRAM";
    Program.sectMap["systemHeap"] = "L2SRAM";
    Program.sectMap[".sysmem"] = "L2SRAM";
    Program.sectMap[".args"] = "L2SRAM";
    Program.sectMap[".cio"] = "L2SRAM";
    Program.sectMap[".far"] = "L2SRAM";
    Program.sectMap[".rodata"] = "L2SRAM";
    Program.sectMap[".neardata"]= "L2SRAM";
    Program.sectMap[".cppi"] = "L2SRAM";
    Program.sectMap[".init_array"] = "L2SRAM";
    Program.sectMap[".qmss"] = "L2SRAM";
    Program.sectMap[".cinit"] = "L2SRAM";
    Program.sectMap[".bss"] = "L2SRAM";
    Program.sectMap[".const"] = "MSMCSRAM";
    Program.sectMap[".text"] = "MSMCSRAM";
    Program.sectMap[".code"] = "MSMCSRAM";
    Program.sectMap[".switch"] = "L2SRAM";
    Program.sectMap[".data"] = "L2SRAM";
    Program.sectMap[".fardata"] = "L2SRAM";
    Program.sectMap[".args"] = "L2SRAM";
    Program.sectMap[".cio"] = "L2SRAM";
    Program.sectMap[".vecs"] = "L2SRAM";
    Program.sectMap["platform_lib"] = "MSMCSRAM";
    Program.sectMap[".DbgSection"] = "MSMCSRAM";
    Program.sectMap[".far:taskStackSection"] = "L2SRAM";
    Program.sectMap[".stack"] = "L2SRAM";
    Program.sectMap[".nimu_eth_ll2"] = "L2SRAM";
    Program.sectMap[".resmgr_memregion"] = {loadSegment: "L2SRAM", loadAlign:128}; /* QMSS descriptors region */
    Program.sectMap[".resmgr_handles"] = {loadSegment: "L2SRAM", loadAlign:16}; /* CPPI/QMSS/PA Handles */
    Program.sectMap[".resmgr_pa"] = {loadSegment: "L2SRAM", loadAlign:8}; /* PA Memory */
    Program.sectMap[".far:IMAGEDATA"] = {loadSegment: "L2SRAM", loadAlign: 8};
    Program.sectMap[".far:NDK_OBJMEM"] = {loadSegment: "L2SRAM", loadAlign: 8};
    Program.sectMap[".far:NDK_PACKETMEM"] = {loadSegment: "L2SRAM", loadAlign: 128};

     

    when I run the demo, when it call NC_NetStart(), it abort as heap problem,if I larger the heap and place in DDR it

    will work well, it seams that ndk does not use my heap to alloc memory.  If NDK use my heap, allocing 0x4000 bytes  for the systemheap is  enough which is use for QMSS,CPPI initialization.

    Si

  • Si,

    I'm trying to understand your last post.  Can you please provide some more information?

    si cheng said:
    when I run the demo, when it call NC_NetStart(), it abort as heap problem

    What was the error you saw?  Please copy/paste it to this thread.

    si cheng said:
    it seams that ndk does not use my heap to alloc memory.

    The NDK creates a Task dynamically in NC_NetStart().  This is done via the Task_create() API.  The following Task module's configuration setting governs the heap to use for dynamically created Tasks.  Can you check the value of this in your configuration?

    Task.defaultStackHeap

    ...

    It sounds like you were able to successfully change the NDK's Memory_alloc() call to use your g_HeapHandle[] array.

    It did not work when you used the above configuration settings, which place the heap into L2SRAM:

    si cheng said:

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');

    var heapMemParams = new HeapMem.Params();
    heapMemParams.size = 0x4000;
    heapMemParams.sectionName = "systemHeap";
    Program.global.heap0 = HeapMem.create(heapMemParams);


    /* This is the default memory heap. */
    Memory.defaultHeapInstance = Program.global.heap0;

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

    So the above settings did not work, correct?  I want to verify that the heap size of 0x4000 didn't work for you.

    si cheng said:

    if I larger the heap and place in DDR it

    will work well

    Can you please provide the details on this working scenario?  E.g. what was the heap size that you had to increase it to, etc.

    What does the ROV tool show you for your heap during these scenarios?

    Steve

  • Steve,

    I am sorry for replying later, I have made a mistake, I have known why when  calling NC_NetStart(), it aborts, because my task is create in cfg file, and don't assign the default stack heap, now I create the task in main and assign the stak heap as  g_HeapHandle[DNUM], and plcae the systemHeap in L2 ,size is 0x1000, it works well. But another question is that the ndk buffer array is in section .far:NDK_PACKETMEM, as it's a little large, I want to place it to MSM RAM or DDR, for multi cores run ndk at the same tiime scenario , the ndk buffer arrays will be coverd by each other, how can I make the array in MSM RAM or DDR and not be coverd by others at the same time.

    Best Regards,

    Si

  • Si,

    The NDK PBM buffer placement is configurable.  Please refer to this wiki page for details.

    Steve

  • Steve,

    I read the wiki page, from the wiki, I don't get how to place NDK PBM buffer on MSM RAM or DDR avoiding being covered by other cores, because every core has a NDK PBM buffer, and all of them on MSM RAM or DDR.

    Si

  • Hi Si Cheng,

    Have you looked at the implementation of the image processing demo that is provided in the MCSDK package. The demo uses NDK on the master core and has the ability to distribute the image processing task only 8 cores. In order to implement this demo there is a custom C6678 XDC platfrom definition created that segregates the MSMC region between the master and the slave core. You can do the same for the NDK PBM buffers.

    Custom platfrom definition  for the C6678 can be found under MCSDK_INSTALL_DIR\demos\image_processing\ipc\evmc6678l\platform

    Segregation of the PACKETMEM buffers on the different cores will be obtained by using the following on mmaster core

    Program.sectMap[".far:NDK_PACKETMEM"]= {loadSegment: "MSMCSRAM_MASTER", loadAlign: 128};

    And configuring the PBM buffers as follows on the slave cores.

    Program.sectMap[".far:NDK_PACKETMEM"]= {loadSegment: "MSMCSRAM_SLAVE#", loadAlign: 128};

    Hope this helps.

    Regards,

    Rahul

  • Rahul,

    your advice can't avoid  NDK PBM to be coverd, because all cores use the same project, and PBM is on .far:NDK_PACKETMEM".

     

    Regards,

    Si