Changeset 1bb3766 in mainline
- Timestamp:
- 2008-06-23T23:02:01Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ac0e791
- Parents:
- 1a1744e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r1a1744e r1bb3766 110 110 * available. 111 111 */ 112 mutex_t zones_mtx; 113 condvar_t zones_cv; 114 int new_freed_mem = false; 112 mutex_t mem_avail_mtx; 113 condvar_t mem_avail_cv; 114 unsigned long mem_avail_frames = 0; /**< Number of available frames. */ 115 unsigned long mem_avail_gen = 0; /**< Generation counter. */ 115 116 116 117 /********************/ … … 141 142 /** Initialize frame structure. 142 143 * 143 * @param frame iFrame structure to be initialized.144 * @param frame Frame structure to be initialized. 144 145 */ 145 146 static void frame_initialize(frame_t *frame) … … 540 541 541 542 /** Return frame from zone. */ 542 static frame_t * 543 static frame_t *zone_get_frame(zone_t *zone, index_t frame_idx) 543 544 { 544 545 ASSERT(frame_idx < zone->count); … … 559 560 ASSERT(link); 560 561 zone->free_count--; 562 563 mutex_lock(&mem_avail_mtx); 564 mem_avail_frames--; 565 mutex_unlock(&mem_avail_mtx); 561 566 } 562 567 … … 736 741 goto errout; 737 742 /* We can join only 2 zones with none existing inbetween */ 738 if (z2 -z1 != 1)743 if (z2 - z1 != 1) 739 744 goto errout; 740 745 … … 797 802 798 803 while (zones.count > 1 && --count) { 799 zone_merge(0, 1);804 zone_merge(0, 1); 800 805 break; 801 806 } … … 894 899 */ 895 900 confcount = SIZE2FRAMES(zone_conf_size(count)); 896 if (confframe >= start && confframe < start +count) {897 for (; confframe < start + count; confframe++) {901 if (confframe >= start && confframe < start + count) { 902 for (; confframe < start + count; confframe++) { 898 903 addr = PFN2ADDR(confframe); 899 904 if (overlaps(addr, PFN2ADDR(confcount), … … 929 934 return -1; 930 935 936 mutex_lock(&mem_avail_mtx); 937 mem_avail_frames += count; 938 mutex_unlock(&mem_avail_mtx); 939 931 940 /* If confdata in zone, mark as unavailable */ 932 941 if (confframe >= start && confframe < start + count) … … 934 943 zone_mark_unavailable(z, i - z->base); 935 944 } 945 936 946 return znum; 937 947 } … … 947 957 ASSERT(zone); 948 958 949 zone_get_frame(zone, pfn -zone->base)->parent = data;959 zone_get_frame(zone, pfn - zone->base)->parent = data; 950 960 spinlock_unlock(&zone->lock); 951 961 } … … 978 988 pfn_t v; 979 989 zone_t *zone; 990 unsigned long gen = 0; 980 991 981 992 loop: … … 1009 1020 1010 1021 #ifdef CONFIG_DEBUG 1011 printf("Thread %" PRIu64 " falling asleep, low memory.\n", THREAD->tid); 1022 unsigned long avail; 1023 1024 mutex_lock(&mem_avail_mtx); 1025 avail = mem_avail_frames; 1026 mutex_unlock(&mem_avail_mtx); 1027 1028 printf("Thread %" PRIu64 " waiting for %u frames, " 1029 "%u available.\n", THREAD->tid, 1ULL << order, avail); 1012 1030 #endif 1013 1031 1014 mutex_lock(&zones_mtx); 1015 if (!new_freed_mem) 1016 condvar_wait(&zones_cv, &zones_mtx); 1017 new_freed_mem = false; 1018 mutex_unlock(&zones_mtx); 1032 mutex_lock(&mem_avail_mtx); 1033 while ((mem_avail_frames < (1ULL << order)) || 1034 gen == mem_avail_gen) 1035 condvar_wait(&mem_avail_cv, &mem_avail_mtx); 1036 gen = mem_avail_gen; 1037 mutex_unlock(&mem_avail_mtx); 1019 1038 1020 1039 #ifdef CONFIG_DEBUG 1021 printf("Thread %" PRIu64 " woken up, memory available.\n", THREAD->tid); 1040 mutex_lock(&mem_avail_mtx); 1041 avail = mem_avail_frames; 1042 mutex_unlock(&mem_avail_mtx); 1043 1044 printf("Thread %" PRIu64 " woken up, %u frames available.\n", 1045 THREAD->tid, avail); 1022 1046 #endif 1023 1047 … … 1030 1054 1031 1055 spinlock_unlock(&zone->lock); 1056 1057 mutex_lock(&mem_avail_mtx); 1058 mem_avail_frames -= (1ULL << order); 1059 mutex_unlock(&mem_avail_mtx); 1060 1032 1061 interrupts_restore(ipl); 1033 1062 … … 1066 1095 * Signal that some memory has been freed. 1067 1096 */ 1068 mutex_lock(&zones_mtx); 1069 new_freed_mem = true; 1070 condvar_broadcast(&zones_cv); 1071 mutex_unlock(&zones_mtx); 1097 mutex_lock(&mem_avail_mtx); 1098 mem_avail_frames++; 1099 mem_avail_gen++; 1100 condvar_broadcast(&mem_avail_cv); 1101 mutex_unlock(&mem_avail_mtx); 1072 1102 1073 1103 interrupts_restore(ipl); … … 1125 1155 zones.count = 0; 1126 1156 spinlock_initialize(&zones.lock, "zones.lock"); 1157 mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE); 1158 condvar_initialize(&mem_avail_cv); 1127 1159 } 1128 1160 /* Tell the architecture to create some memory */ … … 1149 1181 frame_mark_unavailable(0, 1); 1150 1182 } 1151 1152 mutex_initialize(&zones_mtx, MUTEX_ACTIVE); /* mimic spinlock */1153 condvar_initialize(&zones_cv);1154 1183 } 1155 1184
Note:
See TracChangeset
for help on using the changeset viewer.