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.

HeapMem and GateMutex

Other Parts Discussed in Thread: SYSBIOS

Hi!

I statically create one HeapMem Instant by GUI tools, and this HeapMem shall be shared by several tasks, some tasks use Memory_alloc() ,fill message and call MailBox_post(), other tasks  may call MailBox_pend() ,get the message and then call Memory_ free().

This is a traditional intertask communication, so I want to know

1.if Memory_alloc() and Memory_free() API is task-safe API?

2.I read BIOS USER Guide V6.34. it seems you have to use gatemutex to protect this shared HeapMem Instant, is it right?

3.but I can't config this gatemutex  in HeapMem Instant Page, gateMutex config has to be done by editing .cfg file, no GUI tools , is it right?

  • Sorry, I search the E2E forum, and Find:

    http://e2e.ti.com/support/embedded/bios/f/355/p/224914/791851.aspx#791851

    (1)  HeapMem uses a GateMutex by default.   This allows a single HeapMem instance to be used by multiple Tasks.   If the Task module is disabled (not common and not allowed when using NDK), then HeapMem will use 'GateSwi'.   If both Task and Swi modules are disabled (even more uncommon and unlikely), then HeapMem will use GateHwi.    So, if you call memory allocation at Task level, then you should be safe.   If you try to call malloc() or Memory_alloc() from an Swi or Hwi ISR, then GateMutex will raise an assert().    You should not need to do any special configuration options to get this default behavior.

    Thanks.

  • I have another question for this issue:

    When I search .cfg file I can't find any about GateMutex while creating HeapMem instant? the following is not found. why?

    var GateMutexPri = xdc.useModule('ti.sysbios.gates.GateMutexPri');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    HeapMem.common$.gate = GateMutexPri.create();

  • HeapBuf and HeapMultiBuf is also task safe ,just like HeapMem?

  • Hi,Sir!

    When I call Memory_getStats(), does it give different HeapBuf information in HeapMultiBuf instant? for example:

    HeapMultiBuf including three size HeapBuf

    HeapBuf0 , 32 bytes * 10

    HeapBuf1, 64bytes*10

    HeapBuf2,128Bytes*10

    Can Memory_getStats() provide detailed information about usage map on those three HeapBuf?

    typedef struct Memory_Stats {
        Memory_Size totalSize;
        Memory_Size totalFreeSize;
        Memory_Size largestFreeSize;
    Memory_Stats;
    the reurn infor called by Memory_getStats() is a structure defined by above, it seems no any usage map information in this structure.


  • Anyone else can give me some advice?

  • Hi Decai,

    decai wang said:

    When I search .cfg file I can't find any about GateMutex while creating HeapMem instant? the following is not found. why?

    var GateMutexPri = xdc.useModule('ti.sysbios.gates.GateMutexPri');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    HeapMem.common$.gate = GateMutexPri.create();

    If you don't specify which gate you want, the XDCscript in packages\ti\sysbios\heaps\HeapMem.xs will automatically create a GateMutex object for thread-safety.

    decai wang said:

    HeapBuf and HeapMultiBuf is also task safe ,just like HeapMem?

    Yes.

    decai wang said:

    When I call Memory_getStats(), does it give different HeapBuf information in HeapMultiBuf instant? for example:

    HeapMultiBuf including three size HeapBuf

    HeapBuf0 , 32 bytes * 10

    HeapBuf1, 64bytes*10

    HeapBuf2,128Bytes*10

    Can Memory_getStats() provide detailed information about usage map on those three HeapBuf?

    typedef struct Memory_Stats {
        Memory_Size totalSize;
        Memory_Size totalFreeSize;
        Memory_Size largestFreeSize;
    Memory_Stats;
    the reurn infor called by Memory_getStats() is a structure defined by above, it seems no any usage map information in this structure.

    Memory_getStats() will give you the sum of the individual 3 heaps combined. The code is in packages\ti\sysbios\heaps\HeapMultiBuf.c (in function HeapMultiBuf_getStats())

  • Thanks!

    If I want to optimize the HeapMutilBuf, I think HeapMultiBuf_getStats() is not enough, it is better to show:

    HeapBuf0, 5 used, 5 free, maximum used 8

    HeapBuf1, 2 used,8 free,maximum used 5

    HeapBuf2, 3 used,7 free,maximum use 5

    So HeapBuf0 is Ok, don't change; HeapBuf1 blocks can be reduced from 10 to 8 and HeapBuf2 blocks can be reduced from 10 to 8. so some of RAM size can be released.

    So, How can I get the detailed information like  above ?

  • Unfortunately, we don't have a runtime API to give that detailed information. If you need the stats of each buffer at that granular level, you may want to consider to just create several HeapBuf instances each having different block sizes.

  • Hi Tom

    What is the .cfg file equivalent of this code below? since I have .cfg file issues already with HWI's I also want an easy test that the HWI is REALLY disabled

    T_U16 RxgateKey;
    GateHwi_Handle RxgateHwi;

    RxgateHwi = GateHwi_create(&prms, NULL);