message-based inter-task...
TRANSCRIPT
![Page 1: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/1.jpg)
Based on G.C. Buttazzo,
«Sistemi in Tempo Reale», Capitolo 10
Message-based
Inter-task communication
Embedded Real-Time Systems
Prof. Davide Brugali
Università degli Studi di Bergamo
![Page 2: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/2.jpg)
Global shared variables
In most RT applications, tasks exchange data through global
shared variables.
Advantages
this is the fastest mechanism
low run-time overhead
schedulability analysis is available
Disadvantages Data must be accessed in mutual exclusion:
non-preemptive regions;
semaphores, priority inheritance, priority ceiling.
Not good for modular design:
local details are exposed to other tasks;
a change in a task affect other tasks.
![Page 3: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/3.jpg)
Message passing paradigm
Another approach is to exchange data through a message passing
paradigm:
Every task operates on a private memory space;
Data are exchanged by messages through a channel.
![Page 4: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/4.jpg)
Communication Ports
Many operating systems provides the channel abstraction through the port construct.
A task can use a port to exchange messages by means of two primitives:
send sends a message to a port
receive receives a message from a port
Some operating systems allows the user to define different types of ports, with peculiar semantics
![Page 5: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/5.jpg)
Port characteristics
Ports may differ for:
number of tasks allowed to send messages;
number of tasks allowed to receive messages;
policy used to insert and extract messages.
behavior to manage exceptions (sending to a full port or receiving
from an empty port).
Before being used, a port has to be created, and then destroyed when
it is not needed any more.
Port attributes need to be defined at creation time
![Page 6: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/6.jpg)
Sending a message
![Page 7: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/7.jpg)
Receiving a message
![Page 8: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/8.jpg)
Using a port
![Page 9: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/9.jpg)
Periodic task communication
![Page 10: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/10.jpg)
Periodic task communication
![Page 11: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/11.jpg)
Periodic task communication
![Page 12: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/12.jpg)
Exchanged messages
![Page 13: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/13.jpg)
Buffer saturation
![Page 14: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/14.jpg)
STICK Ports
![Page 15: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/15.jpg)
STICK Ports
![Page 16: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/16.jpg)
Blocking on STICK ports
Although a task cannot blocks for a full or empty buffer, it can block
for mutual exclusion:
indeed a semaphore is needed to protect the internal buffer from
simultaneous accesses.
Long messages may cause long blocking delays on such a semaphore.
Long waiting times due to long messages can be avoided through a
buffer replication mechanism.
![Page 17: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/17.jpg)
Cyclic Asynchronous Buffer (CAB)
It is a mechanism for exchanging messages among periodic tasks with
different rates.
Memory conflicts are avoided by replicating the internal buffers.
At any time, the most recent message is always available for reading.
A new message overrides the previous one.
Messages are not consumed by reading.
![Page 18: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/18.jpg)
Simultaneous accesses
![Page 19: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/19.jpg)
Dual buffering
Dual buffering is often used to transfer large data, (images) from the
input peripheral device to a task:
Once written, the new message becomes available to the next
reader:
![Page 20: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/20.jpg)
Accessing a CAB
A CAB generalizes dual buffering for N readers;
Data is accessed through a memory pointer.
Hence, a reader is not forced to copy the message in its memory
space.
More tasks can concurrently read the same message.
At any time, a pointer (mrb) points to the most recent buffer used
for writing a new message.
![Page 21: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/21.jpg)
CAB example
![Page 22: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/22.jpg)
CAB example
![Page 23: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/23.jpg)
CAB example
![Page 24: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/24.jpg)
Dimensioning a CAB
If a CAB is used by N tasks, to avoid blocking, it must have at least N
+1 buffers.
The (N+1)-th buffer is needed for keeping the most recent message
in the case all the other buffers are used.
![Page 25: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/25.jpg)
Inconsistency with N buffers
![Page 26: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/26.jpg)
Writing Protocol
To write a message in a CAB a task must:
1. ask the CAB for a pointer to a free buffer;
2. copy the message into the buffer using the pointer;
3. release the pointer to the CAB to make the message
accessible to the next reader.
![Page 27: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/27.jpg)
Reading Protocol
To read a message from a CAB a task must
1. get the pointer to the most recent message in the
CAB;
2. process the message through the pointer;
3. release the pointer, to allow the CAB to recycle the
buffer if it is not used.
![Page 28: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/28.jpg)
CAB Primitives
![Page 29: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/29.jpg)
CAB Primitives
![Page 30: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/30.jpg)
Writing in a CAB
![Page 31: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/31.jpg)
Reading from a CAB
![Page 32: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/32.jpg)
Implementing CABs
![Page 33: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/33.jpg)
cab_reserve()
![Page 34: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/34.jpg)
cab_putmes()
![Page 35: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/35.jpg)
cab_getmes()
![Page 36: Message-based Inter-task communicationrobotics.unibg.it/teaching/srt/pdf/07_TaskCommunication.pdf · Communication Ports Many operating systems provides the channel abstraction through](https://reader034.vdocuments.us/reader034/viewer/2022043000/5f76532683af8646c45fe94a/html5/thumbnails/36.jpg)
cab_unget()