mC Memory ManagementProblemBuffer DimensioningBuffer Dimensioning: Little’LawBuffer Dimensioning: Little’Law (2)Dynamic Memory ManagementMemory Initialization (OS_MemInit)Memory Initialization (OS_MemInit) (2)Creating a Memory Partition (1) OS_MEM *OSMemCreate(void *addr, INT32U nblks, INT32U blksize INT8U *err)Creating a Memory Partition (2) OS_MEM *OSMemCreate(void *addr, INT32U nblks, INT32U blksize INT8U *err)Tasks Sharing a Pool of BlocksmC Memory ManagementC Memory ManagementRead Chapter 12 (uC Textbook)Read Chapter 7 (Simon Textbook)01/14/19MicroC Memeory management Saad Biaz 2Problem•Embedded systems must handle random events•Randomness creates queues! need memory buffersData InputError messages01/14/19MicroC Memeory management Saad Biaz 3Buffer Dimensioning•Consider the telegraph system:–Receives packets on Ethernet network–Output packets to printer –What should be the size of the output buffer?–What do (can) I know?•Maximal (average) arrival rate of “requests”: •Maximum (average) time to serve requests: Data Input?01/14/19MicroC Memeory management Saad Biaz 4Buffer Dimensioning: Little’Law•Little’s Law: The average number of “requests” N in the system is–N = where is the averages arrival rate and the average time in the system.•Example 1:–An http server gets 50 requests per second–Each request takes on average 15 ms to be served–What should be the size of the http request buffer?Data Input?01/14/19MicroC Memeory management Saad Biaz 5Buffer Dimensioning: Little’Law (2)•Example 2:–An http server gets 50 requests per second–Each request takes on average 25 ms to be served–What should be the size of the http request buffer?•Example 3: same as example 1, but this time the http uses round robin as a scheduling service policy.Data Input?01/14/19MicroC Memeory management Saad Biaz 6Dynamic Memory Management•Two options:–Language tools: malloc, calloc, free ..–RTOS tools: specific functions with time upperbounds (deterministic execution)•Language tools cannot be used for time critical applications01/14/19MicroC Memeory management Saad Biaz 7Memory Initialization (OS_MemInit)•Create a linked list of memory control blocks of “candidate” partitions.OSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeMemory Control Block01/14/19MicroC Memeory management Saad Biaz 8Memory Initialization (OS_MemInit) (2)•Create a linked list of memory control blocks of “candidate” partitions.OSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeNullOSMemFreeList01/14/19MicroC Memeory management Saad Biaz 9Creating a Memory Partition (1)OS_MEM *OSMemCreate(void *addr, INT32U nblks, INT32U blksize INT8U *err)addrOSMemFreeListblkSizenblksnblksOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeOSMemFreeListaddrnblksOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFree01/14/19MicroC Memeory management Saad Biaz 10Creating a Memory Partition (2)OS_MEM *OSMemCreate(void *addr, INT32U nblks, INT32U blksize INT8U *err)addrOSMemFreeListblkSizenblksnblksOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeOSMemFreeListaddrnblksOSMemAddrOSMemFreeListOSMemBlkSizeOSMemBlksOSMemFreeNull01/14/19MicroC Memeory management Saad Biaz 11Tasks Sharing a Pool of Blocks•What if the memory gets exhausted?–Return that memory is not available. Task gets into loop (busy waiting). Can we do better?–Associate a counting semaphore to a partition. Initialize semaphore to the number of available blocks01/14/19MicroC Memeory management Saad Biaz 12C Memory Management •Allocation/Freeing of memory blocks made in CONSTANT time. •No protection mechanism:–No control when partition is set up: •you could map a memory control block to the desert•You could map a memory control block to a memory area used by another partition–No control when block put back ():•A block could be returned to another partition•A block could be returned to multiple
View Full Document