SLIDE 1
Memory and Interrupts Memory Management Exception/Interrupt - - PowerPoint PPT Presentation
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
SLIDE 2
SLIDE 3
Classical Approaches
Paging & Swapping ■ break virtual memory in eqally sized pages
3
■ 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
SLIDE 4
MMChallenges in Embedded & RT Systems
■ missing HW support (MMU, TLB) ■ small memories
4
■ 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
SLIDE 5
Virtual Memory Locking
■ swapping destroys hard realtime behavior ■ should be turned off for realtime applications
5
■ should be turned off for realtime applications ■ POSIX: □ mlock(), mlockall() ■ Windows: □ VirtualLock() □ VirtualLock()
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 6
RealTime Memory Management
■ requirements: □ minimal overhead
6
□ minimal overhead □ minimal fragmentation □ predictable behavior ◊ no swapping ◊ deterministic (timely bounded) allocation / deallocation of memory
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 7
Fragmentation
■ internal Fragmentation □ application gets more memory than requested because of
7
□ application gets more memory than requested because of fixed block sizes ■ external Fragmentation □ noncontiguous free space: free blocks split across memory □ none may be able to satisfy memory request
Memory and Interrupts | Matthias Richly | 19. Mai 2010
external internal
SLIDE 8
Static vs. Dynamic Memory Allocation
static ■ segmentation
8
■ 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
SLIDE 9
Linked List / Bitmap
Linked List
9
■ “firstfit”, “bestfit”, “worstfit” Bitmap
list head memory blocks
Bitmap ■ both ■ recombination?
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 10
Static Allocation Array
■ integer array with special : find neighboring blocks easier □ +x placed in first and last entry x blocks
10
□ +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
SLIDE 11
Static Allocation Array – Merging Free Blocks
■ blocks in front can be merged, if positive number in array at indexofcurrentblock 1
11
indexofcurrentblock 1 ■ blocks behind can be merged, if positive number in array at index
- fcurrentblock + numberofblocks
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 12
Fixedsize MM with Segregated Free Lists
■ memory pools with fixed size blocks ■ block sizes and number of blocks per size statically assigned
12
■ block sizes and number of blocks per size statically assigned ■ no external fragmentation, internal fragmentation depends ■
list heads
32 56
memory blocks
■ only useful for applications with wellknown memory needs □ networking code, protocol stacks
Memory and Interrupts | Matthias Richly | 19. Mai 2010
128
SLIDE 13
Buddy systems
■ block sizes are powers of 2 (binary buddy) ■ block sizes 2min 2max
13
■ block sizes 2 2 ■ (maxmin) lists for free blocks ■ at beginning one block of size 2max ■ on memory request for size s, s ≤ 2max
- 1. calculate smallest k > min, such that 2k ≥ s, i.e. k = log2 s
- 2. look for smallest free jblock, j ≥ k
- 3. while j > k, split jblock two blocks of size j=(j1) 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
SLIDE 14
Buddy systems Example
14 Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 15
Questions so far?
15
MM end.
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 16
Exceptions and Interrupts
- ■ event, which disrupts the normal execution of the processor
16
■ 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
SLIDE 17
Programmable Interrupt Controller (PIC)
■ typically multiple sources of interrupts ■ PIC is a HW device
17
■ PIC is a HW device □ prioritizes the sources □ presents highest priority interrupt to core CPU
Interrupt HIGH MED Memory and Interrupts | Matthias Richly | 19. Mai 2010 Interrupt MED LOW Interrupt request line ISR
Interrupt Vector
SLIDE 18
Interrupt Processing
■ CPU checks for pending interrupts at the beginning of every instruction
18
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
SLIDE 19
Nested Interrupts
■ allow preemption of ISRs by higherpriority interrupts ■ ISRs need to preemptable
19
■ 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
SLIDE 20
Interrupt Latency
■ delay between interrupt raising and beginning of the ISRs execution
20
execution ■ must be bounded in RT systems
interrupt request latency processing time time
ISR
response time
■ sources: □ HW latency □ completion of running instruction □ handling of higher priority interrupts □ context saving
Memory and Interrupts | Matthias Richly | 19. Mai 2010
SLIDE 21
Hints
■ interrupt processing affects RT behavior ■ ISRs run at higher priority than all OS tasks
21
■ ISRs run at higher priority than all OS tasks ■ ISRs should be short □ reenable 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
SLIDE 22
References
RealTime Concepts for Embedded Systems. Qing Li, C. Yao. CMP Books
22
Books Memory Management for Embedded Systems. A. Polze, A. Rasche,
- B. Rabe. Betriebssysteme für Embedded Computing WT 07/08