Multitasking and Resource Sharing in Embedded Systems
Multitasking and Resource Sharing in Embedded Systems
Multitasking and Resource Sharing in Embedded Systems
Channel 1 Channel 2
plot()
Problems:
Inaccurate timing Unpredictable response time as more components are added Even if we add flags to check the occurrence of an event, most of the CPU time will be wasted on polling those flags
Solution: Multitasking
Modular approach: Divide the overall activity into independent tasks. Tasks can be directly linked with interrupt handlers so that events can directly synchronize with the code. Tasks execution dependent on event occurrence. Activities requiring more attention are assigned to higher priority tasks
Solution: Multitasking
Types of multitasking
Cooperative multitasking
Multiple tasks execute by voluntarily ceding control to other tasks. One defines a series of tasks and each task gets is own subroutine stack. Idle task calls an idle routine Another architecture used is an event queue, removing events and calling subroutines based on their values. Pros & Cons: Same as control loop except that more modular approach. But due to non-determinism of time factor, not used in embedded systems.
Multitasking types(contd.)
Pre-emptive multitasking (Let OS Be the Boss!)
Used in most of the embedded systems. Time-slices allotted to processes. Process context-switched with the next process in the scheduling queue due to following reasons:
the process has consumed its time slice, and the system clock interrupt pre-empts the process the process goes to wait state (often due to planned sleeping, waiting for an I/O event to happen, or just Mutual exclusion) a higher priority process becomes ready for execution, which causes a pre-emption the process gives away its time slice voluntarily the process terminates itself
Problems
Compilers, Linker and Loader
Provide abstraction for the application developer Assign proper values to segment register
System programmer not so privileged Task can access other tasks code or data Task can execute privileged instructions
Protected Mode
Segment registers are indexed into special tables All tables initialized and maintained by the operating system, but interpreted by the CPU. Segment Base Address and 8 byte descriptor used Descriptor contains segment size, flag indicating use of segment
LDT
A LDT usually contains a tasks code and data descriptors, and is built when the task is loaded in memory. only one is active at a time
Privilege levels
Using level 0 for all system software and 3 for application software is very common
Priority inversion
Unbounded Priority inversion: Consider another task M, which has higher priority than task l, but lower than H and does not need the shared resource. While H waits for L to complete its operation, M preempts L (since it doesnt need the shared resource). M finishes its operation, and L gets control of the processor. After L finishes its operation, H gets control of the shared resource. Several other processes like M may lead to indefinite blocking of H. This type of blocking is called unbounded priority inversion.
References
How to use priority inheritance? Priority inheritance protocol: An approach to realtime synchronization The Priority Ceiling Protocol: A Method for Minimizing the Blocking of High-Priority Ada Tasks What really happened on Mars? Embedded x86 programming Working in the protected mode environment