# Advanced Operating Systems and Embedded Systems - lesson 3 #### William Fornaciari ###### 11 October 2016 ## Real Time Operating Systems ### Real time system Is a system which has to provide a result within a time range usually before a *deadline* #### Classification - __mission critical systems__ - tipycally involves safety - static allocation of resources - __soft real time__: Best effort performance, if the system underperforms, nobody dies but we have a loss of quality In a system like windows OS, a general delay from an event like mouse movement and the reaction takes 200ms, while is a __RTOS__ this time needs to be under 10ms. #### Charachteristics required for a RTOS - __Deterministic behaviour__: operations are executed ad predetermined times or intervals - __Responsiveness__: involves minimum interrupt latency, and is due to the fact that usually RTOS systems are part of control loops, and the speed of the control system needs to be some tipically 5 times the speed of the system. Measures to guarantee fast ISR time include: - Inhibiting nested routines - Calling ISR without context switching - __User control__: User should have a much more specific control on applications w.r.t. ordinary OS - __Reliability__: The worst case is to have a blue screen where everything stops. A much less worse case is to have a graceful degradation of the performances, an example is the thermal throttling of the CPUs when overheating. For example in the case of a washing machine, in case of a power loss we have 30-100ms before the capacitors discharge, to save the content of RAM to a permanent memory. This behaviour is called __fail-soft__ and consists of preserving as much data ad possible in case of failure. #### RTOS Features - Low cost, small size: usually they employ open-source code. - ~20 tasks usually required for an embedded project. - Use of *semaphors* for fast access protection. - A general paradigm for fast access is *shared memory* protected by *semaphors* - For choosing __schedulers__ predictability is preferred over complexity, because of this generally used schedulers are *FIFO* or *round robin* #### Time Constraints The "ready" event (process woke up for receiving data) may be: - __periodic__: for example sampling at fixed rate, ex: 100Hz - __aperiodic__ but predictable The computation time may be: - Fixed in duration - Variable - Unpredictable: for example human activity with a computer is unpredictable. #### Deadlines - __hard__: the computation must be completed within the limit or there will be a __critical error__ - __soft__: the deadline is expressed as a preference, but is not critical. The *criticality* of a Deadline can be expressed by means of a __Value Function__ #### Preemption Makes possible to suspend a process when another task needs to be executed and and restore the work later. Different tipes of computation can be *preemptable* or not or, only preemptable in a specific part of their execution Keeping the system in a safe state is costly, a better tradeoff could be keeping the system in a safe state only for portions of the time. #### Schedulability analisys consist in deciding to accept or not a new process to guarantee the safely conclusion of the existing processes. Can be carried out: - statically: at bootstrap time - dinamically: when the process is created __Static table driven__ sched. an. is suitable only for mature systems when the execution of the processes is known from the project. A famous example is the __Rate Monotonic__ analisys __Dynamic planning based__: feasibility is determined at runtime ### Design Issues A key problem is choosing the process to be __executed next__ Sometimes using a non-preemptive scheduler makes sense because this way you can not take away the resources that you have allocated.