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 and messageQ

Other Parts Discussed in Thread: SYSBIOS

Dear support,

I have already asked a few questions regarding message queues and heap. I thought I understood but I guess I don't. I cannot get the "heap" and "messageQ" to work together because I am not sure I understand how they interact. Can you please help.

The idea in the code is that I have communication between cores and communication between threads in the same core.

The inter_core is working (following example from the wizard using shared region), I am having problems for the inter_thread because I am not sure how to allocate a heap that will be assigned to the messages and use it there. There are examples (like memory or messageQ from the wizard) but too much is done in the cfg file that I cannot use as it.

Let's say that a would like 2 pools of set size messages that will be used for 2 different purposes. Here what I thought I should have been done (repeat the same procesure for all the pools I need to create)

1) allocate a big enough heap global to the program in the config file:

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

/* confgiure a heap */
var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
var heapMemParams = new HeapMem.Params();
/* size of 64k */
heapMemParams.size = 0x10000;
heapMemParams.sectionName = "systemHeap";
Program.global.heap0 = HeapMem.create(heapMemParams);

2) now that I have a big heap, I can allocate segments of this heap to use for any purpose (let say a segment of 10 buffers of 64 bytes)

heapSize = NUM_MTS_MSG * sizeof(MTS_MSG_TYPE);
heapAddress = Osal_platformMalloc(heapSize,0);
prms.blockSize = sizeof(MTS_MSG_TYPE);
prms.numBlocks = NUM_MTS_MSG;
prms.buf = heapAddress;
prms.bufSize = heapSize;

gMtsHeapHandle = HeapBuf_create(&prms, &eb);
gMtsHeapAddress = heapAddress;

3) All seems to be ok up to this point as far as I can see using ROV.So since I have a section, I can assign it to the message Q using any id I want as long as it is not used, then I will be able to use MessageQ_alloc using the same heapID.

MessageQ_registerHeap (gMtsHeapAddress,MTS_HEAP_ID_MSG_REGISTRATION); (return 0)

ROV does not show anything in the MessageQ module, I am not sure it works

4) Now I should be able to use this pool to allocate and free. However, I will need to cast to the real messages I want

msg = (MTS_MSG_TYPE*) MessageQ_alloc(MTS_HEAP_ID_MSG_REGISTRATION,sizeof(MTS_MSG_TYPE))

And I got:

00001a B23=0x1028262
B24=0x23343642 B25=0x4a4101
B26=0xbab550a7 B27=0x0
B28=0x0 B29=0x1
B30=0xffffffff B31=0xffffffff
NTSR=0x1000c
ITSR=0x0
IRP=0x0
SSR=0x0
AMR=0x0
RILC=0x0
ILC=0x0
Exception at 0x0
EFR=0x2 NRP=0x0
Internal exception: IERR=0x1
Instruction f[C66xx_0] etch exception
ti.sysbios.family.c64p.Exception: line 248: E_exceptionMin: pc = 0x00000000, sp = 0x00889220.
To see more exception detail, use ROV or set 'ti.sysbios.family.c64p.Exception.enablePrint = t[C66xx_0] rue;'
xdc.runtime.Error.raise: terminating execution

What am I not understanding? Isn't it the way to allocate a heap to the messaging module?

Furthermore, I do I get the statistics of my heaps? (the one for messages and the global one)

Here is the releavnt code that I am using1057.heap_messages.c




  • Hi Aymeric,

    Couple inital questions. What version of SYS/BIOS and IPC are you using. What device are you using? What is the value of MTS_HEAP_ID_MSG_REGISTRATION. It needs to be unique and by default < 8.

    Todd

  • FYI: I dynamically registered a heap also and it did not show up in ROV->MessageQ->Module->heaps either. I'm looking into this.

    Todd

  • Hi Todd,

    Thanks for looking into my problem. The sample of code I attached will provide you all the information regarding the code I wrote.

    The registration ID is 2 (0 is used for multicore communication, 1 will be used to use a logger (I hope to send logs to a telnet session) , 2 will be a pool shared by all the threads to communicate between them).

    I will also start with an initial question, is my assumption of creating a big heap (common to all my code and Bios code) and then use part of this memory as a smaller pool for other needs (like messages) correct. Am I allowed to do that or it must be created independently right from the beginning?

    Aymeric

  • Hi Aymeric,

    Sorry, I missed seeing the file.

    Your approach of allocating blocks out of one big heap and using that to create a new heap is fine.

    Looking at your code, you are not checking to make sure the Osal_platformMalloc succeeded. Can you add a check?

    Todd

  • Todd,

    You are correct, I was just testing, I will add this check. I was validating my results using the debugger and the ROV to ensure I understood what was doing on.

    For your info (using my memory map), this what the ROV tells me about my heap (global one)

    the size of one message is (32 (MSH_HEADER) + 32(my dummy variables))

    Before I called OSAL_platformMalloc, heap=0xXXXXF368 and after heap=0xXXXXF0E8 which are the 10 messages I want to allocate

    After I called HeapBuf_create, the heap is 0xXXXXF0B8 (I assume it is a header that is added by the bios to manage the heap)

    MessageQ_alloc fails with the information I put in my email.

    Aymeric

  • Aymeric,

    I think I found the problem. You need to register the heap handle not the address of the buffer.

    status = MessageQ_registerHeap (gMtsHeapAddress,MTS_HEAP_ID_MSG_REGISTRATION);

    should be

    status = MessageQ_registerHeap (gMtsHeapHandle,MTS_HEAP_ID_MSG_REGISTRATION);

    Todd

  • Todd,

    I will try this as soon as I get back to work. I had considered this before but the help said this:

    Int MessageQ_registerHeap ( Ptr  heap,
    UInt16  heapId 
    )

    Where the "Ptr" is not really clear what it is pointing on. The header of the functions says "heap to register" but perhaps it would have been better to say that it is the handle to the heap.

    Anyway, I will get back to you on that, if my allocations works then I will close the query.

    Last thing Todd, how do I get the statistics on this heap? I have seen an example using this function Memory_getStats(heap, &stats); but my problem is that I do not know how to get "IHeap_Handle heap" from the heapbuf handle that I have., is there a conversion?

    Then, regarding the global heap, can I get the stats by doing the following?

    IHeap_Handle heap = HeapMem_Handle_upCast(heap0);

    Get back to you as soon as I can, thanks so much for your support

    Aymeric

    Int MessageQ_registerHeap ( Ptr  heap,
    UInt16  heapId 
    )

    Register a heap with MessageQ.

    This function registers a heap with MessageQ. The user selects a unique heapId associated with this heap. When a message is allocated via the MessageQ_alloc function, the heapId is specified. Internally, MessageQ uses the heapId to access the heap.

    Care must be taken when assigning heapIds. Internally MessageQ stores the heapId into the message. When the message is freed (via MessageQ_free), the heapId is used to determine which heap to use. On systems with shared memory the heapIds must match on corresponding processors. For example, assume there is a heap called myHeap which acts on shared memory and processors 0 and 1 both use this heap. When you register the heap with MessageQ, the same heapId must be used on both processor 0 and 1.

    If a heap is already registered for the specified heapId, no action is taken and MessageQ_E_ALREADYEXISTS is returned.

    Parameters:
    [in] heap Heap to register
    [in] heapId heapId associated with the heap
    Returns:
    MessageQ status:
  • Aymeric,

    Yes, you can use the upCast method to get an IHeap_Handle from a HeapMem_Handle that you can use in Memory_getStats. This is true for all heap implements (e.g. HeapBuf_Handle_upCast(someHeapBuf_handle), etc.).

    Todd