1 / 49

ECE 424 Embedded Systems Design

ECE 424 Embedded Systems Design. Operating System Overview Chapter 7 Ning Weng. Operating System. Abstractions Uninterrupted Computation: No Interrupts Infinite Memory : just an illusion. Simple I/O: Avoid dealing directly with devices (simple writes/reads). Uninterrupted computation.

giza
Download Presentation

ECE 424 Embedded Systems Design

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. ECE 424 Embedded Systems Design Operating System Overview Chapter 7 NingWeng

  2. Operating System • Abstractions • Uninterrupted Computation: No Interrupts • Infinite Memory: just an illusion. • Simple I/O: Avoid dealing directly withdevices (simple writes/reads)

  3. Uninterrupted computation • Underlying mechanisms • Context switching • Scheduling • Protection • Flavors of “process” - increasing complexity • Interrupt handlers, threads, processes

  4. Infinite memory via virtual memory • Via virtual memory • Page mapping (avoids finding contiguous locations). • Demand paging (use more space than memory) • Slow DRAM lookup avoided with fast TLB • Protection by allowing only OS to modify page tables.

  5. Simple I/O using system calls • For abstraction alone, I/O could be libraries. • For security, I/O handled by device drivers. • System calls, trap to kernel protection levels. • More expensive function call, because of privilege escalation.

  6. Four Types of Operating Systems • Single-user, single task - Designed to manage the computer so that one user can effectively do one thing at a time. Ex: Apple iPhone • Single-user, multi-tasking - Type of operating system most use on desktop and laptop computers today. Windows 7 and the MacOSX are examples of OS that let a single user have several programs in operation at the same time. • Multi-user - Allows many users to obtain the computer's resources simultaneously. OS must make sure that each program being used has sufficient and separate resources so that a problem with one user doesn't affect the other users. Ex: Unix • Real-time operating system (RTOS) - Main task is to manage computer’s resources so a particular operation executes in precisely the same amount of time every time it occurs.

  7. Embedded Operating Systems Characteristics • Designed to perform a dedicated function • Real-Time Operating Systems (RTOS) • Examples: • iOS, Android, Blackberry OS • VxWorks (Boeing 787 Dreamliner and many spacecraft)

  8. Service Calls ECE 424

  9. Service Call Design Patterns ECE 424

  10. Tasks & Threads & Process ECE 424

  11. RTOS States Transitions ECE 424

  12. Nonpreemptive FIFO Scheduling ECE 424

  13. RR Scheduler with Priority & Preemption ECE 424

  14. Memory Allocation • Malloc() and Free() • Allocates and frees memory from system heap to an application, respectively • Problem with the allocation system: • Forgets sequence of memory and free allocations • Can cause fragmentation (small contiguous section + lots of free memory) • Solution: • Allocator algorithm • Maximize size of contiguous blocks over time

  15. Fragmentation Example

  16. Fragmented Heap ECE 424

  17. Power of two heap ECE 424

  18. Virtual Memory • Memory Management Unit (MMU) manages translation between code, data, and heap process memory to physical memory • Virtual addresses are unique to accessing process • Physical addresses are unique to the hardware (i.e. ram)

  19. Address Space Mapping ECE 424

  20. Freeing and Swapping Memory • Freeing Memory • Memory allocated by a task may not be automatically freed upon deletion of that task • Must keep track of all allocated memory • Swapping Memory • Utilized in Linux to allocate more virtual memory to applications than the total amount of physical memory • Rarely used in embedded systems • Additional wear on system (normally based on solid-state drives)

  21. Clocks and Timers • Synchronous Execution • Used to specify timeouts • Sleep() and yield() are also used to delay execution • If time is long enough, task is de-scheduled and moved to ready queue • Asynchronous Execution • Callback functions – Indicates that a timeout has occurred to other threads • Callbacks with expiry time less than or equal to current time count are called • Can release semaphores • Often called because of timer interrupt • Interrupt – mechanism used to inform CPU that an asynchronous event has occurred

  22. Time of Today • Time source • Real time Clock • Hardware timer backup with battery • CPU when it is running • Seed source • RTC • NTP (network time protocol) • Cellular radio network ECE 424

  23. Mutual Exclusion/Synchronization • Goal: to serialized atomic access to share resources ECE 424

  24. Difficulties of Concurrency • Sharing of global resources • Writing a shared variable: the order of writes is important • Incomplete writes a major problem • Optimally managing the allocation of resources • Difficult to locate programming errors as results are not deterministic and reproducible.

  25. A Simple Example void echo() { chin = getchar(); chout = chin; putchar(chout); }

  26. A Simple Example: On a Multiprocessor Process P1 Process P2 . . chin = getchar(); . . chin = getchar(); chout = chin; chout = chin; putchar(chout); . . putchar(chout); . .

  27. Competition among Processes for Resources Three main control problems: • Need for Mutual Exclusion • Critical sections • Deadlock • Starvation

  28. Disabling Interrupts • Uniprocessors only allow interleaving • Interrupt Disabling • A process runs until it invokes an operating system service or until it is interrupted • Disabling interrupts guarantees mutual exclusion • Will not work in multiprocessor architecture

  29. Pseudo-Code while (true) { /* disable interrupts */; /* critical section */; /* enable interrupts */; /* remainder */; }

  30. Special MachineInstructions • Compare&Swap Instruction • also called a “compare and exchange instruction” • Exchange Instruction

  31. Compare&Swap Instruction int compare_and_swap (int *word, int testval, int newval) { int oldval; oldval = *word; if (oldval == testval) *word = newval; return oldval; }

  32. Semaphore • Semaphore: • An integer value used for signalling among processes. • Only three operations may be performed on a semaphore, all of which are atomic: • initialize, • Decrement (semWait) • increment. (semSignal)

  33. OS Required Semaphore ECE 424

  34. Semaphore • Binary • Couting ECE 424

  35. Execution Environment • Program • Libraries • Kernel subsystems • Hardware

  36. Device Driver • The driver controls the hardware and provides an abstract interface to its capabilities. • The driver ideally imposes no restrictions (or policy) on how the hardware should be used by applications. • Scatter gather list: • a mechanism defined and supported by OS to represent a list of data is not physically contiguous. ECE 424

  37. Service, Driver and Device ECE 424

  38. Scatter Gather Structures ECE 424

  39. Direct Memory Access (DMA) • What, why and how/ ECE 424

  40. Transmit Descriptor Ring ECE 424

  41. Network Stack and Device Driver ECE 424

  42. Storage File System • present logical (abstract) view of files and directories • hide complexity of hardware devices • facilitate efficient use of storage devices • optimize access, e.g., to disk • support sharing • provide protection ECE 424

  43. Files Open and Read ECE 424

  44. Synchronization File System • File write is asynchronous • Write call function does not block • Data may not have been in disk • Consolidating and scheduling writing requests for performance • Synchronization is required before • Shut down, restart or disk removal • Example: Stop a USB disk (safe remove) • Two challenges of power interactions • Un-notified power removal • Large capacitor and sensing circuits • Brownout • Voltage drop ECE 424

  45. Brownout Events ECE 424

  46. Real Time ECE 424

  47. Real Time • Real time: required to complete its task on time • Usually have deterministic time bound • Hard or soft • Features of RTOS • Scheduling, resource allocation, interrupt handing and etc • Example, VxWorks ECE 424

  48. In a Hard RTOS • Thread priorities can be set by the client • Threads always run according to priority • Kernel must be preemptible or bounded • Interrupts must be bounded • No virtual memory

  49. In a Soft RTOS… • Like a hard RTOS: • Priority scheduling, with no degradation • Low dispatch latency • Preemptible system calls • No virtual memory (or allow pages to be locked) • Linux: guarantees about relative timing of tasks, no guarantees about syscalls

More Related