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.

problem with creating more msg with the same heapId

Platform:EVM 6472
XDCtools version: 3.20.04.68
IPC: 1.21.02.23
BIOS: 6.30.03.46

Who can tell me if two or more messages can be created with the same heapId?  When I created msg and msg1 with

heaId=0, the program broken with an error of "out of memory". What is the problem?  I don't know how to configure Memory.defaultHeapSize and  Program.heap. Must Memory.defaultHeapSize and Program.heap be the same?


#define HEAP_NAME   "myHeapBuf"
#define HEAPID      0

Void tsk0_func(UArg arg0, UArg arg1)
{
    MessageQ_Msg     msg;
    MessageQ_Msg     msg1;    
    MessageQ_Handle  messageQ;
    MessageQ_QueueId remoteQueueId;   
    Int              status;
    UInt16           msgId = 0;
    HeapBufMP_Handle              heapHandle;
    HeapBufMP_Params              heapBufParams;

    HeapBufMP_Params_init(&heapBufParams);
    heapBufParams.regionId       = 0;
    heapBufParams.name           = HEAP_NAME;
    heapBufParams.numBlocks      = 1;
    heapBufParams.blockSize      = sizeof(MessageQ_MsgHeader);
  
    heapHandle = HeapBufMP_create(&heapBufParams);
    MessageQ_registerHeap((IHeap_Handle)heapHandle, HEAPID);
   
    /* Generate queue names based on own proc ID and total number of procs */
    System_sprintf(localQueueName, "CORE%d", MultiProc_self());
    System_sprintf(nextQueueName, "CORE%d", (MultiProc_self() + 1) % MultiProc_getNumProcessors()));
    
    messageQ = MessageQ_create(localQueueName, NULL);   
     
    /* Open the remote message queue. Spin until it is ready. */
    do {
        status = MessageQ_open(nextQueueName, &remoteQueueId);
    } while (status < 0);
   
    /* Allocate a message to be ping-ponged around the processors */
    msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader));
    if (msg == NULL) {
       System_abort("MessageQ_alloc failed\n" );
    }
    msg1 = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader));
    if (msg1 == NULL) {
       System_abort("MessageQ_alloc failed\n" );
    }
}

segment of message_single.cfg:
Memory.defaultHeapSize = 0x8000;
Program.heap = 0x8000;

/* Synchronize all processors (this will be done in Ipc_start) */
Ipc.procSync = Ipc.ProcSync_ALL;

/* Shared Memory base address and length */
var SHAREDMEM           = 0x200000;
var SHAREDMEMSIZE       = 0xC0000;

  • li lu said:
        HeapBufMP_Params_init(&heapBufParams);
        heapBufParams.regionId       = 0;
        heapBufParams.name           = HEAP_NAME;
        heapBufParams.numBlocks      = 1;
        heapBufParams.blockSize      = sizeof(MessageQ_MsgHeader);

    You are probably running out of memory because 'numBlocks' is '1' and you are trying to allocate more than 1 message from the HeapBuf.(which is registered with MessageQ using HEAPID).

    Try changing '1' to a bigger value to accommodate the extra messages.

    Regards,

    Shreyas

  • Thanks, Shreyas.   I have another question to ask for help.  Must we define the heapid  as the default value 0 ?   I  have tried to modify heapid with  1 or 2,  but the application was broken with invalid_heapId error .  Can you explain how to configure the value of  heapid  ? Can  two or more messages  use the same heapid?

  • li lu said:
    Must we define the heapid  as the default value 0 ?   I  have tried to modify heapid with  1 or 2,  but the application was broken with invalid_heapId error .  Can you explain how to configure the value of  heapid  ?

    The range of heapId's is governed by the value of the "MessageQ.numHeaps" module configuration.  The value of heapId may be inclusively between 0 and numHeaps - 1.

    You can set the value of numHeaps as follows:

    var MessageQ = xdc.useModule('ti.sdo.ipc.MessageQ');

    MessageQ.numHeaps = 8; //new value

    In your version of IPC, 'numHeaps' is by default '1' which explains why you can't use any heapId besides '0'.  However, in later version of IPC, the default value has been increased to '8' which accommodates heapId's betwen '0' and '7'.  

    li lu said:
    Can  two or more messages  use the same heapid?

    Yes, definitely.  The number of message allocated from a heap is limited by the size of the heap (and perhaps alignment as well).  Under-the-scenes, MessageQ_alloc performs a Memory_alloc using the heap that was registered with MessageQ using HEAPID. 

    However, two heaps cannot use the same heapId. I.e. trying to register two HeapBufMP's with MessageQ using the same HEAPID should produce some sort of failure.

    Regards,

    Shreyas