Changeset 4638401 in mainline
- Timestamp:
- 2007-03-26T19:13:00Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 454f1da
- Parents:
- d5bd8d7
- Location:
- kernel/generic/src/mm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/as.c
rd5bd8d7 r4638401 412 412 413 413 if (overlaps(b, c * PAGE_SIZE, area->base, 414 pages *PAGE_SIZE)) {414 pages * PAGE_SIZE)) { 415 415 416 416 if (b + c * PAGE_SIZE <= start_free) { … … 554 554 area->backend->frame_free) { 555 555 area->backend->frame_free(area, b + 556 j * PAGE_SIZE, PTE_GET_FRAME(pte));556 j * PAGE_SIZE, PTE_GET_FRAME(pte)); 557 557 } 558 558 page_mapping_remove(as, b + j * PAGE_SIZE); -
kernel/generic/src/mm/frame.c
rd5bd8d7 r4638401 71 71 count_t refcount; /**< tracking of shared frames */ 72 72 uint8_t buddy_order; /**< buddy system block order */ 73 link_t buddy_link; /**< link to the next free block inside one order */ 73 link_t buddy_link; /**< link to the next free block inside one 74 order */ 74 75 void *parent; /**< If allocated by slab, this points there */ 75 76 } frame_t; … … 77 78 typedef struct { 78 79 SPINLOCK_DECLARE(lock); /**< this lock protects everything below */ 79 pfn_t base; /**< frame_no of the first frame in the frames array */ 80 pfn_t base; /**< frame_no of the first frame in the frames 81 array */ 80 82 count_t count; /**< Size of zone */ 81 83 82 frame_t *frames; /**< array of frame_t structures in this zone */ 84 frame_t *frames; /**< array of frame_t structures in this 85 zone */ 83 86 count_t free_count; /**< number of free frame_t structures */ 84 87 count_t busy_count; /**< number of busy frame_t structures */ … … 158 161 /* Check for overflow */ 159 162 z = zones.info[i]; 160 if (overlaps(newzone->base,newzone->count, 161 z->base,z->count)) {163 if (overlaps(newzone->base,newzone->count, z->base, 164 z->count)) { 162 165 printf("Zones overlap!\n"); 163 166 return -1; … … 167 170 } 168 171 /* Move other zones up */ 169 for (j = i; j < zones.count; j++)172 for (j = i; j < zones.count; j++) 170 173 zones.info[j + 1] = zones.info[j]; 171 174 zones.info[i] = newzone; … … 203 206 spinlock_lock(&z->lock); 204 207 if (z->base <= frame && z->base + z->count > frame) { 205 spinlock_unlock(&zones.lock); /* Unlock the global lock */ 208 /* Unlock the global lock */ 209 spinlock_unlock(&zones.lock); 206 210 if (pzone) 207 211 *pzone = i; … … 230 234 * 231 235 * @param order Size (2^order) of free space we are trying to find 232 * @param pzone Pointer to preferred zone or NULL, on return contains zone number 236 * @param pzone Pointer to preferred zone or NULL, on return contains zone 237 * number 233 238 */ 234 239 static zone_t * find_free_zone_and_lock(uint8_t order, unsigned int *pzone) … … 274 279 */ 275 280 static link_t *zone_buddy_find_block(buddy_system_t *b, link_t *child, 276 277 { 278 frame_t * 279 zone_t * 281 uint8_t order) 282 { 283 frame_t *frame; 284 zone_t *zone; 280 285 index_t index; 281 286 … … 294 299 static void zone_buddy_print_id(buddy_system_t *b, link_t *block) 295 300 { 296 frame_t * 297 zone_t * 301 frame_t *frame; 302 zone_t *zone; 298 303 index_t index; 299 304 … … 311 316 * @return Buddy for given block if found 312 317 */ 313 static link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t *block)314 { 315 frame_t * 316 zone_t * 318 static link_t *zone_buddy_find_buddy(buddy_system_t *b, link_t *block) 319 { 320 frame_t *frame; 321 zone_t *zone; 317 322 index_t index; 318 323 bool is_left, is_right; … … 320 325 frame = list_get_instance(block, frame_t, buddy_link); 321 326 zone = (zone_t *) b->data; 322 ASSERT(IS_BUDDY_ORDER_OK(frame_index_abs(zone, frame), frame->buddy_order)); 327 ASSERT(IS_BUDDY_ORDER_OK(frame_index_abs(zone, frame), 328 frame->buddy_order)); 323 329 324 330 is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame); … … 349 355 * @return right block 350 356 */ 351 static link_t * zone_buddy_bisect(buddy_system_t *b, link_t * 352 frame_t * frame_l, *frame_r;357 static link_t * zone_buddy_bisect(buddy_system_t *b, link_t *block) { 358 frame_t *frame_l, *frame_r; 353 359 354 360 frame_l = list_get_instance(block, frame_t, buddy_link); … … 366 372 * @return Coalesced block (actually block that represents lower address) 367 373 */ 368 static link_t * zone_buddy_coalesce(buddy_system_t *b, link_t *block_1,369 link_t *block_2)374 static link_t *zone_buddy_coalesce(buddy_system_t *b, link_t *block_1, 375 link_t *block_2) 370 376 { 371 377 frame_t *frame1, *frame2; … … 383 389 * @param order Order to set 384 390 */ 385 static void zone_buddy_set_order(buddy_system_t *b, link_t * block, uint8_t order) { 386 frame_t * frame; 391 static void zone_buddy_set_order(buddy_system_t *b, link_t *block, 392 uint8_t order) { 393 frame_t *frame; 387 394 frame = list_get_instance(block, frame_t, buddy_link); 388 395 frame->buddy_order = order; … … 396 403 * @return Order of block 397 404 */ 398 static uint8_t zone_buddy_get_order(buddy_system_t *b, link_t * 399 frame_t * 405 static uint8_t zone_buddy_get_order(buddy_system_t *b, link_t *block) { 406 frame_t *frame; 400 407 frame = list_get_instance(block, frame_t, buddy_link); 401 408 return frame->buddy_order; … … 421 428 * 422 429 */ 423 static void zone_buddy_mark_available(buddy_system_t *b, link_t * 424 frame_t * 430 static void zone_buddy_mark_available(buddy_system_t *b, link_t *block) { 431 frame_t *frame; 425 432 frame = list_get_instance(block, frame_t, buddy_link); 426 433 frame->refcount = 0; … … 521 528 if (frame->refcount) 522 529 return; 523 link = buddy_system_alloc_block(zone->buddy_system, 524 530 link = buddy_system_alloc_block(zone->buddy_system, 531 &frame->buddy_link); 525 532 ASSERT(link); 526 533 zone->free_count--; … … 546 553 frame_t *frame; 547 554 548 ASSERT(!overlaps(z1->base, z1->count,z2->base,z2->count));555 ASSERT(!overlaps(z1->base, z1->count, z2->base, z2->count)); 549 556 ASSERT(z1->base < z2->base); 550 557 551 558 spinlock_initialize(&z->lock, "zone_lock"); 552 559 z->base = z1->base; 553 z->count = z2->base +z2->count - z1->base;560 z->count = z2->base + z2->count - z1->base; 554 561 z->flags = z1->flags & z2->flags; 555 562 … … 559 566 max_order = fnzb(z->count); 560 567 561 z->buddy_system = (buddy_system_t *) &z[1];562 buddy_system_create(z->buddy_system, max_order, 563 &zone_buddy_system_operations,564 (void *) z); 565 566 z->frames = (frame_t *)((uint8_t *) z->buddy_system +buddy_conf_size(max_order));568 z->buddy_system = (buddy_system_t *) &z[1]; 569 buddy_system_create(z->buddy_system, max_order, 570 &zone_buddy_system_operations, (void *) z); 571 572 z->frames = (frame_t *)((uint8_t *) z->buddy_system + 573 buddy_conf_size(max_order)); 567 574 for (i = 0; i < z->count; i++) { 568 575 /* This marks all frames busy */ … … 604 611 while (zone_can_alloc(z2, 0)) { 605 612 frame_idx = zone_frame_alloc(z2, 0); 606 frame = &z->frames[frame_idx + (z2->base -z1->base)];613 frame = &z->frames[frame_idx + (z2->base - z1->base)]; 607 614 frame->refcount = 0; 608 615 buddy_system_free(z->buddy_system, &frame->buddy_link); … … 669 676 frame = &zone->frames[i + frame_idx]; 670 677 frame->buddy_order = 0; 671 if (! 678 if (!frame->refcount) 672 679 frame->refcount = 1; 673 680 ASSERT(frame->refcount == 1); … … 711 718 spinlock_lock(&zone2->lock); 712 719 713 cframes = SIZE2FRAMES(zone_conf_size(zone2->base+zone2->count-zone1->base)); 720 cframes = SIZE2FRAMES(zone_conf_size(zone2->base + zone2->count - 721 zone1->base)); 714 722 if (cframes == 1) 715 723 order = 0; … … 804 812 /* Allocate frames _after_ the conframe */ 805 813 /* Check sizes */ 806 z->frames = (frame_t *)((uint8_t *) z->buddy_system + buddy_conf_size(max_order)); 814 z->frames = (frame_t *)((uint8_t *) z->buddy_system + 815 buddy_conf_size(max_order)); 807 816 for (i = 0; i < count; i++) { 808 817 frame_initialize(&z->frames[i]); … … 866 875 for (;confframe < start + count; confframe++) { 867 876 addr = PFN2ADDR(confframe); 868 if (overlaps(addr, PFN2ADDR(confcount), KA2PA(config.base), config.kernel_size)) 877 if (overlaps(addr, PFN2ADDR(confcount), 878 KA2PA(config.base), config.kernel_size)) 869 879 continue; 870 880 871 if (overlaps(addr, PFN2ADDR(confcount), KA2PA(config.stack_base), config.stack_size)) 881 if (overlaps(addr, PFN2ADDR(confcount), 882 KA2PA(config.stack_base), config.stack_size)) 872 883 continue; 873 884 … … 875 886 count_t i; 876 887 for (i = 0; i < init.cnt; i++) 877 if (overlaps(addr, PFN2ADDR(confcount), KA2PA(init.tasks[i].addr), init.tasks[i].size)) { 888 if (overlaps(addr, PFN2ADDR(confcount), 889 KA2PA(init.tasks[i].addr), 890 init.tasks[i].size)) { 878 891 overlap = true; 879 892 break; … … 916 929 } 917 930 918 void * 931 void *frame_get_parent(pfn_t pfn, unsigned int hint) 919 932 { 920 933 zone_t *zone = find_zone_and_lock(pfn, &hint); … … 1074 1087 frame_arch_init(); 1075 1088 if (config.cpu_active == 1) { 1076 frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), SIZE2FRAMES(config.kernel_size)); 1077 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)), SIZE2FRAMES(config.stack_size)); 1089 frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), 1090 SIZE2FRAMES(config.kernel_size)); 1091 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)), 1092 SIZE2FRAMES(config.stack_size)); 1078 1093 1079 1094 count_t i; 1080 for (i = 0; i < init.cnt; i++) 1081 frame_mark_unavailable(ADDR2PFN(KA2PA(init.tasks[i].addr)), SIZE2FRAMES(init.tasks[i].size)); 1095 for (i = 0; i < init.cnt; i++) { 1096 pfn_t pfn = ADDR2PFN(KA2PA(init.tasks[i].addr)); 1097 frame_mark_unavailable(pfn, 1098 SIZE2FRAMES(init.tasks[i].size)); 1099 } 1082 1100 1083 1101 if (ballocs.size) 1084 frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)), SIZE2FRAMES(ballocs.size)); 1102 frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)), 1103 SIZE2FRAMES(ballocs.size)); 1085 1104 1086 1105 /* Black list first frame, as allocating NULL would … … 1107 1126 zone = zones.info[i]; 1108 1127 spinlock_lock(&zone->lock); 1109 printf("%-2d %12p %12zd %12zd\n", i, PFN2ADDR(zone->base), zone->free_count, zone->busy_count); 1128 printf("%-2d %12p %12zd %12zd\n", i, PFN2ADDR(zone->base), 1129 zone->free_count, zone->busy_count); 1110 1130 spinlock_unlock(&zone->lock); 1111 1131 } … … 1139 1159 spinlock_lock(&zone->lock); 1140 1160 printf("Memory zone information\n"); 1141 printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2, PFN2ADDR(zone->base)); 1142 printf("Zone size: %zd frames (%zdK)\n", zone->count, ((zone->count) * FRAME_SIZE) >> 10); 1143 printf("Allocated space: %zd frames (%zdK)\n", zone->busy_count, (zone->busy_count * FRAME_SIZE) >> 10); 1144 printf("Available space: %zd frames (%zdK)\n", zone->free_count, (zone->free_count * FRAME_SIZE) >> 10); 1161 printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2, 1162 PFN2ADDR(zone->base)); 1163 printf("Zone size: %zd frames (%zdK)\n", zone->count, 1164 ((zone->count) * FRAME_SIZE) >> 10); 1165 printf("Allocated space: %zd frames (%zdK)\n", zone->busy_count, 1166 (zone->busy_count * FRAME_SIZE) >> 10); 1167 printf("Available space: %zd frames (%zdK)\n", zone->free_count, 1168 (zone->free_count * FRAME_SIZE) >> 10); 1145 1169 buddy_system_structure_print(zone->buddy_system, FRAME_SIZE); 1146 1170 … … 1153 1177 /** @} 1154 1178 */ 1179 -
kernel/generic/src/mm/tlb.c
rd5bd8d7 r4638401 79 79 * @param count Number of pages, if required by type. 80 80 */ 81 void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, uintptr_t page, count_t count) 81 void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, 82 uintptr_t page, count_t count) 82 83 { 83 84 int i; … … 108 109 * Enqueue the message. 109 110 */ 110 cpu->tlb_messages[cpu->tlb_messages_count].type = type;111 cpu->tlb_messages[ cpu->tlb_messages_count].asid = asid;112 cpu->tlb_messages[ cpu->tlb_messages_count].page = page;113 cpu->tlb_messages[ cpu->tlb_messages_count].count = count;114 cpu->tlb_messages _count++;111 index_t idx = cpu->tlb_messages_count++; 112 cpu->tlb_messages[idx].type = type; 113 cpu->tlb_messages[idx].asid = asid; 114 cpu->tlb_messages[idx].page = page; 115 cpu->tlb_messages[idx].count = count; 115 116 } 116 117 spinlock_unlock(&cpu->lock);
Note:
See TracChangeset
for help on using the changeset viewer.