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.

Dynamic allocation of variable size messages in MessageQ

Hi,

I'm trying to setup a communication framework between cores using MessageQ module, where I need to dynamically allocate a message for being sent. At runtime I need to define the type of data as well as the lenght or size of the data to be sent. However, I see that in MessageQ you need to define a struct where the first field is the  MessageQ_MsgHeader and then you define extra elements for extending the message, but you have to define statically the the type and the lenght of the data, like the following example:

Typedef struct myMsg {

    MessageQ_MsgHeader           header;

    int                                                 data;

} myMsg;

Then my question is how is the best way to use messageQ for sending messages where the type and the lenght is not statically defined? Should I send a pointer to other buffer instead of allocation memory in the message for the data itself?, if so what is the best way to reserve this extra buffer (Heap*Buf) and how to define the data type dinamically.

Thanks,

Miguel

  • Miguel,

    You are right.  Your message would be a MessageQ_MsgHeader and pointer to a buffer instead of the structure embedded.

    I assume you will be sharing this extra buffer between different processors correct?  If so you could create it with HeapBufMP or HeapMemMP.  If you're not shared it between different processors then HeapBuf or HeapMem be would sufficient.

    Note:  HeapBuf and HeapBufMP are fixed sized allocations while HeapMem and HeapMemMP are variable sized.

    Judah

  • Hi Judah,

    Ok now is clear for me that the proper way is to create an extra buffer with the Heap* modules and then just pass the pointer, however What if I don't know the type of data of the buffer? Is it possible to send a void pointer in the message?

    Thanks,

    Miguel

  • Hi Judah,

    What is the proper way to share between different cores a buffer created by one of them? Is also possible that all the Cores can have simultaneous access to the same buffer? If so GateMP should be used, or the multiprocessor exclusion is guaranted by the SharedRegion module or the Heap*MP module?

    Thanks,

    Miguel

  • Miguel,

    Use one of the Heap*MP, these heaps were purposely created to allow different cores to access them.  So say that 2 cores simulanteously call Memory_alloc(), this is okay when using Heap*MP because it uses a GateMP to prevent one core from interrupting the other core if the other core got there first and is in the middle of doing an alloc.

    If you don't know the type of data...using a Void * is fine.

    I don't think any buffer should be "simulateneous access" by different cores.  Only 1 core should ever own a buffer at any given moment.  When its done with the buffer, it then hands it to the next core.

    Judah

  • Judah,

    What I would like to do is to create a FIFO in shared memory, in such a way that this FIFO can be read or writen by any core at any time, of course ensuring multiprocessor exclusion. In fact this architecture was implemented before like this, using the DSPLink and also MPCS and POOL modules, in order to create shared memory regions with multiprocessor exclusion.

    By simultaneous access I mean that any processor can try to read or write data from/to the buffer at any time but using GateMP to ensure mutual exclusion.

    So my question is if with Heap*MP is possible to create a buffer shared by more than one core at the same time and by using GateMP you ensure mutual exclusion among the processors?.

    What I did so far is that one processor creates a buffer with HeapBufMP, then I write some data to this buffer, and with MessageQ_put I send to other processor the pointer to this buffer, for reading the data, however the data that I'm writing is not matching with the data that I'm reading, even if the pointer that I get in the other processor is the right address.

    Can you also bring me a code example about how is the right way to share buffer (or pointer to the buffer) among the processors?

    Thanks,

    Miguel

  • Miguel,

    Yes, using Heap*MP which already uses GateMP, you an ensured mutual exclusion among the processors!

    According to previous posts in this forum, You said the MessageQ Msg contains only a pointer to the buffer (where the real data is).  If this is the case, then after getting the data in your buffer, you need to do a Cache_wbInv() of the buffer before doing a MessageQ_put of the msg.  This will ensure the data is coherent.

    Judah