Overview of Reentrant Functions, IPC, and Priority Management in Embedded Systems & IoT
Explore reentrant vs non-reentrant functions, shared resources, priority inversion and inheritance, and inter-process communication methods like shared memory and message passing in embedded systems and IoT.
RAJASEKAR T, AP/ECE
ReentrantFunctions
• A reentrant function can be used by more than one task
without fear of data corruption.
• A re-entrant function can be interrupted at any time and
resumed at a later time without loss of data.
• Reentrant functions either use local variables (i.e., CPU
registers or variables on the stack) or protect data when
global variables are used.
20EC211- Embedded
Systems & IoT
2
3.
RAJASEKAR T, AP/ECE
ReentrantFunctions
• Copies of the arguments to strcpy() are placed on the task’s
stack, strcpy() can be invoked by multiple tasks without fear
that the tasks will corrupt each other’s pointers.
20EC211- Embedded
Systems & IoT
3
Rajasekar T AP/ECE5
Shared resources
• Critical sections
• Semaphores
• The semaphore is used to guard a resource.
• The semaphore names are, by tradition, P() to gain access to the protected
resource and V() to release it.
• /* some nonprotected operations here */
• P(); /* wait for semaphore */
• /* do protected work here */
• V(); /* release semaphore */
20EC211- Embedded
Systems & IoT
Rajasekar T AP/ECE9
Priority inversion
• Shared resources cause a new and subtle scheduling problem: a low-
priority process blocks execution of a higher-priority process by
keeping hold of its resource, a phenomenon known as priority
inversion.
20EC211- Embedded
Systems & IoT
11.
Rajasekar T AP/ECE11
Priority inheritance
• The most common method for dealing with priority inversion is
priority inheritance: promote the priority of any process when it
requests a resource from the operating system.
• The priority of the process temporarily becomes higher than that of
any other process that may use the resource.
• Once the process is finished with the resource, its priority is demoted
to its normal value.
20EC211- Embedded
Systems & IoT
32.
Rajasekar T AP/ECE32
Inter process communication
mechanisms
• There are two major styles of inter process communication:
• Shared memory
• Message passing.
20EC211- Embedded
Systems & IoT
33.
Rajasekar T AP/ECE33
Shared memory communication
20EC211- Embedded
Systems & IoT
34.
Rajasekar T AP/ECE34
• Two components, such as a CPU and an I/O device, communicate
through a shared memory location.
20EC211- Embedded
Systems & IoT
35.
Rajasekar T AP/ECE35
Elastic Buffers as Shared Memory
• The text compressor uses the CPU to compress incoming text, which
is then sent on a serial line by a UART.
20EC211- Embedded
Systems & IoT
Rajasekar T AP/ECE38
• The message is not stored on the communications link, but rather at
the senders/receivers at the endpoints.
• In contrast, shared memory communication can be seen as a
memory block used as a communication device, in which all the data
are stored in the communication link/memory.
20EC211- Embedded
Systems & IoT
53.
Rajasekar T AP/ECE53
Queue
• A queue is a common form of message passing. The queue uses a
FIFO discipline and holds records that represent messages.
20EC211- Embedded
Systems & IoT
Rajasekar T AP/ECE55
Signals
• A signal is simple because it does not pass data beyond the existence
of the signal itself.
• A signal is analogous to an interrupt, but it is entirely a software
creation.
• A signal is generated by a process and transmitted to another process
by the operating system.
20EC211- Embedded
Systems & IoT
56.
Rajasekar T AP/ECE56
Mailboxes
• The mailbox is a simple mechanism for asynchronous
communication. Some architectures define mailbox registers.
• These mailboxes have a fixed number of bits and can be used for
small messages.
20EC211- Embedded
Systems & IoT