Rtos Concepts

62,034 views

Published on

BASIC ABOUT REAL TIME OPERATING SYSTEM

Published in: Technology, Business
11 Comments
27 Likes
Statistics
Notes
No Downloads
Views
Total views
62,034
On SlideShare
0
From Embeds
0
Number of Embeds
2,341
Actions
Shares
0
Downloads
4,463
Comments
11
Likes
27
Embeds 0
No embeds

No notes for slide

Rtos Concepts

  1. 1. RTOS Concepts
  2. 2. What Does Real-Time Mean? <ul><li>Main difference to other computation: time </li></ul><ul><li>time means that correctness of system depends </li></ul><ul><li>- not only on logical results </li></ul><ul><li>- but also on the time the results are produced </li></ul><ul><li>real => reaction to external events must occur during their evolution. </li></ul><ul><li>system time ( internal time ) has to be measured </li></ul><ul><li>with same time scale as controlled environment </li></ul><ul><li>( external time ) </li></ul>
  3. 3. Foreground/Background. <ul><li>Systems which do not use an RTOS </li></ul><ul><li>An application consist of an infinite loop which calls application modules to perform the desired operations. </li></ul><ul><li>The modules are executed sequentially (background) with interrupt service routines (ISRs) handling asynchronous events (foreground). </li></ul><ul><li>Batch process </li></ul><ul><li>A process which executes without user interaction. </li></ul><ul><li>Interactive process </li></ul><ul><li>A process which requires user interaction while executing </li></ul>
  4. 4. Kernel <ul><li>Kernel : the smallest portion of the operating system that provides </li></ul><ul><li>task scheduling, dispatching, and intertask communication. </li></ul><ul><li>Kernel types </li></ul><ul><ul><li>Nanokernel - the dispatcher </li></ul></ul><ul><ul><li>Microkernel - a nanokernel with task scheduling </li></ul></ul><ul><ul><li>Kernel - a microkernel with intertask synchronization </li></ul></ul><ul><ul><li>Executive - a kernel that includes privatized memory blocks, I/O services, and other complex issues. Most commercial real-time kernels are in this category. </li></ul></ul><ul><ul><li>Operating system - an executive that also provides generalized user interface, security, file management system, etc </li></ul></ul>
  5. 5. What is RTOS? <ul><li>A real-time operating system (RTOS) that supports real-time applications and embedded systems. </li></ul><ul><li>Real-time applications have the requirement to meet task deadlines in addition to the logical correctness of the results. </li></ul><ul><li>– Multiple events handled by a single processor </li></ul><ul><li>– Events may occur simultaneously </li></ul><ul><li>– Processor must handle multiple, often competing events </li></ul>
  6. 6. Desirable Features of Real-Time Systems <ul><li>Timeliness </li></ul><ul><li>- OS has to provide kernel mechanisms for </li></ul><ul><li>- time management </li></ul><ul><li>- handling tasks with explicit time constraints </li></ul><ul><li>Deterministic </li></ul><ul><li>Design for peak load </li></ul><ul><li>Predictability </li></ul><ul><li>Fault tolerance </li></ul><ul><li>Maintainability </li></ul><ul><li>  </li></ul>
  7. 7. Multitasking <ul><li>Must provide mechanisms for scheduling and switching for several user and kernel tasks </li></ul><ul><li>Maximize CPU utilization </li></ul><ul><li>Allow for managing of complex and real-time applications </li></ul>
  8. 8. Categories <ul><li>Hard Real Time System: </li></ul><ul><li>failure to meet time constraints leads to system failure </li></ul><ul><li>Firm Real Time System: </li></ul><ul><li>low occurrence of missing a deadline can be tolerated </li></ul><ul><li>Soft Real Time System: </li></ul><ul><li>performance is degraded by failure to meet time constraints </li></ul><ul><li>An RTOS differs from common OS, in that the user when using the former has the ability to directly access the microprocessor and peripherals. </li></ul><ul><li>Such an ability of the RTOS helps to meet deadlines. </li></ul>
  9. 9. Real-Time Systems <ul><li> RTOS is a multitasking system where multiple tasks run concurrently </li></ul><ul><li>– system shifts from task to task </li></ul><ul><li>– must remember key registers of each task </li></ul><ul><li>• called its context </li></ul><ul><li>RTOS responsible for all activities related to a task: </li></ul><ul><li>– scheduling and dispatching </li></ul><ul><li>– intertask communication </li></ul><ul><li>– memory system management </li></ul><ul><li>– input/output system management </li></ul><ul><li>– timing </li></ul><ul><li>– error management </li></ul><ul><li>– message management </li></ul>
  10. 10. Basic requirements of an RTOS. <ul><li>(i) Multi-threading and preemptibility </li></ul><ul><li>(ii) Thread priority </li></ul><ul><li>(iii) Thread synchronization mechanisms </li></ul><ul><li>(iv) Priority inheritance </li></ul><ul><li>(v) Predefined latencies </li></ul><ul><li>Task switching latency: time to save the context of a currently executing task and switch to another task.. </li></ul><ul><li> Interrupt latency: time elapsed between the execution of the last instruction of the interrupted task and the first instruction in the interrupt handler </li></ul><ul><li> Interrupt dispatch latency: This is the time to go from the last instruction in the interrupt handler to the next task scheduled to run. </li></ul>
  11. 11. Basic requirements of an RTOS. <ul><li>priority inversion </li></ul><ul><li>occurs when a higher priority task must wait on a low priority task to release a resource </li></ul><ul><li>Priority Ceiling </li></ul><ul><ul><li>Each resource has an assigned priority </li></ul></ul><ul><ul><li>Priority of thread is the highest of all priorities of the resources it’s holding </li></ul></ul><ul><li>Priority Inheritance </li></ul><ul><ul><li>The thread holding a resource inherits the priority of the thread blocked on that resource </li></ul></ul>
  12. 12. <ul><li>Preemptive scheduling . </li></ul><ul><li>In a preemptive kernel, when an event makes a higher priority task ready to run, the current task is immediately suspended and the higher priority task is given control of the CPU. </li></ul><ul><li>Reentrancy . </li></ul><ul><li>reentrant function : can be used by more than one task without fear of data corruption. </li></ul><ul><li>non-reentrant function : cannot be shared by more than one task unless mutual exclusion to the function is ensured by either using a semaphore, by disabling interrupts during critical sections of code. </li></ul><ul><li>A reentrant function can be interrupted at any time and resumed at a later time without loss of data. </li></ul><ul><li>Reentrant functions either use local variables (CPU registers or variables on the stack) or protect their data when global variables are used. </li></ul><ul><li>Compilers specifically designed for embedded software will generally provide reentrant run-time libraries. </li></ul>
  13. 13. Dynamic Memory Allocation <ul><li>RTOS uses abstract data types such as record, linked list, and queue </li></ul><ul><li>These data types normally use RAM dynamic memory allocation techniques </li></ul><ul><li>Data structures are created (allocated) on the fly during program execution and destroyed when no longer needed </li></ul><ul><li>– Requires large RAM memory </li></ul><ul><li>Heap is portion of memory used for dynamic memory allocation </li></ul><ul><li>Must allocate separate RAM spaces for the Heap as well as the Stack </li></ul><ul><li>Stack : Last-in-first-out (LIFO) data structure </li></ul><ul><li>RTOS requires multiple stacks - one for each task </li></ul>
  14. 14. Memory Management <ul><li>Two issues </li></ul><ul><ul><li>Heap management </li></ul></ul><ul><ul><li>Stack management </li></ul></ul><ul><li>Heap management </li></ul><ul><ul><li>Classic heap </li></ul></ul><ul><ul><li>Priority heap </li></ul></ul><ul><ul><li>Fixed block heap </li></ul></ul>
  15. 15. Memory Management <ul><li>Classic heap </li></ul><ul><ul><li>The memory is collected into one giant heap and partitioned according to the demand from tasks . </li></ul></ul><ul><ul><li>There are several “fit” memory allocation algorithms, e.g., best-fit, first-fit, that also attempt to minimize the memory fragmentation. </li></ul></ul><ul><ul><li>Has a big management overhead so is not used in real-time systems </li></ul></ul><ul><li>Priority heap </li></ul><ul><ul><li>partitions the memory along priority boundaries, e.g., a high and a low priority partitions are created </li></ul></ul><ul><li>Fixed block heap </li></ul><ul><ul><li>partitions the memory into several pools of fixed block length and upon a request, allocates a single block of memory from the pool with size equal or larger than the requested amount </li></ul></ul>
  16. 16. Stack management: <ul><li>When multiple tasks share a single processor, their contexts </li></ul><ul><li>(volatile information such as the contents of hardware registers, memory-management registers, and the program counter) </li></ul><ul><li>need to be saved and restored so as to switch them. </li></ul><ul><li> This can be done using </li></ul><ul><ul><ul><li>task-control block model OR one or more run-time stacks </li></ul></ul></ul><ul><li>Run-time stacks - used to keep context </li></ul><ul><ul><li>may use only one run-time stack for all the tasks or one run-time stack in conjunction with several application stacks (or private stacks), one for each task in memory </li></ul></ul><ul><ul><li>Multiple stack case allows tasks to interrupt themselves , </li></ul></ul><ul><ul><li>Stack size must be known a priori. </li></ul></ul><ul><ul><li>Operating system manages the stacks </li></ul></ul>
  17. 17. Task and Task Control Blocks <ul><li>In RTOS program consists of independent,asynchronous, and interacting tasks </li></ul><ul><li>– Must have capability to store task context </li></ul><ul><li>Context is kept in the control block of the task. </li></ul><ul><li>Having multiple tasks means multiple control blocks, which are maintained in a list </li></ul><ul><li>• RTOS updates TCB when task is switched </li></ul><ul><li>best for full-featured real-time operating systems </li></ul><ul><li>Device Control Block (DCB) </li></ul><ul><li>– tracks status of system associated devices </li></ul>
  18. 18. Priorities <ul><li>Priority </li></ul><ul><li>An ordinal number which represents the relative importance of a task. </li></ul><ul><li>Static priority </li></ul><ul><li>A priority which is not automatically adjusted by the system. </li></ul><ul><li>Static priority can typically be changed by user. </li></ul><ul><li>Dynamic priority </li></ul><ul><li>A priority which is adjusted automatically by the system according to task behavior and system loading. </li></ul><ul><li>Dynamic priority imposes an overhead on the system. </li></ul><ul><li>Dynamic priority can improve response times and eliminate indefinite postponing </li></ul>
  19. 19. Scheduling algorithms of RTOS <ul><li>The most commonly used static scheduling algorithm is the Rate Monotonic (RM) scheduling algorithm </li></ul><ul><li>The RM algorithm assigns different priorities proportional to the frequency of tasks. </li></ul><ul><li>The task with the shortest period gets the highest priority, and the task with the longest period gets the lowest static priority. </li></ul><ul><li>Rate monotonic algorithm is a dynamic preemptive algorithm based on static priorities </li></ul><ul><li>RM algorithm provides no support for dynamically changing task periods and/or priorities and tasks that may experience priority inversion. </li></ul>
  20. 20. Rate Monotonic <ul><li>Priority inversion occurs in an RM system where in order to enforce rate monotonicity, a non-critical task with a high frequency of execution is assigned a higher priority than a critical task with lower frequency of execution </li></ul><ul><li>A priority ceiling protocol (PCP) can be used to counter priority inversion, wherein a task blocking a higher priority task inherits the higher priority for the duration of the blocked task. </li></ul><ul><li>The priority ceiling protocol is used to schedule a set dependant periodic tasks that share resources protected by semaphores </li></ul>
  21. 21. Earliest deadline first <ul><li>Earliest deadline first (EDF) scheduling can be used for both static and dynamic real-time scheduling. </li></ul><ul><li>a dynamic priority algorithm which uses the deadline of a task as its priority. </li></ul><ul><li>The task with the earliest deadline has the highest priority </li></ul>
  22. 22. Minimum Laxity First <ul><li>A variant of EDF is Minimum Laxity First (MLF) scheduling where a laxity is assigned to each task in the system and minimum laxity tasks are executed first. </li></ul><ul><li>Laxity : The difference between the time until a tasks completion deadline and its remaining processing time requirement. </li></ul><ul><li>{ the deadline by which _ { the amount of the task must be completed } computation </li></ul><ul><li> remaining to be performed } </li></ul><ul><li>MLF considers the execution time of a task, which EDF does not </li></ul>
  23. 23. Minimum Laxity First <ul><li>MLF assigns higher priority to a task with the least laxity </li></ul><ul><li>A task with zero laxity must be scheduled right away and executed without preemption or it will fail to meet its deadline. </li></ul><ul><li>The negative laxity indicates that the task will miss the deadline, no matter when it is picked up for execution. </li></ul><ul><li>A major problem with LLF algorithm is that it is </li></ul><ul><li>impractical to implement because laxity ties ( two or more tasks have the same laxities ) result in the frequent context switches among the corresponding tasks. </li></ul><ul><li>This will cause the system performance to remarkably degrade. </li></ul>
  24. 24. Modified Least Laxity First <ul><li>MLLF schedules the task sets the same as LLF algorithm. </li></ul><ul><li>If the laxity tie occurs, the running task continues to run with no preemption as far as the deadlines of other tasks are not missed. </li></ul><ul><li>The MLLF algorithm defers the context switching until necessary and it is safe even if the laxity tie occurs. </li></ul><ul><li>That is, it allows the laxity inversion where a task with the least laxity may not be scheduled immediately. </li></ul><ul><li>Laxity inversion applies to the duration that the currently running task can continue running with no loss in schedulability </li></ul>
  25. 25. Maximum Urgency First Algorithm <ul><li>solves the problem of unpredictability during a transient overload for EDF, LLF and MLLF algorithms. </li></ul><ul><li>This algorithm is a combination of fixed and dynamic priority scheduling, also called mixed priority scheduling. </li></ul><ul><li>With this algorithm, each task is given an urgency which is defined as a combination of two fixed priorities ( criticality and user priority ) and a dynamic priority that is inversely proportional to the laxity. </li></ul><ul><li>The MUF algorithm assigns priorities in two phases </li></ul><ul><li>Phase One concerns the assignment of static priorities to tasks </li></ul><ul><li>Phase Two deals with the run-time behavior of the MUF scheduler </li></ul>
  26. 26. Maximum Urgency First Algorithm <ul><li>The first phase consists of these steps : </li></ul><ul><li>1) It sorts the tasks from the shortest period to the longest period. Then it defines the critical set as the first N tasks such that the total CPU load factor does not exceed 100%. These tasks are guaranteed not to fail even during a transient overload. </li></ul><ul><li>2) All tasks in the critical set are assigned high criticality.The remaining tasks are considered to have low criticality. </li></ul><ul><li>3) Every task in the system is assigned an optional unique user priority </li></ul><ul><li>{ CHIMERA II, a real-time operating system being used to control sensor-based control systems } </li></ul>
  27. 27. Maximum Urgency First Algorithm <ul><li>In the second phase , the MUF scheduler follows an algorithm to select a task for execution. </li></ul><ul><li>This algorithm is executed whenever a new task is arrived to the ready queue. </li></ul><ul><li>The algorithm is as follows: </li></ul><ul><li>1) If there is only one highly critical task, pick it up and execute it. </li></ul><ul><li>2) If there are more than one highly critical task, select the one with the highest dynamic priority. Here, the task with the least laxity is considered to be the one with the highest priority. </li></ul><ul><li>3) If there is more than one task with the same laxity, select the one with the highest user priority. </li></ul>
  28. 28. <ul><li>In addition to basic scheduling and context switching , a real-time kernel typically provides other valuable services to applications such as: </li></ul><ul><li>Time Delay </li></ul><ul><li>System Time </li></ul><ul><li>Inter-Process Communication (IPC) </li></ul><ul><li>Synchronization —semaphores or flags </li></ul><ul><li>Resource Protection - mutex </li></ul>
  29. 29. <ul><li>RTOS for small footprint, mobile and connected devices </li></ul><ul><li>Windows CE </li></ul><ul><li>(32 bit devices , minimum footprint of 400KB , 256 priority levels ) </li></ul><ul><li>RTOS for complex, hard real-time applications </li></ul><ul><li>LynxOS </li></ul><ul><li>(microkernel is 28 KB, 512 thread priority levels, supports memory protection ) </li></ul><ul><li>General purpose RTOS in the embedded industry </li></ul><ul><li>VxWorks </li></ul><ul><li>(256 priority levels, multitasking, deterministic context switching, </li></ul><ul><li>preemptive and round robin scheduling, binary and counting semaphores, mutual exclusion with inheritance, supports virtual memory configuration ) </li></ul>
  30. 30. <ul><li>RTOS for the Java Platform </li></ul><ul><li>Jbed RTOS package </li></ul><ul><li>( runs on 32 -bit microprocessors and controllers. Current versions support ARM7, 68k, PowerPC architectures, supports up to 10-thread priority levels, EDF ) </li></ul><ul><li>Objected-oriented RTOS </li></ul><ul><li>pSOSystem </li></ul>
  31. 31. Why Should I Use an RTOS? <ul><li>True that many or most applications can be written without the support of an RTOS. </li></ul><ul><li>A few reasons to consider using an RTOS : </li></ul><ul><li>The job of writing application software is generally easier using an RTOS, because the use of a kernel enforces certain disciplines in how your code is structured. </li></ul><ul><li>While the illusion of concurrency can be created without the use of an RTOS (though not always), it almost always results in a much more complex piece of software. </li></ul>
  32. 32. Disadvantages of Real-Time Kernels <ul><ul><li>Extra cost of the kernel at Software </li></ul></ul><ul><ul><li>More ROM/RAM </li></ul></ul>
  33. 33. <ul><li>In addition to basic scheduling and context switching, a real-time kernel typically provides other valuable services to applications such as: </li></ul><ul><li>Time Delays </li></ul><ul><li>System Time </li></ul><ul><li>Inter-Process Communication (IPC) </li></ul><ul><li>Synchronization </li></ul>

×