1 / 676

Fundamentals of Embedded Operating Systems

Fundamentals of Embedded Operating Systems. Operating System. Exploits the hardware resources of one or more processors Provides a set of services to system users Manages memory (primary and secondary) and I/O devices. Foreground/Background Systems .

jalila
Download Presentation

Fundamentals of Embedded Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals of Embedded Operating Systems

  2. Operating System • Exploits the hardware resources of one or more processors • Provides a set of services to system users • Manages memory (primary and secondary) and I/O devices

  3. Foreground/Background Systems • Small, simple systems usually don't have an OS • Instead, an application consists of an infinite loop that calls modules (functions) to perform various actions in the “Background”. • Interrupt Service Routines (ISRs) handle asynchronous events in the “Foreground”

  4. Foreground/Background System while loop “Foreground” ISR ISR ISR Code Execution time “Background”

  5. Why Embedded Operating System? • For complex applications with a multitude of functionality • mechanisms are required to implement each functionality independent of the others, but still make them work co-operatively

  6. Embedded systems need Multitasking • Multitasking - The ability to execute more than one task or program at the same time • CPU switches from one program to another so quickly that it gives the appearance of executing all of the programs at the same time.

  7. Example Multitasking Telephone Answering Machine Operating the user’s control panel User has picked up receiver Recording a phone call

  8. Nature of Multitasking • Cooperative multitasking -each program can control the CPU for as long as it needs it. It allows other programs to use it at times when it does not use the CPU • Preemptive multitasking - Operating system parcels out CPU time slices to each program

  9. Complexities of multitasking • Multi-rate tasks • Periodic tasks • Concurrent tasks • Synchronous and asynchronous tasks

  10. EXAMPLE: Complex Timing Requirements of a compression unit Uncompressed Data Compressed Data Compressor Compression Table Character Bit Queue

  11. Cooperating Tasks • Data may be received and sent at different rates - example one byte may be compressed to 2 bits while another may be compressed to 6 bits • Data should be stored in input and output queues to be read in a specific order • Time for packaging and emitting output characters should not be so high that input characters are lost

  12. Fundamentals

  13. How a System works • Wake Up Call -On Power_ON • Execute BIOS - instructions kept in Flash Memory - type of read-only memory (ROM) examines system hardware • Power-on self test (POST) checks the CPU, memory and basic input-output systems (BIOS) for errors and stores the result in a special memory location

  14. Processing Sequence Power Up BSP/OS Initialization Decompression /Bootloading Application code begins Hardware Init

  15. Board Support Package • BSP is a component that provides board/hardware-specific details to OS for the OS to provide hardware-abstractions to the tasks that use its services • BSP is specific to both the board and the OS for which it is written

  16. BSP startup code • Initializes processor • Sets various parameters required by processor for • Memory initialization • Clock setup • Setting up various components like cache • BSP also contains drivers for peripherals

  17. Kernel • Most frequently used portion of OS • Resides permanently in main memory • Runs in privileged mode • Responds to calls from processes and interrupts from devices

  18. Kernel’s responsibility • Managing Processes • Context switching: alternating between the different processes or tasks • Scheduling: deciding which task/process to run next • Various scheduling algorithms • Critical sections = providing adequate memory-protection when multiple tasks/processes run concurrently • Various solutions to dealing with critical sections

  19. Process • A process is a unique sequential execution of a program • Execution context of the program • All information the operating system needs to manage the process • Process Characteristics • Period - Time between successive executions • Rate - Inverse of Period • In a multi-rate system each process executes at its own rate

  20. Process Control Block (PCB) • Process Control Block • OS structure which holds the pieces of information associated with a process • Process state: new, ready, running, waited, halted, etc. • Program counter: contents of the PC • CPU registers: contents of the CPU registers • CPU scheduling information: information on priority and scheduling parameters

  21. PCB • Memory­management information: Pointers to page or segment tables • Accounting information: CPU and real time used, time limits, etc. • I/O status information: which I/O devices (if any) this process has allocated to it, list of open files, etc.

  22. Process states Executing Obtains data, allocated CPU scheduled Needs data Preempted Received data Ready Waiting Needs data

  23. Multithreading • Operating system supports multiple threads of execution within a single process • An executing process is divided into threads that run concurrently • Thread – a dispatchable unit of work

  24. Multi-threaded Process Model

  25. Threads in Embedded Applications • Lightweight processes are ideal for embedded computing systems since these platforms typically run only a few programs • Concurrency within programs better managed using threads

  26. Context Switch • The CPU’s replacement of the currently running task with a new one is called a “context switch” • Simply saves the old context and “restores” the new one • Actions: • Current task is interrupted • Processor’s registers for that particular task are saved in a task-specific table • Task is placed on the “ready” list to await the next time-slice

  27. Context switch • Actions (more) • Task control block stores memory usage, priority level, etc. • New task’s registers and status are loaded into the processor • New task starts to run • Involves changing the stack pointer, the PC and the PSR (program status register)

  28. ARM instructions: Saving the context STMIA r13, {r0-r14}^ ; save all user registers in space pointed to by r13 in ascending order MRS r0, SPSR ; get status register and put it in r0 STMDB r13, {r0, r15} ; save status register and PC into context block

  29. ARM Instructions: Loading a new process ADR r0, NEWPROC ; get address for pointer LDR r13, [r0]; Load next context block in r13 LDMDB r13, {r0, r14}; Get status register and PC MSR SPSR, r0; Set status register LDMIA r13, {r0-r14}^; Get the registers MOVS pc, r14; Restore status register

  30. Context switches When A Context-Switch Occur? • Time-slicing • Time-slice: period of time a task can run before a context-switch can replace it • Driven by periodic hardware interrupts from the system timer • During a clock interrupt, the kernel’s scheduler can determine if another process should run and perform a context-switch • However, this doesn’t mean that there is a context-switch at every time-slice!

  31. Pre-emption • Preemption • Currently running task can be halted and switched out by a higher-priority active task • No need to wait until the end of the time-slice

  32. Context Switch Overhead • Frequency of context switch depends upon application • Overhead for Processor context-switch is the amount of time required for the CPU to save the current task’s context and restore the next task’s context • Overhead for System context-switch is the amount of time from the point that the task was ready for context-switching to when it was actually swapped in

  33. Context switch overhead • How long does a system context-switch take? • System context-switch time is a measure of responsiveness • Time-slicing: a time-slice period + processor context-switch time • Preemption is mostly preferred because it is more responsive (system context-switch = processor context-switch)

  34. Process Scheduling • What is the scheduler? • Part of the operating system that decides which process/task to run next • Uses a scheduling algorithm that enforces some kind of policy that is designed to meet some criteria

  35. Scheduling • Criteria may vary • CPU utilization ­ keep the CPU as busy as possible • Throughput ­ maximize the number of processes completed per time unit • Turnaround time ­ minimize a process’ latency (run time), i.e., time between task submission and termination • Response time ­ minimize the wait time for interactive processes • Real-time ­ must meet specific deadlines to prevent “bad things” from happening

  36. Scheduling Policies • First­come, first­served (FCFS) • The first task that arrives at the request queue is executed first, the second task is executed second and so on • FCFS can make the wait time for a process very long • Shortest Job First: Schedule processes according to their run-times • Generally difficult to know the run-time of a process

  37. Priority Scheduling • Shortest­Job­First is a special case of priority scheduling • Priority scheduling assigns a priority to each process. Those with higher priorities are run first.

  38. Real Time Scheduling

  39. Characteristics of Real-Time Systems • Event-driven, reactive. • High cost of failure. • Concurrency/multiprogramming. • Stand-alone/continuous operation. • Reliability/fault-tolerance requirements. • Predictable behavior.

  40. Example Real-Time Applications Many real-time systems are control systems. Example 1: A simple one-sensor, one-actuator control system. rk reference input r(t) A/D uk control-law computation D/A yk A/D y(t) u(t) sensor actuator plant The system being controlled

  41. Simple Control System Basic Operation set timer to interrupt periodically with period T; at each timer interrupt do do analog-to-digital conversion to get y; compute control output u; output u and do digital-to-analog conversion; end do T is called the sampling period. T is a key design choice. Typical range for T: seconds to milliseconds.

  42. Multi-rate Control Systems • More complicated control systems have multiple sensors and actuators and must support control loops of different rates. Example:Helicopter flight controller Do the following in each 1/180-sec. cycle: validate sensor data and select data source; if failure, reconfigure the system

  43. Helicopter Controller Every sixth cycle do: keyboard input and mode selection; data normalization and coordinate transformation; tracking reference update control laws of the outer pitch-control loop; control laws of the outer roll-control loop; control laws of the outer yaw- and collective-control loop

  44. Air traffic-flight control hierarchy. Hierarchical Control Systems sampling rates may be minutes or even hours commands responses operator-system interface  state estimator air traffic control from sensors virtual plant navigation  flight management state estimator virtual plant  flight control state estimator sampling rates may be secs. or msecs. air data physical plant

  45. Signal-Processing Systems Signal-processing systems transform data from one form to another. • Examples: • Digital filtering. • Video and voice compression/decompression. • Radar signal processing. • Response times range from a few milliseconds to a few seconds.

  46. Example: Radar System DSP radar memory DSP sampled digitized data DSP signal processors track records track records data processor control status signal processing parameters

  47. Other Real-Time Applications • Real-time databases. • Transactions must complete by deadlines. • Main dilemma: Transaction scheduling algorithms and real-time scheduling algorithms often have conflicting goals. • Data may be subject to absolute and relative temporal consistency requirements. • Multimedia. • Want to process audio and video frames at steady rates. • TV video rate is 30 frames/sec. HDTV is 60 frames/sec. • Telephone audio is 16 Kbits/sec. CD audio is 128 Kbits/sec. • Other requirements: Lip synchronization, low jitter, low end-to-end response times (if interactive).

  48. Are All Systems Real-Time Systems? • Question: Is a payroll processing system a real-time system? • It has a time constraint: Print the pay checks every two weeks. • Perhaps it is a real-time system in a definitional sense, but it doesn’t pay us to view it as such. • We are interested in systems for which it is not a priori obvious how to meet timing constraints.

  49. The “Window of Scarcity” • Resources may be categorized as: • Abundant: Virtually any system design methodology can be used to realize the timing requirements of the application. • Insufficient: The application is ahead of the technology curve; no design methodology can be used to realize the timing requirements of the application. • Sufficient but scarce: It is possible to realize the timing requirements of the application, but careful resource allocation is required.

  50. Example: Interactive/Multimedia Applications Requirements (performance, scale) The interesting real-time applications are here sufficient but scarce resources insufficient resources Interactive Video High-quality Audio Network File Access abundant resources Remote Login 2000 1990 1980 Hardware resources in year X

More Related