Changeset 2ec725f in mainline
- Timestamp:
- 2008-07-06T18:20:02Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5f7a0ef
- Parents:
- 000350f8
- Location:
- kernel/generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/buddy.h
r000350f8 r2ec725f 67 67 /** Find parent of block that has given order */ 68 68 link_t *(* find_block)(struct buddy_system *, link_t *, uint8_t); 69 void (* print_id)(struct buddy_system *, link_t *);70 69 } buddy_system_operations_t; 71 70 … … 79 78 } buddy_system_t; 80 79 81 extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, 82 buddy_system_operations_t *op, void *data); 83 extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); 84 extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); 85 extern void buddy_system_free(buddy_system_t *b, link_t *block); 86 extern void buddy_system_structure_print(buddy_system_t *b, size_t elem_size); 87 extern size_t buddy_conf_size(int max_order); 88 extern link_t *buddy_system_alloc_block(buddy_system_t *b, link_t *block); 80 extern void buddy_system_create(buddy_system_t *, uint8_t, 81 buddy_system_operations_t *, void *); 82 extern link_t *buddy_system_alloc(buddy_system_t *, uint8_t); 83 extern bool buddy_system_can_alloc(buddy_system_t *, uint8_t); 84 extern void buddy_system_free(buddy_system_t *, link_t *); 85 extern size_t buddy_conf_size(int); 86 extern link_t *buddy_system_alloc_block(buddy_system_t *, link_t *); 89 87 90 88 #endif -
kernel/generic/src/mm/buddy.c
r000350f8 r2ec725f 36 36 * 37 37 * This file contains buddy system allocator framework. 38 * Specialized functions are needed for this abstract framework 39 * to be useful. 38 * Specialized functions are needed for this abstract framework to be useful. 40 39 */ 41 40 … … 47 46 #include <macros.h> 48 47 49 /** Return size needed for the buddy configuration data */48 /** Return size needed for the buddy configuration data. */ 50 49 size_t buddy_conf_size(int max_order) 51 50 { … … 54 53 55 54 56 /** Create buddy system 55 /** Create buddy system. 57 56 * 58 57 * Allocate memory for and initialize new buddy system. 59 58 * 60 * @param b Preallocated buddy system control data. 61 * @param max_order The biggest allocable size will be 2^max_order. 62 * @param op Operations for new buddy system. 63 * @param data Pointer to be used by implementation. 64 * 65 * @return New buddy system. 66 */ 67 void buddy_system_create(buddy_system_t *b, 68 uint8_t max_order, 69 buddy_system_operations_t *op, 70 void *data) 59 * @param b Preallocated buddy system control data. 60 * @param max_order The biggest allocable size will be 2^max_order. 61 * @param op Operations for new buddy system. 62 * @param data Pointer to be used by implementation. 63 * 64 * @return New buddy system. 65 */ 66 void 67 buddy_system_create(buddy_system_t *b, uint8_t max_order, 68 buddy_system_operations_t *op, void *data) 71 69 { 72 70 int i; … … 82 80 83 81 /* 84 * Use memory after our own structure 82 * Use memory after our own structure. 85 83 */ 86 84 b->order = (link_t *) (&b[1]); … … 94 92 } 95 93 96 /** Check if buddy system can allocate block 97 * 98 * @param b Buddy system pointer 99 * @param i Size of the block (2^i) 100 * 101 * @return True if block can be allocated 102 */ 103 bool buddy_system_can_alloc(buddy_system_t *b, uint8_t i) { 94 /** Check if buddy system can allocate block. 95 * 96 * @param b Buddy system pointer. 97 * @param i Size of the block (2^i). 98 * 99 * @return True if block can be allocated. 100 */ 101 bool buddy_system_can_alloc(buddy_system_t *b, uint8_t i) 102 { 104 103 uint8_t k; 105 104 … … 108 107 * we know immediatly that we cannot satisfy the request. 109 108 */ 110 if (i > b->max_order) return false; 109 if (i > b->max_order) 110 return false; 111 111 112 112 /* 113 113 * Check if any bigger or equal order has free elements 114 114 */ 115 for (k =i; k <= b->max_order; k++) {115 for (k = i; k <= b->max_order; k++) { 116 116 if (!list_empty(&b->order[k])) { 117 117 return true; … … 120 120 121 121 return false; 122 123 } 124 125 /** Allocate PARTICULAR block from buddy system 126 * 127 * @ return Block of data or NULL if no such block was found 122 } 123 124 /** Allocate PARTICULAR block from buddy system. 125 * 126 * @return Block of data or NULL if no such block was found. 128 127 */ 129 128 link_t *buddy_system_alloc_block(buddy_system_t *b, link_t *block) … … 136 135 list_remove(left); 137 136 while (1) { 138 if (! b->op->get_order(b,left)) {137 if (!b->op->get_order(b, left)) { 139 138 b->op->mark_busy(b, left); 140 139 return left; … … 144 143 145 144 right = b->op->bisect(b, left); 146 b->op->set_order(b, left, order -1);147 b->op->set_order(b, right, order -1);145 b->op->set_order(b, left, order - 1); 146 b->op->set_order(b, right, order - 1); 148 147 149 148 tmp = b->op->find_block(b, block, BUDDY_SYSTEM_INNER_BLOCK); … … 162 161 /** Allocate block from buddy system. 163 162 * 164 * @param b 165 * @param i 166 * 167 * @return 163 * @param b Buddy system pointer. 164 * @param i Returned block will be 2^i big. 165 * 166 * @return Block of data represented by link_t. 168 167 */ 169 168 link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i) … … 219 218 220 219 return res; 221 222 220 } 223 221 224 222 /** Return block to buddy system. 225 223 * 226 * @param b 227 * @param block 224 * @param b Buddy system pointer. 225 * @param block Block to return. 228 226 */ 229 227 void buddy_system_free(buddy_system_t *b, link_t *block) … … 269 267 270 268 /* 271 * Recursively add the coalesced block to the list of order i + 1. 269 * Recursively add the coalesced block to the list of 270 * order i + 1. 272 271 */ 273 272 buddy_system_free(b, hlp); … … 280 279 */ 281 280 list_append(block, &b->order[i]); 282 283 }284 285 /** Prints out structure of buddy system286 *287 * @param b Pointer to buddy system288 * @param elem_size Element size289 */290 void buddy_system_structure_print(buddy_system_t *b, size_t elem_size) {291 index_t i;292 count_t cnt, elem_count = 0, block_count = 0;293 link_t *cur;294 295 296 printf("Order\tBlocks\tSize \tBlock size\tElems per block\n");297 printf("-----\t------\t--------\t----------\t---------------\n");298 299 for (i = 0;i <= b->max_order; i++) {300 cnt = 0;301 if (!list_empty(&b->order[i])) {302 for (cur = b->order[i].next; cur != &b->order[i]; cur = cur->next)303 cnt++;304 }305 306 printf("#%" PRIi "\t%5" PRIc "\t%7" PRIc "K\t%8" PRIi "K\t%6u\t",307 i, cnt, SIZE2KB(cnt * (1 << i) * elem_size), SIZE2KB((1 << i) * elem_size), 1 << i);308 if (!list_empty(&b->order[i])) {309 for (cur = b->order[i].next; cur != &b->order[i]; cur = cur->next) {310 b->op->print_id(b, cur);311 printf(" ");312 }313 }314 printf("\n");315 316 block_count += cnt;317 elem_count += (1 << i) * cnt;318 }319 printf("-----\t------\t--------\t----------\t---------------\n");320 printf("Buddy system contains %" PRIc " free elements (%" PRIc " blocks)\n" , elem_count, block_count);321 281 } 322 282 -
kernel/generic/src/mm/frame.c
r000350f8 r2ec725f 319 319 } 320 320 321 static void zone_buddy_print_id(buddy_system_t *b, link_t *block)322 {323 frame_t *frame;324 zone_t *zone;325 index_t index;326 327 frame = list_get_instance(block, frame_t, buddy_link);328 zone = (zone_t *) b->data;329 index = frame_index(zone, frame);330 printf("%" PRIi, index);331 }332 333 321 /** Buddy system find_buddy implementation. 334 322 * … … 470 458 .mark_busy = zone_buddy_mark_busy, 471 459 .mark_available = zone_buddy_mark_available, 472 .find_block = zone_buddy_find_block, 473 .print_id = zone_buddy_print_id 460 .find_block = zone_buddy_find_block 474 461 }; 475 462 … … 1284 1271 ipl_t ipl; 1285 1272 unsigned int i; 1273 uintptr_t base; 1274 count_t count; 1275 count_t busy_count; 1276 count_t free_count; 1286 1277 1287 1278 ipl = interrupts_disable(); … … 1295 1286 } 1296 1287 if (!zone) { 1288 spinlock_unlock(&zones.lock); 1289 interrupts_restore(ipl); 1297 1290 printf("Zone not found.\n"); 1298 goto out;1291 return; 1299 1292 } 1300 1293 1301 1294 spinlock_lock(&zone->lock); 1302 printf("Memory zone information\n"); 1303 printf("Zone base address: %p\n", PFN2ADDR(zone->base)); 1304 printf("Zone size: %" PRIc " frames (%" PRIs " KB)\n", zone->count, 1305 SIZE2KB(FRAMES2SIZE(zone->count))); 1306 printf("Allocated space: %" PRIc " frames (%" PRIs " KB)\n", 1307 zone->busy_count, SIZE2KB(FRAMES2SIZE(zone->busy_count))); 1308 printf("Available space: %" PRIc " frames (%" PRIs " KB)\n", 1309 zone->free_count, SIZE2KB(FRAMES2SIZE(zone->free_count))); 1310 buddy_system_structure_print(zone->buddy_system, FRAME_SIZE); 1295 base = PFN2ADDR(zone->base); 1296 count = zone->count; 1297 busy_count = zone->busy_count; 1298 free_count = zone->free_count; 1311 1299 spinlock_unlock(&zone->lock); 1312 1313 out:1314 1300 spinlock_unlock(&zones.lock); 1315 1301 interrupts_restore(ipl); 1302 1303 printf("Zone base address: %p\n", base); 1304 printf("Zone size: %" PRIc " frames (%" PRIs " KiB)\n", count, 1305 SIZE2KB(FRAMES2SIZE(count))); 1306 printf("Allocated space: %" PRIc " frames (%" PRIs " KiB)\n", 1307 busy_count, SIZE2KB(FRAMES2SIZE(busy_count))); 1308 printf("Available space: %" PRIc " frames (%" PRIs " KiB)\n", 1309 free_count, SIZE2KB(FRAMES2SIZE(free_count))); 1316 1310 } 1317 1311
Note:
See TracChangeset
for help on using the changeset viewer.