memory and interrupts
play

Memory and Interrupts Memory Management Exception/Interrupt - PowerPoint PPT Presentation

Memory and Interrupts Memory Management Exception/Interrupt Handling Outline 2 RealTime & Embedded Memory Management Retro: Classical Approaches Retro: Classical Approaches


  1. Memory and Interrupts Memory Management Exception/Interrupt Handling ���������������

  2. Outline 2 ■ Real�Time & Embedded Memory Management □ Retro: Classical Approaches □ Retro: Classical Approaches □ Challenges & Requirements □ Dynamic Allocation Algorithms ■ Exceptions and Interrupts □ Programmable Interrupt Controller □ Interrupt Processing □ Interrupt Processing □ Interrupt Nesting Memory and Interrupts | Matthias Richly | 19. Mai 2010

  3. Classical Approaches 3 Paging & Swapping ■ break virtual memory in eqally sized pages ■ break virtual memory in eqally sized pages ■ break physical memory in frames of the same size ■ map logical adresses to physical by mapping pages to frames ■ mapping done by HW (MMU) ■ pages may be swapped to disk; brought back into main memory, when needed Memory and Interrupts | Matthias Richly | 19. Mai 2010

  4. MM�Challenges in Embedded & RT Systems 4 ■ missing HW support (MMU, TLB) ■ small memories ■ small memories ■ missing secondary storage ■ swapping pages from disc into memory in case of a page fault takes much longer than usual memory access □ unpredictable ■ garbage collection? ■ garbage collection? □ RT Java … Memory and Interrupts | Matthias Richly | 19. Mai 2010

  5. Virtual Memory Locking 5 ■ swapping destroys hard real�time behavior ■ should be turned off for real�time applications ■ should be turned off for real�time applications ■ POSIX: □ mlock(), mlockall() ■ Windows: □ VirtualLock() □ VirtualLock() Memory and Interrupts | Matthias Richly | 19. Mai 2010

  6. Real�Time Memory Management 6 ■ requirements: □ minimal overhead □ minimal overhead □ minimal fragmentation □ predictable behavior ◊ no swapping ◊ deterministic (timely bounded) allocation / deallocation of memory Memory and Interrupts | Matthias Richly | 19. Mai 2010

  7. Fragmentation 7 ■ internal Fragmentation □ application gets more memory than requested because of □ application gets more memory than requested because of fixed block sizes ■ external Fragmentation □ non�contiguous free space: free blocks split across memory □ none may be able to satisfy memory request internal external Memory and Interrupts | Matthias Richly | 19. Mai 2010

  8. Static vs. Dynamic Memory Allocation 8 static ■ segmentation ■ segmentation ■ fixed memory region for each task ■ predictable, but inflexible dynamic ■ memory allocation at runtime from global heap ■ allocator keeps track of used and free memory ■ allocator keeps track of used and free memory □ linked lists, bitmaps, static allocation array, segregated lists, buddy systems ■ difficult to design predictable ■ creates fragmentation � compaction / recombination of free blocks required Memory and Interrupts | Matthias Richly | 19. Mai 2010

  9. Linked List / Bitmap 9 Linked List memory list blocks head ■ “first�fit”, “best�fit”, “worst�fit” Bitmap Bitmap ■ both ���� ■ recombination? Memory and Interrupts | Matthias Richly | 19. Mai 2010

  10. Static Allocation Array 10 ■ integer array with special �������� : find neighboring blocks easier □ +x placed in first and last entry � x ���� blocks □ +x placed in first and last entry � x ���� blocks □ �x in first and 0 in last entry � x ��������� blocks ■ no. of array entries = no. of fixed size memory blocks ■ speed up search for free blocks by using a heap structure Memory and Interrupts | Matthias Richly | 19. Mai 2010

  11. Static Allocation Array – Merging Free Blocks 11 ■ blocks in front can be merged, if positive number in array at index�of�current�block � 1 index�of�current�block � 1 ■ blocks behind can be merged, if positive number in array at index� of�current�block + number�of�blocks Memory and Interrupts | Matthias Richly | 19. Mai 2010

  12. Fixed�size MM with Segregated Free Lists 12 ■ memory pools with fixed size blocks ■ block sizes and number of blocks per size statically assigned ■ block sizes and number of blocks per size statically assigned ■ no external fragmentation, internal fragmentation depends ■ ���� 32 list memory 56 heads blocks 128 ■ only useful for applications with well�known memory needs □ networking code, protocol stacks Memory and Interrupts | Matthias Richly | 19. Mai 2010

  13. Buddy systems 13 ■ block sizes are powers of 2 (binary buddy) ■ block sizes 2 min � 2 max ■ block sizes 2 � 2 ■ (max�min) lists for free blocks ■ at beginning one block of size 2 max ■ on memory request for size s, s ≤ 2 max 1. calculate smallest k > min, such that 2 k ≥ s, i.e. k =  log 2 s  2. look for smallest free j�block, j ≥ k 3. while j > k, split j�block � two blocks of size j=(j�1) arise, so called ������� called ������� 4. now j = k � return block ■ on deallocation, join buddies to get larger free blocks ■ ��������� ■ but high degree of fragmentation (internal & external) Memory and Interrupts | Matthias Richly | 19. Mai 2010

  14. Buddy systems � Example 14 Memory and Interrupts | Matthias Richly | 19. Mai 2010

  15. Questions so far? 15 MM end. Memory and Interrupts | Matthias Richly | 19. Mai 2010

  16. Exceptions and Interrupts 16 ��������� ■ event, which disrupts the normal execution of the processor ■ event, which disrupts the normal execution of the processor ■ forces execution of special instructions in a privileged state ■ synchronous vs. asynchronous ��������� ■ asynchronous exception triggered by an external HW device ■ � a means to communicate between HW and application ■ � a means to communicate between HW and application ■ maskable Memory and Interrupts | Matthias Richly | 19. Mai 2010

  17. Programmable Interrupt Controller (PIC) 17 ■ typically multiple sources of interrupts ■ PIC is a HW device ■ PIC is a HW device □ prioritizes the sources □ presents highest priority interrupt to core CPU HIGH MED MED Interrupt Interrupt Interrupt ISR Vector LOW Interrupt request line Memory and Interrupts | Matthias Richly | 19. Mai 2010

  18. Interrupt Processing 18 ■ CPU checks for pending interrupts at the beginning of every instruction instruction ■ if interrupt was raised: □ save current processor state (PC, …) □ set PC to ISR address (calculated from interrupt vector) □ execute ISR ◊ mask other interrupts ◊ perform required operations on the device ◊ execute interrupt return instruction (iret) □ restore state and resume previous execution Memory and Interrupts | Matthias Richly | 19. Mai 2010

  19. Nested Interrupts 19 ■ allow preemption of ISRs by higher�priority interrupts ■ ISRs need to preemptable ■ ISRs need to preemptable ■ reentrant ISRs ■ challenge: prevent stack overflows □ increase the tasks’ stack space □ better: use own stack for ISRs Memory and Interrupts | Matthias Richly | 19. Mai 2010

  20. Interrupt Latency 20 ■ delay between interrupt raising and beginning of the ISRs execution execution ■ must be bounded in RT systems response time ISR time interrupt processing time latency request ■ sources: □ HW latency □ completion of running instruction □ handling of higher priority interrupts □ context saving Memory and Interrupts | Matthias Richly | 19. Mai 2010

  21. Hints 21 ■ interrupt processing affects RT behavior ■ ISRs run at higher priority than all OS tasks ■ ISRs run at higher priority than all OS tasks ■ ISRs should be short □ re�enable interrupts as fast as possible □ consider deferring parts of the processing to some OS task(s) ■ don’t use blocking calls in ISRs Memory and Interrupts | Matthias Richly | 19. Mai 2010

  22. References 22 � Real�Time Concepts for Embedded Systems. Qing Li, C. Yao. CMP Books Books � Memory Management for Embedded Systems. A. Polze, A. Rasche, B. Rabe. Betriebssysteme für Embedded Computing WT 07/08 � Interrupts and Exceptions. A. Polze, A. Rasche, B. Rabe. Betriebssysteme für Embedded Computing WT 07/08 � The Art of Computer Programming. Volume 1: Fundamental Algorithms, Second Edition. Knuth, D.E. Addison�Wesley, pp. 442� 445. 445. Memory and Interrupts | Matthias Richly | 19. Mai 2010

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend