Changeset a35b458 in mainline for kernel/generic/src/mm/frame.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r3061bc1 ra35b458 108 108 return (size_t) -1; 109 109 } 110 110 111 111 size_t i; 112 112 for (i = 0; i < zones.count; i++) { … … 114 114 if (overlaps(zones.info[i].base, zones.info[i].count, 115 115 base, count)) { 116 116 117 117 /* 118 118 * If the overlaping zones are of the same type … … 121 121 * 122 122 */ 123 123 124 124 if ((zones.info[i].flags != flags) || 125 125 (!iswithin(zones.info[i].base, zones.info[i].count, … … 132 132 (void *) PFN2ADDR(zones.info[i].count)); 133 133 } 134 134 135 135 return (size_t) -1; 136 136 } … … 138 138 break; 139 139 } 140 140 141 141 /* Move other zones up */ 142 142 for (size_t j = zones.count; j > i; j--) 143 143 zones.info[j] = zones.info[j - 1]; 144 144 145 145 zones.count++; 146 146 147 147 return i; 148 148 } … … 163 163 for (i = 0; i < zones.count; i++) 164 164 total += zones.info[i].free_count; 165 165 166 166 return total; 167 167 } … … 195 195 if (hint >= zones.count) 196 196 hint = 0; 197 197 198 198 size_t i = hint; 199 199 do { … … 201 201 && (zones.info[i].base + zones.info[i].count >= frame + count)) 202 202 return i; 203 203 204 204 i++; 205 205 if (i >= zones.count) 206 206 i = 0; 207 207 208 208 } while (i != hint); 209 209 210 210 return (size_t) -1; 211 211 } … … 219 219 * the bitmap if the last argument is NULL. 220 220 */ 221 221 222 222 return ((zone->flags & ZONE_AVAILABLE) && 223 223 bitmap_allocate_range(&zone->bitmap, count, zone->base, … … 245 245 for (size_t pos = 0; pos < zones.count; pos++) { 246 246 size_t i = (pos + hint) % zones.count; 247 247 248 248 /* Check whether the zone meets the search criteria. */ 249 249 if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) 250 250 continue; 251 251 252 252 /* Check if the zone can satisfy the allocation request. */ 253 253 if (zone_can_alloc(&zones.info[i], count, constraint)) 254 254 return i; 255 255 } 256 256 257 257 return (size_t) -1; 258 258 } … … 291 291 for (size_t pos = 0; pos < zones.count; pos++) { 292 292 size_t i = (pos + hint) % zones.count; 293 293 294 294 /* Skip zones containing only high-priority memory. */ 295 295 if (is_high_priority(zones.info[i].base, zones.info[i].count)) 296 296 continue; 297 297 298 298 /* Check whether the zone meets the search criteria. */ 299 299 if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) 300 300 continue; 301 301 302 302 /* Check if the zone can satisfy the allocation request. */ 303 303 if (zone_can_alloc(&zones.info[i], count, constraint)) 304 304 return i; 305 305 } 306 306 307 307 return (size_t) -1; 308 308 } … … 328 328 if (hint >= zones.count) 329 329 hint = 0; 330 330 331 331 /* 332 332 * Prefer zones with low-priority memory over 333 333 * zones with high-priority memory. 334 334 */ 335 335 336 336 size_t znum = find_free_zone_lowprio(count, flags, constraint, hint); 337 337 if (znum != (size_t) -1) 338 338 return znum; 339 339 340 340 /* Take all zones into account */ 341 341 return find_free_zone_all(count, flags, constraint, hint); … … 350 350 { 351 351 assert(index < zone->count); 352 352 353 353 return &zone->frames[index]; 354 354 } … … 371 371 { 372 372 assert(zone->flags & ZONE_AVAILABLE); 373 373 374 374 /* Allocate frames from zone */ 375 375 size_t index = (size_t) -1; 376 376 int avail = bitmap_allocate_range(&zone->bitmap, count, zone->base, 377 377 FRAME_LOWPRIO, constraint, &index); 378 378 379 379 assert(avail); 380 380 assert(index != (size_t) -1); 381 381 382 382 /* Update frame reference count */ 383 383 for (size_t i = 0; i < count; i++) { 384 384 frame_t *frame = zone_get_frame(zone, index + i); 385 385 386 386 assert(frame->refcount == 0); 387 387 frame->refcount = 1; 388 388 } 389 389 390 390 /* Update zone information. */ 391 391 zone->free_count -= count; 392 392 zone->busy_count += count; 393 393 394 394 return index; 395 395 } … … 408 408 { 409 409 assert(zone->flags & ZONE_AVAILABLE); 410 410 411 411 frame_t *frame = zone_get_frame(zone, index); 412 412 413 413 assert(frame->refcount > 0); 414 414 415 415 if (!--frame->refcount) { 416 416 bitmap_set(&zone->bitmap, index, 0); 417 417 418 418 /* Update zone information. */ 419 419 zone->free_count++; 420 420 zone->busy_count--; 421 421 422 422 return 1; 423 423 } 424 424 425 425 return 0; 426 426 } … … 430 430 { 431 431 assert(zone->flags & ZONE_AVAILABLE); 432 432 433 433 frame_t *frame = zone_get_frame(zone, index); 434 434 if (frame->refcount > 0) 435 435 return; 436 436 437 437 frame->refcount = 1; 438 438 bitmap_set_range(&zone->bitmap, index, 1); 439 439 440 440 zone->free_count--; 441 441 reserve_force_alloc(1); … … 462 462 assert(!overlaps(zones.info[z1].base, zones.info[z1].count, 463 463 zones.info[z2].base, zones.info[z2].count)); 464 464 465 465 /* Difference between zone bases */ 466 466 pfn_t base_diff = zones.info[z2].base - zones.info[z1].base; 467 467 468 468 zones.info[z1].count = base_diff + zones.info[z2].count; 469 469 zones.info[z1].free_count += zones.info[z2].free_count; 470 470 zones.info[z1].busy_count += zones.info[z2].busy_count; 471 471 472 472 bitmap_initialize(&zones.info[z1].bitmap, zones.info[z1].count, 473 473 confdata + (sizeof(frame_t) * zones.info[z1].count)); 474 474 bitmap_clear_range(&zones.info[z1].bitmap, 0, zones.info[z1].count); 475 475 476 476 zones.info[z1].frames = (frame_t *) confdata; 477 477 478 478 /* 479 479 * Copy frames and bits from both zones to preserve parents, etc. 480 480 */ 481 481 482 482 for (size_t i = 0; i < old_z1->count; i++) { 483 483 bitmap_set(&zones.info[z1].bitmap, i, … … 485 485 zones.info[z1].frames[i] = old_z1->frames[i]; 486 486 } 487 487 488 488 for (size_t i = 0; i < zones.info[z2].count; i++) { 489 489 bitmap_set(&zones.info[z1].bitmap, base_diff + i, … … 510 510 { 511 511 assert(zones.info[znum].flags & ZONE_AVAILABLE); 512 512 513 513 size_t cframes = SIZE2FRAMES(zone_conf_size(count)); 514 514 515 515 if ((pfn < zones.info[znum].base) || 516 516 (pfn >= zones.info[znum].base + zones.info[znum].count)) 517 517 return; 518 518 519 519 for (size_t i = 0; i < cframes; i++) 520 520 (void) zone_frame_free(&zones.info[znum], … … 536 536 { 537 537 irq_spinlock_lock(&zones.lock, true); 538 538 539 539 bool ret = true; 540 540 541 541 /* 542 542 * We can join only 2 zones with none existing inbetween, … … 549 549 goto errout; 550 550 } 551 551 552 552 pfn_t cframes = SIZE2FRAMES(zone_conf_size( 553 553 zones.info[z2].base - zones.info[z1].base 554 554 + zones.info[z2].count)); 555 555 556 556 /* Allocate merged zone data inside one of the zones */ 557 557 pfn_t pfn; … … 566 566 goto errout; 567 567 } 568 568 569 569 /* Preserve original data from z1 */ 570 570 zone_t old_z1 = zones.info[z1]; 571 571 572 572 /* Do zone merging */ 573 573 zone_merge_internal(z1, z2, &old_z1, (void *) PA2KA(PFN2ADDR(pfn))); 574 574 575 575 /* Subtract zone information from busy frames */ 576 576 zones.info[z1].busy_count -= cframes; 577 577 578 578 /* Free old zone information */ 579 579 return_config_frames(z1, … … 582 582 ADDR2PFN(KA2PA((uintptr_t) zones.info[z2].frames)), 583 583 zones.info[z2].count); 584 584 585 585 /* Move zones down */ 586 586 for (size_t i = z2 + 1; i < zones.count; i++) 587 587 zones.info[i - 1] = zones.info[i]; 588 588 589 589 zones.count--; 590 590 591 591 errout: 592 592 irq_spinlock_unlock(&zones.lock, true); 593 593 594 594 return ret; 595 595 } … … 605 605 { 606 606 size_t i = 1; 607 607 608 608 while (i < zones.count) { 609 609 if (!zone_merge(i - 1, i)) … … 631 631 zone->free_count = count; 632 632 zone->busy_count = 0; 633 633 634 634 if (flags & ZONE_AVAILABLE) { 635 635 /* … … 637 637 * frame_t structures in the configuration space). 638 638 */ 639 639 640 640 bitmap_initialize(&zone->bitmap, count, confdata + 641 641 (sizeof(frame_t) * count)); 642 642 bitmap_clear_range(&zone->bitmap, 0, count); 643 643 644 644 /* 645 645 * Initialize the array of frame_t structures. 646 646 */ 647 647 648 648 zone->frames = (frame_t *) confdata; 649 649 650 650 for (size_t i = 0; i < count; i++) 651 651 frame_initialize(&zone->frames[i]); … … 672 672 { 673 673 size_t frames = SIZE2FRAMES(zone_conf_size(count)); 674 674 675 675 return ADDR2PFN((uintptr_t) 676 676 frame_alloc(frames, FRAME_LOWMEM | FRAME_ATOMIC, 0)); … … 697 697 { 698 698 irq_spinlock_lock(&zones.lock, true); 699 699 700 700 if (flags & ZONE_AVAILABLE) { /* Create available zone */ 701 701 /* … … 705 705 */ 706 706 assert(confframe != ADDR2PFN((uintptr_t ) NULL)); 707 707 708 708 /* Update the known end of physical memory. */ 709 709 config.physmem_end = max(config.physmem_end, PFN2ADDR(start + count)); 710 710 711 711 /* 712 712 * If confframe is supposed to be inside our zone, then make sure … … 714 714 */ 715 715 size_t confcount = SIZE2FRAMES(zone_conf_size(count)); 716 716 717 717 if ((confframe >= start) && (confframe < start + count)) { 718 718 for (; confframe < start + count; confframe++) { … … 721 721 KA2PA(config.base), config.kernel_size)) 722 722 continue; 723 723 724 724 if (overlaps(addr, PFN2ADDR(confcount), 725 725 KA2PA(config.stack_base), config.stack_size)) 726 726 continue; 727 727 728 728 bool overlap = false; 729 729 for (size_t i = 0; i < init.cnt; i++) { … … 735 735 } 736 736 } 737 737 738 738 if (overlap) 739 739 continue; 740 740 741 741 break; 742 742 } 743 743 744 744 if (confframe >= start + count) 745 745 panic("Cannot find configuration data for zone."); 746 746 } 747 747 748 748 size_t znum = zones_insert_zone(start, count, flags); 749 749 if (znum == (size_t) -1) { … … 751 751 return (size_t) -1; 752 752 } 753 753 754 754 void *confdata = (void *) PA2KA(PFN2ADDR(confframe)); 755 755 zone_construct(&zones.info[znum], start, count, flags, confdata); 756 756 757 757 /* If confdata in zone, mark as unavailable */ 758 758 if ((confframe >= start) && (confframe < start + count)) { … … 761 761 i - zones.info[znum].base); 762 762 } 763 763 764 764 irq_spinlock_unlock(&zones.lock, true); 765 765 766 766 return znum; 767 767 } 768 768 769 769 /* Non-available zone */ 770 770 size_t znum = zones_insert_zone(start, count, flags); … … 773 773 return (size_t) -1; 774 774 } 775 775 776 776 zone_construct(&zones.info[znum], start, count, flags, NULL); 777 777 778 778 irq_spinlock_unlock(&zones.lock, true); 779 779 780 780 return znum; 781 781 } … … 789 789 { 790 790 irq_spinlock_lock(&zones.lock, true); 791 791 792 792 size_t znum = find_zone(pfn, 1, hint); 793 793 794 794 assert(znum != (size_t) -1); 795 795 796 796 zone_get_frame(&zones.info[znum], 797 797 pfn - zones.info[znum].base)->parent = data; 798 798 799 799 irq_spinlock_unlock(&zones.lock, true); 800 800 } … … 803 803 { 804 804 irq_spinlock_lock(&zones.lock, true); 805 805 806 806 size_t znum = find_zone(pfn, 1, hint); 807 807 808 808 assert(znum != (size_t) -1); 809 809 810 810 void *res = zone_get_frame(&zones.info[znum], 811 811 pfn - zones.info[znum].base)->parent; 812 812 813 813 irq_spinlock_unlock(&zones.lock, true); 814 814 815 815 return res; 816 816 } … … 831 831 { 832 832 assert(count > 0); 833 833 834 834 size_t hint = pzone ? (*pzone) : 0; 835 835 pfn_t frame_constraint = ADDR2PFN(constraint); 836 836 837 837 /* 838 838 * If not told otherwise, we must first reserve the memory. … … 840 840 if (!(flags & FRAME_NO_RESERVE)) 841 841 reserve_force_alloc(count); 842 842 843 843 loop: 844 844 irq_spinlock_lock(&zones.lock, true); 845 845 846 846 /* 847 847 * First, find suitable frame zone. … … 849 849 size_t znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags), 850 850 frame_constraint, hint); 851 851 852 852 /* 853 853 * If no memory, reclaim some slab memory, … … 858 858 size_t freed = slab_reclaim(0); 859 859 irq_spinlock_lock(&zones.lock, true); 860 860 861 861 if (freed > 0) 862 862 znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags), 863 863 frame_constraint, hint); 864 864 865 865 if (znum == (size_t) -1) { 866 866 irq_spinlock_unlock(&zones.lock, true); 867 867 freed = slab_reclaim(SLAB_RECLAIM_ALL); 868 868 irq_spinlock_lock(&zones.lock, true); 869 869 870 870 if (freed > 0) 871 871 znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags), … … 873 873 } 874 874 } 875 875 876 876 if (znum == (size_t) -1) { 877 877 if (flags & FRAME_ATOMIC) { 878 878 irq_spinlock_unlock(&zones.lock, true); 879 879 880 880 if (!(flags & FRAME_NO_RESERVE)) 881 881 reserve_free(count); 882 882 883 883 return 0; 884 884 } 885 885 886 886 size_t avail = frame_total_free_get_internal(); 887 887 888 888 irq_spinlock_unlock(&zones.lock, true); 889 889 890 890 if (!THREAD) 891 891 panic("Cannot wait for %zu frames to become available " 892 892 "(%zu available).", count, avail); 893 893 894 894 /* 895 895 * Sleep until some frames are available again. 896 896 */ 897 897 898 898 #ifdef CONFIG_DEBUG 899 899 log(LF_OTHER, LVL_DEBUG, … … 901 901 "%zu available.", THREAD->tid, count, avail); 902 902 #endif 903 903 904 904 /* 905 905 * Since the mem_avail_mtx is an active mutex, we need to … … 908 908 ipl_t ipl = interrupts_disable(); 909 909 mutex_lock(&mem_avail_mtx); 910 910 911 911 if (mem_avail_req > 0) 912 912 mem_avail_req = min(mem_avail_req, count); 913 913 else 914 914 mem_avail_req = count; 915 915 916 916 size_t gen = mem_avail_gen; 917 917 918 918 while (gen == mem_avail_gen) 919 919 condvar_wait(&mem_avail_cv, &mem_avail_mtx); 920 920 921 921 mutex_unlock(&mem_avail_mtx); 922 922 interrupts_restore(ipl); 923 923 924 924 #ifdef CONFIG_DEBUG 925 925 log(LF_OTHER, LVL_DEBUG, "Thread %" PRIu64 " woken up.", 926 926 THREAD->tid); 927 927 #endif 928 928 929 929 goto loop; 930 930 } 931 931 932 932 pfn_t pfn = zone_frame_alloc(&zones.info[znum], count, 933 933 frame_constraint) + zones.info[znum].base; 934 934 935 935 irq_spinlock_unlock(&zones.lock, true); 936 936 937 937 if (pzone) 938 938 *pzone = znum; 939 939 940 940 return PFN2ADDR(pfn); 941 941 } … … 960 960 { 961 961 size_t freed = 0; 962 962 963 963 irq_spinlock_lock(&zones.lock, true); 964 964 965 965 for (size_t i = 0; i < count; i++) { 966 966 /* … … 969 969 pfn_t pfn = ADDR2PFN(start) + i; 970 970 size_t znum = find_zone(pfn, 1, 0); 971 971 972 972 assert(znum != (size_t) -1); 973 973 974 974 freed += zone_frame_free(&zones.info[znum], 975 975 pfn - zones.info[znum].base); 976 976 } 977 977 978 978 irq_spinlock_unlock(&zones.lock, true); 979 979 980 980 /* 981 981 * Signal that some memory has been freed. … … 984 984 * with TLB shootdown. 985 985 */ 986 986 987 987 ipl_t ipl = interrupts_disable(); 988 988 mutex_lock(&mem_avail_mtx); 989 989 990 990 if (mem_avail_req > 0) 991 991 mem_avail_req -= min(mem_avail_req, freed); 992 992 993 993 if (mem_avail_req == 0) { 994 994 mem_avail_gen++; 995 995 condvar_broadcast(&mem_avail_cv); 996 996 } 997 997 998 998 mutex_unlock(&mem_avail_mtx); 999 999 interrupts_restore(ipl); 1000 1000 1001 1001 if (!(flags & FRAME_NO_RESERVE)) 1002 1002 reserve_free(freed); … … 1024 1024 { 1025 1025 irq_spinlock_lock(&zones.lock, true); 1026 1026 1027 1027 /* 1028 1028 * First, find host frame zone for addr. 1029 1029 */ 1030 1030 size_t znum = find_zone(pfn, 1, 0); 1031 1031 1032 1032 assert(znum != (size_t) -1); 1033 1033 1034 1034 zones.info[znum].frames[pfn - zones.info[znum].base].refcount++; 1035 1035 1036 1036 irq_spinlock_unlock(&zones.lock, true); 1037 1037 } … … 1043 1043 { 1044 1044 irq_spinlock_lock(&zones.lock, true); 1045 1045 1046 1046 for (size_t i = 0; i < count; i++) { 1047 1047 size_t znum = find_zone(start + i, 1, 0); 1048 1048 1049 1049 if (znum == (size_t) -1) /* PFN not found */ 1050 1050 continue; 1051 1051 1052 1052 zone_mark_unavailable(&zones.info[znum], 1053 1053 start + i - zones.info[znum].base); 1054 1054 } 1055 1055 1056 1056 irq_spinlock_unlock(&zones.lock, true); 1057 1057 } … … 1068 1068 condvar_initialize(&mem_avail_cv); 1069 1069 } 1070 1070 1071 1071 /* Tell the architecture to create some memory */ 1072 1072 frame_low_arch_init(); 1073 1073 1074 1074 if (config.cpu_active == 1) { 1075 1075 frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), … … 1077 1077 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)), 1078 1078 SIZE2FRAMES(config.stack_size)); 1079 1079 1080 1080 for (size_t i = 0; i < init.cnt; i++) 1081 1081 frame_mark_unavailable(ADDR2PFN(init.tasks[i].paddr), 1082 1082 SIZE2FRAMES(init.tasks[i].size)); 1083 1083 1084 1084 if (ballocs.size) 1085 1085 frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)), 1086 1086 SIZE2FRAMES(ballocs.size)); 1087 1087 1088 1088 /* 1089 1089 * Blacklist first frame, as allocating NULL would … … 1092 1092 frame_mark_unavailable(0, 1); 1093 1093 } 1094 1094 1095 1095 frame_high_arch_init(); 1096 1096 } … … 1113 1113 { 1114 1114 uintptr_t limit = KA2PA(config.identity_base) + config.identity_size; 1115 1115 1116 1116 if (low) { 1117 1117 if (*basep > limit) 1118 1118 return false; 1119 1119 1120 1120 if (*basep + *sizep > limit) 1121 1121 *sizep = limit - *basep; … … 1123 1123 if (*basep + *sizep <= limit) 1124 1124 return false; 1125 1125 1126 1126 if (*basep <= limit) { 1127 1127 *sizep -= limit - *basep; … … 1129 1129 } 1130 1130 } 1131 1131 1132 1132 return true; 1133 1133 } … … 1139 1139 { 1140 1140 irq_spinlock_lock(&zones.lock, true); 1141 1141 1142 1142 uint64_t total = 0; 1143 1143 1144 1144 for (size_t i = 0; i < zones.count; i++) 1145 1145 total += (uint64_t) FRAMES2SIZE(zones.info[i].count); 1146 1146 1147 1147 irq_spinlock_unlock(&zones.lock, true); 1148 1148 1149 1149 return total; 1150 1150 } … … 1157 1157 assert(busy != NULL); 1158 1158 assert(free != NULL); 1159 1159 1160 1160 irq_spinlock_lock(&zones.lock, true); 1161 1161 1162 1162 *total = 0; 1163 1163 *unavail = 0; 1164 1164 *busy = 0; 1165 1165 *free = 0; 1166 1166 1167 1167 for (size_t i = 0; i < zones.count; i++) { 1168 1168 *total += (uint64_t) FRAMES2SIZE(zones.info[i].count); 1169 1169 1170 1170 if (zones.info[i].flags & ZONE_AVAILABLE) { 1171 1171 *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count); … … 1174 1174 *unavail += (uint64_t) FRAMES2SIZE(zones.info[i].count); 1175 1175 } 1176 1176 1177 1177 irq_spinlock_unlock(&zones.lock, true); 1178 1178 } … … 1190 1190 printf("[nr] [base address ] [frames ] [flags ] [free frames ] [busy frames ]\n"); 1191 1191 #endif 1192 1192 1193 1193 /* 1194 1194 * Because printing may require allocation of memory, we may not hold … … 1201 1201 * the listing). 1202 1202 */ 1203 1203 1204 1204 size_t free_lowmem = 0; 1205 1205 size_t free_highmem = 0; 1206 1206 size_t free_highprio = 0; 1207 1207 1208 1208 for (size_t i = 0;; i++) { 1209 1209 irq_spinlock_lock(&zones.lock, true); 1210 1210 1211 1211 if (i >= zones.count) { 1212 1212 irq_spinlock_unlock(&zones.lock, true); 1213 1213 break; 1214 1214 } 1215 1215 1216 1216 pfn_t fbase = zones.info[i].base; 1217 1217 uintptr_t base = PFN2ADDR(fbase); … … 1220 1220 size_t free_count = zones.info[i].free_count; 1221 1221 size_t busy_count = zones.info[i].busy_count; 1222 1222 1223 1223 bool available = ((flags & ZONE_AVAILABLE) != 0); 1224 1224 bool lowmem = ((flags & ZONE_LOWMEM) != 0); 1225 1225 bool highmem = ((flags & ZONE_HIGHMEM) != 0); 1226 1226 bool highprio = is_high_priority(fbase, count); 1227 1227 1228 1228 if (available) { 1229 1229 if (lowmem) 1230 1230 free_lowmem += free_count; 1231 1231 1232 1232 if (highmem) 1233 1233 free_highmem += free_count; 1234 1234 1235 1235 if (highprio) { 1236 1236 free_highprio += free_count; … … 1241 1241 * statistics. 1242 1242 */ 1243 1243 1244 1244 for (size_t index = 0; index < count; index++) { 1245 1245 if (is_high_priority(fbase + index, 0)) { … … 1251 1251 } 1252 1252 } 1253 1253 1254 1254 irq_spinlock_unlock(&zones.lock, true); 1255 1255 1256 1256 printf("%-4zu", i); 1257 1257 1258 1258 #ifdef __32_BITS__ 1259 1259 printf(" %p", (void *) base); 1260 1260 #endif 1261 1261 1262 1262 #ifdef __64_BITS__ 1263 1263 printf(" %p", (void *) base); 1264 1264 #endif 1265 1265 1266 1266 printf(" %12zu %c%c%c%c%c ", count, 1267 1267 available ? 'A' : '-', … … 1270 1270 (flags & ZONE_LOWMEM) ? 'L' : '-', 1271 1271 (flags & ZONE_HIGHMEM) ? 'H' : '-'); 1272 1272 1273 1273 if (available) 1274 1274 printf("%14zu %14zu", 1275 1275 free_count, busy_count); 1276 1276 1277 1277 printf("\n"); 1278 1278 } 1279 1279 1280 1280 printf("\n"); 1281 1281 1282 1282 uint64_t size; 1283 1283 const char *size_suffix; 1284 1284 1285 1285 bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix, 1286 1286 false); 1287 1287 printf("Available low memory: %zu frames (%" PRIu64 " %s)\n", 1288 1288 free_lowmem, size, size_suffix); 1289 1289 1290 1290 bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix, 1291 1291 false); 1292 1292 printf("Available high memory: %zu frames (%" PRIu64 " %s)\n", 1293 1293 free_highmem, size, size_suffix); 1294 1294 1295 1295 bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix, 1296 1296 false); … … 1308 1308 irq_spinlock_lock(&zones.lock, true); 1309 1309 size_t znum = (size_t) -1; 1310 1310 1311 1311 for (size_t i = 0; i < zones.count; i++) { 1312 1312 if ((i == num) || (PFN2ADDR(zones.info[i].base) == num)) { … … 1315 1315 } 1316 1316 } 1317 1317 1318 1318 if (znum == (size_t) -1) { 1319 1319 irq_spinlock_unlock(&zones.lock, true); … … 1321 1321 return; 1322 1322 } 1323 1323 1324 1324 size_t free_lowmem = 0; 1325 1325 size_t free_highmem = 0; 1326 1326 size_t free_highprio = 0; 1327 1327 1328 1328 pfn_t fbase = zones.info[znum].base; 1329 1329 uintptr_t base = PFN2ADDR(fbase); … … 1332 1332 size_t free_count = zones.info[znum].free_count; 1333 1333 size_t busy_count = zones.info[znum].busy_count; 1334 1334 1335 1335 bool available = ((flags & ZONE_AVAILABLE) != 0); 1336 1336 bool lowmem = ((flags & ZONE_LOWMEM) != 0); 1337 1337 bool highmem = ((flags & ZONE_HIGHMEM) != 0); 1338 1338 bool highprio = is_high_priority(fbase, count); 1339 1339 1340 1340 if (available) { 1341 1341 if (lowmem) 1342 1342 free_lowmem = free_count; 1343 1343 1344 1344 if (highmem) 1345 1345 free_highmem = free_count; 1346 1346 1347 1347 if (highprio) { 1348 1348 free_highprio = free_count; … … 1353 1353 * statistics. 1354 1354 */ 1355 1355 1356 1356 for (size_t index = 0; index < count; index++) { 1357 1357 if (is_high_priority(fbase + index, 0)) { … … 1363 1363 } 1364 1364 } 1365 1365 1366 1366 irq_spinlock_unlock(&zones.lock, true); 1367 1367 1368 1368 uint64_t size; 1369 1369 const char *size_suffix; 1370 1370 1371 1371 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1372 1372 1373 1373 printf("Zone number: %zu\n", znum); 1374 1374 printf("Zone base address: %p\n", (void *) base); … … 1381 1381 (flags & ZONE_LOWMEM) ? 'L' : '-', 1382 1382 (flags & ZONE_HIGHMEM) ? 'H' : '-'); 1383 1383 1384 1384 if (available) { 1385 1385 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, … … 1387 1387 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1388 1388 busy_count, size, size_suffix); 1389 1389 1390 1390 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1391 1391 false); 1392 1392 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1393 1393 free_count, size, size_suffix); 1394 1394 1395 1395 bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix, 1396 1396 false); 1397 1397 printf("Available low memory: %zu frames (%" PRIu64 " %s)\n", 1398 1398 free_lowmem, size, size_suffix); 1399 1399 1400 1400 bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix, 1401 1401 false); 1402 1402 printf("Available high memory: %zu frames (%" PRIu64 " %s)\n", 1403 1403 free_highmem, size, size_suffix); 1404 1404 1405 1405 bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix, 1406 1406 false);
Note:
See TracChangeset
for help on using the changeset viewer.