CS 452/652 Fall 2019 - Lecture 7
September 18, 2019
prev next
Memory Management
- C/C++ provide very good control over memory layout of structured data
- use pointer casting to switch between unstructured and structured view
- alternative: union declaration
- ARM 920T: all relevant unstructured data is 32-bit wide, so no padding or alignment problems
- otherwise, GCC extensions could be used to increase control over memory layout
- techniques for dynamic data structures without heap
- intrusive linkage, i.e., embed next (and/or other) pointers in data strucure
- slab allocation: dedicated memory region for each relevant data type
- stored freed objects in free list, use intrusive overlay (cast/union, see above) to manage
- allocate first from free list, then from slab
- use stack or static (file-)local memory for slab
- when using static memory: do not share between tasks!
Mixing C and Assembler
Coding
See various examples file in demo07. Take a look at the compiled .s source assembler version or use objdump -d to look at the binary code.
- main.c, adder.c - basic argument passing in r0, r1
- adder6.c - beyond 4 arguments passed on stack
- main.c, asm_adder.S - manual assembler routine working with C caller
- main3.c, data_adder.c - memory-based data exchange between C and assembler
- special register access: msr/mrs for cpsr, spsr
- special register access: mcr/mrc for co-process registers cp15
- asm.c - embed assembler in C code; exchange data with local variables
Recommendations
- use embedded assembler via asm only for short code sequences that do not access sp
- use assembler routine linked as C routine for context-switch code
Kernel Start
- SVC mode, working stack, caches disabled, IRQs disabled
- set up (now, K1): UARTs, SWI handler
- set up (later): caches, timers, track, IRQs, IRQ handler
- create dedicated first user task (init task)
- start kernel loop
Scheduling
- preemption: each kernel entry triggers re-scheduling
- but: no time-sliced preemption!
- after kernel entry and corresponding processing
- task might be blocked → track
- task might be ready → back on ready queue
- but not both! single intrusive linkage element sufficient
- ready queue - keep simple: array of plain FIFO queues
- no support for timeout/cancellation of blocking operations
- no need to remove internal element from queue
- only push to back of queue, pop from front