Allocation in system memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Allocation in system memory

724 Views
alessandraorlan
Contributor I

Hi to all,

I have two questions about memory management with MQX.

The first question is basic and due to my short experience on this OS:

I know that both _mem_ alloc and _mem_alloc_system allocate data into default pool,  to a private task or to a generic system task, respectively.

In general, the memory private ownership of a task could be a limit generating wrong deallocation and memory consumption.

--> According to your experience, could I always exploit system memory allocation safely and without secondary effects?

On the other hand,  to overcome the private ownership,  I made an exercise using _mem_transfer

instruction before memory deallocation, as follows:

#ifdef TEST_MEM_TRANSFER

  _task_number taskn = GET_MEMBLOCK_PTR(memory)->TASK_NUMBER;

  if ((taskn != TASK_NUMBER_FROM_TASKID(task_get_id()) && (taskn != TASK_NUMBER_FROM_TASKID(_mqx_get_system_task_id()))

  _mem_transfer(memory, BUILD_TASKID(kernel_data->INIT.PROCESSOR_NUMBER, task_num), _mqx_get_system_task_id);

#endif

Above I supposed to know a priori the processor number of the task owner.

My question is:

Is there a way to infer the task id (processor number + task number) of the owner task directly from  memory block structure?

0 Kudos
2 Replies

403 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi!

Actually you can see that _lwmem_alloc_internal() returns the address where block_ptr was created plus the size of this structure.

retval = (void *) ((unsigned char *) block_ptr + sizeof(LWMEM_BLOCK_STRUCT));

This means that if you substract manually from the memory pointer the sizeof(LWMEM_BLOCK_STRUCT)) you will get the block starting address and you only need calculate the address of bloct_ptr-> U->S->TASK_NUMBER

Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

403 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Alessandra,

_mem_alloc() calls _GET_KERNEL_DATA(kernel_data); followed by next code.

result = _lwmem_alloc_internal(requested_size, kernel_data->ACTIVE_PTR,

                    (_lwmem_pool_id) kernel_data->KERNEL_LWMEM_POOL, FALSE);

Here you will find LWMEM_BLOCK_STRUCT_PTR block_ptr; which contains the owner task number. However, this information is internal, you may need either to reproduce all the private structures in your application or modify BSP to save the task number that called the mem_alloc() and make it readable for your application.

I hope this helps.


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos