Double FreeRTOS AMP synchronization

alessandro90 wrote on Friday, March 25, 2016:

Hi, I’m completely new to FreeRTOS and I’m trying to study it to understand if it fits my needs for my application. My idea is to use it on a Zynq board, so with a dual core ARM, building an AMP system with two FreeRTOS instances running at the same time. However, I need also strict synchronization between their tasks. From Xilinx notes, I saw that for bare metal applications the standard way to synchronize two cores is using polling on some shared variables in the OCM, but of course I don’t like busy waiting. Is there a standard/suggested way to synchronize two instances of FreeRTOS? Of course also suggestions on a different approach to use both cores is welcome.
Thanks in advance.

richard_damon wrote on Friday, March 25, 2016:

With AMP, since it is asymetric, you can’t just try to treat things as symetric and get things to work. An AMP system tends to be designed as mostly independent systems with a defined protocal between them.

Shared variables are ok for sending data between processors, but isn’t good for sending syncronization between them. For that I would build on something based on the inter-processor interrupt, so one processor, so one processor sets up information in the shared memory, and then sends an interrupt to the other processer. The interrupt code in the second processor perhaps looks at parts of the data, and then signals to the appropriate syncronizing primitives in its OS, that tasks could be waiting on.

alessandro90 wrote on Friday, March 25, 2016:

Thank you for your valuable suggestion. Probably this is not the best place where to answer, but what about the Xilinx OpenAMP framework? It is well integrated, reliable and efficient in FreeRTOS to your experience? Because at this point, if the synchronization between cores would be too tricky to be implemented from scratches, I’m thinking to adopt a linux/freertos solution to use both cores with an already developed framework.

rtel wrote on Friday, March 25, 2016:

The Xilinx OpenAMP code is definitely one approach you could take,
although it is intended for Linux to FreeRTOS comms, and may be a bit
heavy for FreeRTOS to FreeRTOS comms.

We have implemented some light weight event driven AMP systems using
thread safe circular buffers and direct to task notifications. There
are several approaches that can be taken - but the basis is the same for
all approaches; one core buffers some data then generates an interrupt
in the other core, the ISR uses a direct to task notification to unblock
a task that reads the data from the buffer and processes as necessary.
Simple and light weight.

alessandro90 wrote on Friday, March 25, 2016:

Thank you, this is exactly the kind of information I was looking for, very clear!

xuantran wrote on Friday, April 05, 2019:

Hi, could I use a queue for inter-processor communication between two cores? If possible, what are the differences between using message buffer and using queue? If it is not possible, would you mind explaning it? I’ll be very greatful for any help.

rtel wrote on Friday, April 05, 2019:

No, a queue cannot be used as it contains lists of tasks waiting to send
and lists of tasks waiting to receive - memory addresses that are not
shared between cores. Message/stream buffers are designed so that the
only shared memory required is the memory used to actually pass the
payload data. Although by default message/stream buffers operate on a
single core, the macros that indicate the end of a send or receive
operation can be overridden to just generate an interrupt in the other core.

xuantran wrote on Monday, April 08, 2019:

Thank you so much for your answer.

xuantran wrote on Monday, April 08, 2019:

As I understood that a queue is considered as data storage. Is that correct?

What happens if a queue is created in shared memory by using the function XQueueCreateStatic () and there are only two tasks, each of which is created on each core, to be allowed to send/receive data to/from this queue. Every core polls the queue to receive data. Is is possible?

I’ll be greatful for any help.

rtel wrote on Monday, April 08, 2019:

That would require an SMP (symmetric multiprocessing, where one instance
of FreeRTOS schedules tasks across multiple cores) version of FreeRTOS -
of which there are some about but not versions developed or supported by
us. The scenario you described is AMP (asymmetric multiprocessing,
where there is an independent instance of the OS on each core), where
one instance of the OS cannot schedule tasks under the control of
another instance.

xuantran wrote on Tuesday, April 09, 2019:

Thank you so much for your answer.