Changeset 71eef11 in mainline for kernel/generic/src/mm/frame.c
- Timestamp:
- 2008-02-06T14:24:13Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7208b6c
- Parents:
- 1b067315
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
r1b067315 r71eef11 105 105 106 106 107 /******************** *************/107 /********************/ 108 108 /* Helper functions */ 109 /********************/ 110 109 111 static inline index_t frame_index(zone_t *zone, frame_t *frame) 110 112 { 111 return (index_t)(frame - zone->frames); 112 } 113 return (index_t) (frame - zone->frames); 114 } 115 113 116 static inline index_t frame_index_abs(zone_t *zone, frame_t *frame) 114 117 { 115 return (index_t)(frame - zone->frames) + zone->base; 116 } 118 return (index_t) (frame - zone->frames) + zone->base; 119 } 120 117 121 static inline int frame_index_valid(zone_t *zone, index_t index) 118 122 { 119 return index >= 0 && index < zone->count;123 return (index >= 0) && (index < zone->count); 120 124 } 121 125 … … 123 127 static index_t make_frame_index(zone_t *zone, frame_t *frame) 124 128 { 125 return frame - zone->frames;129 return (frame - zone->frames); 126 130 } 127 131 … … 138 142 } 139 143 140 /********************** ***************/144 /**********************/ 141 145 /* Zoneinfo functions */ 146 /**********************/ 142 147 143 148 /** … … 155 160 ipl = interrupts_disable(); 156 161 spinlock_lock(&zones.lock); 162 157 163 /* Try to merge */ 158 if (zones.count + 1 == ZONES_MAX) 159 panic("Maximum zone(%d) count exceeded.", ZONES_MAX); 164 if (zones.count + 1 == ZONES_MAX) { 165 printf("Maximum zone count %u exceeded!\n", ZONES_MAX); 166 spinlock_unlock(&zones.lock); 167 interrupts_restore(ipl); 168 return -1; 169 } 170 160 171 for (i = 0; i < zones.count; i++) { 161 172 /* Check for overflow */ 162 173 z = zones.info[i]; 163 if (overlaps(newzone->base,newzone->count, z->base, 164 z->count)) { 174 if (overlaps(newzone->base, newzone->count, z->base, z->count)) { 165 175 printf("Zones overlap!\n"); 166 176 return -1; … … 169 179 break; 170 180 } 181 171 182 /* Move other zones up */ 172 183 for (j = i; j < zones.count; j++) 173 184 zones.info[j + 1] = zones.info[j]; 185 174 186 zones.info[i] = newzone; 175 187 zones.count++; 188 176 189 spinlock_unlock(&zones.lock); 177 190 interrupts_restore(ipl); … … 182 195 /** 183 196 * Try to find a zone where can we find the frame 184 197 * 185 198 * Assume interrupts are disabled. 186 199 * 187 200 * @param frame Frame number contained in zone 188 201 * @param pzone If not null, it is used as zone hint. Zone index … … 901 914 } 902 915 903 z = (zone_t *) PA2KA(PFN2ADDR(confframe));916 z = (zone_t *) PA2KA(PFN2ADDR(confframe)); 904 917 zone_construct(start, count, z, flags); 905 918 znum = zones_add_zone(z); … … 1110 1123 1111 1124 1125 /** Return total size of all zones 1126 * 1127 */ 1128 uint64_t zone_total_size(void) { 1129 zone_t *zone = NULL; 1130 unsigned int i; 1131 ipl_t ipl; 1132 uint64_t total = 0; 1133 1134 ipl = interrupts_disable(); 1135 spinlock_lock(&zones.lock); 1136 1137 for (i = 0; i < zones.count; i++) { 1138 zone = zones.info[i]; 1139 spinlock_lock(&zone->lock); 1140 total += (uint64_t) FRAMES2SIZE(zone->count); 1141 spinlock_unlock(&zone->lock); 1142 } 1143 1144 spinlock_unlock(&zones.lock); 1145 interrupts_restore(ipl); 1146 1147 return total; 1148 } 1149 1150 1112 1151 1113 1152 /** Prints list of zones … … 1161 1200 1162 1201 for (i = 0; i < zones.count; i++) { 1163 if ( i == num || PFN2ADDR(zones.info[i]->base) == num) {1202 if ((i == num) || (PFN2ADDR(zones.info[i]->base) == num)) { 1164 1203 zone = zones.info[i]; 1165 1204 break; … … 1175 1214 printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2, 1176 1215 PFN2ADDR(zone->base)); 1177 printf("Zone size: %zd frames (%zd K)\n", zone->count,1178 ((zone->count) * FRAME_SIZE) >> 10);1179 printf("Allocated space: %zd frames (%zd K)\n", zone->busy_count,1180 (zone->busy_count * FRAME_SIZE) >> 10);1181 printf("Available space: %zd frames (%zd K)\n", zone->free_count,1182 (zone->free_count * FRAME_SIZE) >> 10);1216 printf("Zone size: %zd frames (%zd KB)\n", zone->count, 1217 SIZE2KB(FRAMES2SIZE(zone->count))); 1218 printf("Allocated space: %zd frames (%zd KB)\n", zone->busy_count, 1219 SIZE2KB(FRAMES2SIZE(zone->busy_count))); 1220 printf("Available space: %zd frames (%zd KB)\n", zone->free_count, 1221 SIZE2KB(FRAMES2SIZE(zone->free_count))); 1183 1222 buddy_system_structure_print(zone->buddy_system, FRAME_SIZE); 1184 1185 1223 spinlock_unlock(&zone->lock); 1224 1186 1225 out: 1187 1226 spinlock_unlock(&zones.lock);
Note:
See TracChangeset
for help on using the changeset viewer.