Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 424 Embedded Systems Design Operating System Overview Chapter 7 Ning Weng.

Similar presentations

Presentation on theme: "ECE 424 Embedded Systems Design Operating System Overview Chapter 7 Ning Weng."— Presentation transcript:

1 ECE 424 Embedded Systems Design Operating System Overview Chapter 7 Ning Weng

2 Operating System Abstractions ─Uninterrupted Computation: No Interrupts ─Infinite Memory: just an illusion. ─Simple I/O: Avoid dealing directly with devices (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 Ning WengECE 4248

9 Service Call Design Patterns Ning WengECE 4249

10 Tasks & Threads & Process Ning WengECE 42410

11 RTOS States Transitions Ning WengECE 42411

12 Nonpreemptive FIFO Scheduling Ning WengECE 42412

13 RR Scheduler with Priority & Preemption Ning WengECE 42413

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 Ning WengECE 42416

17 Power of two heap Ning WengECE 42417

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 Ning WengECE 42419

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 Ning WengECE 42422

23 Mutual Exclusion/Synchronization Goal: to serialized atomic access to share resources Ning WengECE 42423

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 P1Process P2. chin = getchar();..chin = getchar();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 Machine Instructions 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 Ning WengECE 42433

34 Semaphore Binary Couting Ning WengECE 42434

35 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. Ning WengECE 42436

37 Service, Driver and Device Ning WengECE 42437

38 Scatter Gather Structures Ning WengECE 42438

39 Direct Memory Access (DMA) What, why and how/ Ning WengECE 42439

40 Transmit Descriptor Ring Ning WengECE 42440

41 Network Stack and Device Driver Ning WengECE 42441

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 Ning WengECE 42442

43 Files Open and Read Ning WengECE 42443

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 Ning WengECE 42444

45 Brownout Events Ning WengECE 42445

46 Real Time Ning WengECE 42446

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 Ning WengECE 42447

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

Download ppt "ECE 424 Embedded Systems Design Operating System Overview Chapter 7 Ning Weng."

Similar presentations

Ads by Google