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.

How to relocate the NDK buffer to DDR while keep the local variable in IRAM in CCS3.2

I'm using old version CCS3.2.

To speed up the ethernet, I created a larger heap in DDR, and used

bios.MEM.MALLOGSEG = prog.get("DDR");

bios.MEM.BIOSOBJSEG = prog.get("DDR");

to make NDK use the buffer in DDR heap.

However, I found the local variables within each function are also assigned to DDR which is not my desire.

Is there any way to relocate the NDK buffer to DDR, and keep the local variables still in IRAM?

I tried 

bios.MEM.STACKSEG = prog.get("IRAM");

bios.TSK.STACKSEG = prog.get("IRAM");

Doesn't work.

Thanks

  • Which version of the NDK are you working with?

    FENG WU said:

    bios.MEM.MALLOGSEG = prog.get("DDR");

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

    Which NDK buffers are you trying to relocate?  Are you talking about the PBM buffers?

    These settings only configure the memory segment to be used for dynamic memory allocations for malloc() and module XXX_create() function calls (e.g. TSK_create()), respectively.

    FENG WU said:
    Is there any way to relocate the NDK buffer to DDR, and keep the local variables still in IRAM?

    What memory segment do you have configured for .data and .bss?  e.g. what are the values of:

    bios.MEM.DATASEG

    bios.MEM.BSSSEG

    Steve

  • Hi, Steve

    Sorry to reply so late, my deep apology.

    Which version of the NDK are you working with?

    The NDK version I used is an old one :1.94.01.

    Which NDK buffers are you trying to relocate?  

    The NDK buffer I'm trying to relocate is the TCP transmit buffer and receive buffer whose default size is 8192KB( if I'm right).  The buffer sizes are defined as follows in the stack_test() function.

    // TCP Transmit buffer size
    rc = 128000; // default 8192
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
    CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );

    // TCP Receive buffer size (copy mode)
    rc = 128000; // default 8192
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
    CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );

    Originally, the buffers with default size are located in the IRAM. With the increased size to seek higher speed, it's hard to hold them in the IRAM for my application.

    What memory segment do you have configured for .data and .bss?

    Both .data and .bss are assigned to IRAM.

    Looking forward to your reply.

  • Hi Feng Wu,


    From what you wrote above, I think your configuration for the TCP send and receive buffers is correct.  These buffers are allocated using the NDK's mmBulkAlloc() function.  mmBulkAlloc() in turn calls BIOS' MEM_alloc() function to do the actual allocation of the memory.  And MEM_alloc() will allocate memory out of the default heap.

    FENG WU said:
    However, I found the local variables within each function are also assigned to DDR which is not my desire.

    How are you creating this TSK?  Are you creating at run time via a call to TSK_create()?  Or, are you creating statically, within the *.tcf file?

    FENG WU said:
    bios.TSK.STACKSEG = prog.get("IRAM");

    This setting only applies to TSKs created dynamically at runtime, using the TSK_create function.


    To change the stack location of a statically created TSK (i.e. a TSK created in the *.tcf configuration file), you need to set create the TSK instance in your *.tcf file, and then set the stack segment. For example:

    var myTsk = bios.TSK.create("myTsk");

    myTsk.stackMemSeg = prog.get("myMEM");

    Please refer to the DSP/BIOS API guide (spru403s.pdf, section "2.32 TSK Module") for further details.

    Steve

  • Hi Steve

    Thank you so much for your reply.

    Most functions are working ok now except the function called by DaemonNew() in NetworkOpen().

    Are the stacks in the functions called within NDK assigned in a same way as the TCP send and receive buffers?

    If so, is there any way to separate them? I mean TCP buffer in DDR while stacks in IRAM.

    Feng

  • Feng,


    Yes. The functions that run as daemons are running as BIOS TSKs.  So, what I wrote in my previous post, regarding how to place TSK stacks in memory for dynamically created TSKs applies here.

    Steve

  • Hi, Steve

    The local variables in the function called by daemons are still assigned to DDR even I used

    bios.TSK.STACKSEG = prog.get("IRAM");

    I think the reason is that I used the following configuration

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

     

    However, if I remove it 

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

     

    The NDK will not work properly. The error messages popped out all the time:

    00000.503 SBNew: Buffer OOM

    00010.504 SBNew: Buffer OOM

    00020.505 SBNew: Buffer OOM

    00030.506 SBNew: Buffer OOM

    00040.507 SBNew: Buffer OOM

    ...

    Any suggestion?

    Feng

  • Hi, Steve

    Sorry, an error in the last post.

    Not removing 

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

    I changed it to

    bios.MEM.BIOSOBJSEG = prog.get("IRAM");

    Feng

  • Feng,

    Yes, this makes sense, you are just running out of heap.

    Those errors you show above are happening during your socket() create call.  The socket() API is failing to allocate the buffers it needs.

    Since you removed:

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

    Now BIOS' dynamically created instances are being created from the same heap as your socket buffers have been coming from.

    In other words, when you keep the above configuration, there is enough heap for your socket buffers to be allocated.  But when you remove that configuration, then the BIOS objects are also using the same heap, and probably by the time it comes to allocate your socket buffers, there is not enough heap left.

    Steve

  • Hi, Steve

    In my application, I have a heap in IRAM, now I create another heap in DDR. What I want is just put the NDK Tx/Rx buffer to the heap created in DDR.

    The final solution I found is to call funcation _mmBulkAllocSeg(1) during system initialization while all configurations are kept untouched.

    That means 

    bios.MEM.MALLOGSEG = prog.get("IRAM");

    bios.MEM.BIOSOBJSEG = prog.get("IRAM");

    &

    _mmBulkAllocSeg(1) ; // called in system init

     

    I tracked the program, and found that the NDK TX/RX buffer is allocated using mmBulkAlloc() function. During this function, BulkSegId identifies which heap is used for the allocation. _mmBulkAllocSeg(1)  sets BulkSegId to 1 which implies the second heap.

    Because I have only two heaps created, my understanding is the heap in IRAM is 0, and the heap in DDR is 1.

    And during my debugging, I found that once I set

    bios.MEM.MALLOGSEG = prog.get("DDR");

    bios.MEM.BIOSOBJSEG = prog.get("DDR");

    The configuration 

    bios.TSK.STACKSEG = prog.get("IRAM");

    does not apply for the dynamically created task , e.g. the callback function created in DaemonNew(). The local variables in that callback function are still from DDR heap.

    I don't know why.

    Thank you so much for answering my questions with great patience.

    Feng