Changeset b5e68c8 in mainline for kernel/generic/src/mm/frame.c
- Timestamp:
- 2011-05-12T16:49:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f36787d7
- Parents:
- e80329d6 (diff), 750636a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
re80329d6 rb5e68c8 45 45 #include <typedefs.h> 46 46 #include <mm/frame.h> 47 #include <mm/reserve.h> 47 48 #include <mm/as.h> 48 49 #include <panic.h> … … 59 60 #include <macros.h> 60 61 #include <config.h> 62 #include <str.h> 61 63 62 64 zones_t zones; … … 145 147 (!iswithin(zones.info[i].base, zones.info[i].count, 146 148 base, count))) { 147 printf("Zone (%p, %p) overlaps with previous zone (%p, %p)!\n", 148 PFN2ADDR(base), PFN2ADDR(count), 149 PFN2ADDR(zones.info[i].base), 150 PFN2ADDR(zones.info[i].count)); 149 printf("Zone (%p, %p) overlaps " 150 "with previous zone (%p %p)!\n", 151 (void *) PFN2ADDR(base), (void *) PFN2ADDR(count), 152 (void *) PFN2ADDR(zones.info[i].base), 153 (void *) PFN2ADDR(zones.info[i].count)); 151 154 } 152 155 … … 471 474 * @param frame_idx Frame index relative to zone. 472 475 * 473 */ 474 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx) 476 * @return Number of freed frames. 477 * 478 */ 479 NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx) 475 480 { 476 481 ASSERT(zone_flags_available(zone->flags)); 477 482 478 483 frame_t *frame = &zone->frames[frame_idx]; 479 480 /* Remember frame order */ 481 uint8_t order = frame->buddy_order; 484 size_t size = 0; 482 485 483 486 ASSERT(frame->refcount); 484 487 485 488 if (!--frame->refcount) { 486 buddy_system_free(zone->buddy_system, &frame->buddy_link);487 489 size = 1 << frame->buddy_order; 490 buddy_system_free(zone->buddy_system, &frame->buddy_link); 488 491 /* Update zone information. */ 489 zone->free_count += (1 << order); 490 zone->busy_count -= (1 << order); 491 } 492 zone->free_count += size; 493 zone->busy_count -= size; 494 } 495 496 return size; 492 497 } 493 498 … … 515 520 ASSERT(link); 516 521 zone->free_count--; 522 reserve_force_alloc(1); 517 523 } 518 524 … … 644 650 for (i = 0; i < cframes; i++) { 645 651 zones.info[znum].busy_count++; 646 zone_frame_free(&zones.info[znum],652 (void) zone_frame_free(&zones.info[znum], 647 653 pfn - zones.info[znum].base + i); 648 654 } … … 682 688 /* Free unneeded frames */ 683 689 for (i = count; i < (size_t) (1 << order); i++) 684 zone_frame_free(&zones.info[znum], i + frame_idx);690 (void) zone_frame_free(&zones.info[znum], i + frame_idx); 685 691 } 686 692 … … 694 700 * not to be 2^order size. Once the allocator is running it is no longer 695 701 * possible, merged configuration data occupies more space :-/ 696 *697 * The function uses698 702 * 699 703 */ … … 836 840 buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link); 837 841 } 842 843 /* "Unreserve" new frames. */ 844 reserve_free(count); 838 845 } else 839 846 zone->frames = NULL; … … 878 885 * the assert 879 886 */ 880 ASSERT(confframe != NULL);887 ASSERT(confframe != ADDR2PFN((uintptr_t ) NULL)); 881 888 882 889 /* If confframe is supposed to be inside our zone, then make sure … … 998 1005 size_t hint = pzone ? (*pzone) : 0; 999 1006 1007 /* 1008 * If not told otherwise, we must first reserve the memory. 1009 */ 1010 if (!(flags & FRAME_NO_RESERVE)) 1011 reserve_force_alloc(size); 1012 1000 1013 loop: 1001 1014 irq_spinlock_lock(&zones.lock, true); … … 1032 1045 if (flags & FRAME_ATOMIC) { 1033 1046 irq_spinlock_unlock(&zones.lock, true); 1047 if (!(flags & FRAME_NO_RESERVE)) 1048 reserve_free(size); 1034 1049 return NULL; 1035 1050 } … … 1049 1064 1050 1065 #ifdef CONFIG_DEBUG 1051 printf("Thread %" PRIu64 " waiting for % " PRIs "frames, "1052 "% " PRIs "available.\n", THREAD->tid, size, avail);1066 printf("Thread %" PRIu64 " waiting for %zu frames, " 1067 "%zu available.\n", THREAD->tid, size, avail); 1053 1068 #endif 1054 1069 … … 1087 1102 } 1088 1103 1104 void *frame_alloc(uint8_t order, frame_flags_t flags) 1105 { 1106 return frame_alloc_generic(order, flags, NULL); 1107 } 1108 1109 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags) 1110 { 1111 return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL); 1112 } 1113 1089 1114 /** Free a frame. 1090 1115 * … … 1094 1119 * 1095 1120 * @param frame Physical Address of of the frame to be freed. 1096 * 1097 */ 1098 void frame_free(uintptr_t frame) 1099 { 1121 * @param flags Flags to control memory reservation. 1122 * 1123 */ 1124 void frame_free_generic(uintptr_t frame, frame_flags_t flags) 1125 { 1126 size_t size; 1127 1100 1128 irq_spinlock_lock(&zones.lock, true); 1101 1129 … … 1104 1132 */ 1105 1133 pfn_t pfn = ADDR2PFN(frame); 1106 size_t znum = find_zone(pfn, 1, NULL); 1134 size_t znum = find_zone(pfn, 1, 0); 1135 1107 1136 1108 1137 ASSERT(znum != (size_t) -1); 1109 1138 1110 zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);1139 size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base); 1111 1140 1112 1141 irq_spinlock_unlock(&zones.lock, true); … … 1117 1146 mutex_lock(&mem_avail_mtx); 1118 1147 if (mem_avail_req > 0) 1119 mem_avail_req --;1148 mem_avail_req -= min(mem_avail_req, size); 1120 1149 1121 1150 if (mem_avail_req == 0) { … … 1124 1153 } 1125 1154 mutex_unlock(&mem_avail_mtx); 1155 1156 if (!(flags & FRAME_NO_RESERVE)) 1157 reserve_free(size); 1158 } 1159 1160 void frame_free(uintptr_t frame) 1161 { 1162 frame_free_generic(frame, 0); 1163 } 1164 1165 void frame_free_noreserve(uintptr_t frame) 1166 { 1167 frame_free_generic(frame, FRAME_NO_RESERVE); 1126 1168 } 1127 1169 … … 1141 1183 * First, find host frame zone for addr. 1142 1184 */ 1143 size_t znum = find_zone(pfn, 1, NULL);1185 size_t znum = find_zone(pfn, 1, 0); 1144 1186 1145 1187 ASSERT(znum != (size_t) -1); … … 1297 1339 bool available = zone_flags_available(flags); 1298 1340 1299 printf("%-4 " PRIs, i);1341 printf("%-4zu", i); 1300 1342 1301 1343 #ifdef __32_BITS__ 1302 printf(" % 10p",base);1344 printf(" %p", (void *) base); 1303 1345 #endif 1304 1346 1305 1347 #ifdef __64_BITS__ 1306 printf(" % 18p",base);1348 printf(" %p", (void *) base); 1307 1349 #endif 1308 1350 1309 printf(" %12 " PRIs "%c%c%c ", count,1351 printf(" %12zu %c%c%c ", count, 1310 1352 available ? 'A' : ' ', 1311 1353 (flags & ZONE_RESERVED) ? 'R' : ' ', … … 1313 1355 1314 1356 if (available) 1315 printf("%14 " PRIs " %14" PRIs,1357 printf("%14zu %14zu", 1316 1358 free_count, busy_count); 1317 1359 … … 1354 1396 bool available = zone_flags_available(flags); 1355 1397 1356 printf("Zone number: %" PRIs "\n", znum); 1357 printf("Zone base address: %p\n", base); 1358 printf("Zone size: %" PRIs " frames (%" PRIs " KiB)\n", count, 1359 SIZE2KB(FRAMES2SIZE(count))); 1398 uint64_t size; 1399 const char *size_suffix; 1400 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1401 1402 printf("Zone number: %zu\n", znum); 1403 printf("Zone base address: %p\n", (void *) base); 1404 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count, 1405 size, size_suffix); 1360 1406 printf("Zone flags: %c%c%c\n", 1361 1407 available ? 'A' : ' ', … … 1364 1410 1365 1411 if (available) { 1366 printf("Allocated space: %" PRIs " frames (%" PRIs " KiB)\n", 1367 busy_count, SIZE2KB(FRAMES2SIZE(busy_count))); 1368 printf("Available space: %" PRIs " frames (%" PRIs " KiB)\n", 1369 free_count, SIZE2KB(FRAMES2SIZE(free_count))); 1412 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, 1413 false); 1414 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1415 busy_count, size, size_suffix); 1416 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1417 false); 1418 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1419 free_count, size, size_suffix); 1370 1420 } 1371 1421 }
Note:
See TracChangeset
for help on using the changeset viewer.