Subversion Repositories HelenOS

Rev

Rev 2712 | Rev 3057 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2712 Rev 2725
Line 102... Line 102...
102
} zones_t;
102
} zones_t;
103
 
103
 
104
static zones_t zones;
104
static zones_t zones;
105
 
105
 
106
 
106
 
107
/*********************************/
107
/********************/
108
/* Helper functions */
108
/* Helper functions */
-
 
109
/********************/
-
 
110
 
109
static inline index_t frame_index(zone_t *zone, frame_t *frame)
111
static inline index_t frame_index(zone_t *zone, frame_t *frame)
110
{
112
{
111
    return (index_t)(frame - zone->frames);
113
    return (index_t) (frame - zone->frames);
112
}
114
}
-
 
115
 
113
static inline index_t frame_index_abs(zone_t *zone, frame_t *frame)
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;
118
    return (index_t) (frame - zone->frames) + zone->base;
116
}
119
}
-
 
120
 
117
static inline int frame_index_valid(zone_t *zone, index_t index)
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
 
122
/** Compute pfn_t from frame_t pointer & zone pointer */
126
/** Compute pfn_t from frame_t pointer & zone pointer */
123
static index_t make_frame_index(zone_t *zone, frame_t *frame)
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
 
128
/** Initialize frame structure
132
/** Initialize frame structure
129
 *
133
 *
130
 * Initialize frame structure.
134
 * Initialize frame structure.
Line 135... Line 139...
135
{
139
{
136
    frame->refcount = 1;
140
    frame->refcount = 1;
137
    frame->buddy_order = 0;
141
    frame->buddy_order = 0;
138
}
142
}
139
 
143
 
140
/*************************************/
144
/**********************/
141
/* Zoneinfo functions */
145
/* Zoneinfo functions */
-
 
146
/**********************/
142
 
147
 
143
/**
148
/**
144
 * Insert-sort zone into zones list
149
 * Insert-sort zone into zones list
145
 *
150
 *
146
 * @param newzone New zone to be inserted into zone list
151
 * @param newzone New zone to be inserted into zone list
Line 152... Line 157...
152
    ipl_t ipl;
157
    ipl_t ipl;
153
    zone_t *z;
158
    zone_t *z;
154
 
159
 
155
    ipl = interrupts_disable();
160
    ipl = interrupts_disable();
156
    spinlock_lock(&zones.lock);
161
    spinlock_lock(&zones.lock);
-
 
162
   
157
    /* Try to merge */
163
    /* Try to merge */
158
    if (zones.count + 1 == ZONES_MAX)
164
    if (zones.count + 1 == ZONES_MAX) {
159
        panic("Maximum zone(%d) count exceeded.", 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
    for (i = 0; i < zones.count; i++) {
171
    for (i = 0; i < zones.count; i++) {
161
        /* Check for overflow */
172
        /* Check for overflow */
162
        z = zones.info[i];
173
        z = zones.info[i];
163
        if (overlaps(newzone->base,newzone->count, z->base,
174
        if (overlaps(newzone->base, newzone->count, z->base, z->count)) {
164
            z->count)) {
-
 
165
            printf("Zones overlap!\n");
175
            printf("Zones overlap!\n");
166
            return -1;
176
            return -1;
167
        }
177
        }
168
        if (newzone->base < z->base)
178
        if (newzone->base < z->base)
169
            break;
179
            break;
170
    }
180
    }
-
 
181
   
171
    /* Move other zones up */
182
    /* Move other zones up */
172
    for (j = i; j < zones.count; j++)
183
    for (j = i; j < zones.count; j++)
173
        zones.info[j + 1] = zones.info[j];
184
        zones.info[j + 1] = zones.info[j];
-
 
185
   
174
    zones.info[i] = newzone;
186
    zones.info[i] = newzone;
175
    zones.count++;
187
    zones.count++;
-
 
188
   
176
    spinlock_unlock(&zones.lock);
189
    spinlock_unlock(&zones.lock);
177
    interrupts_restore(ipl);
190
    interrupts_restore(ipl);
178
 
191
 
179
    return i;
192
    return i;
180
}
193
}
181
 
194
 
182
/**
195
/**
183
 * Try to find a zone where can we find the frame
196
 * Try to find a zone where can we find the frame
184
 
197
 *
185
 * Assume interrupts are disabled.
198
 * Assume interrupts are disabled.
186
 
199
 *
187
 * @param frame Frame number contained in zone
200
 * @param frame Frame number contained in zone
188
 * @param pzone If not null, it is used as zone hint. Zone index
201
 * @param pzone If not null, it is used as zone hint. Zone index
189
 *              is filled into the variable on success.
202
 *              is filled into the variable on success.
190
 * @return Pointer to locked zone containing frame
203
 * @return Pointer to locked zone containing frame
191
 */
204
 */
Line 898... Line 911...
898
        }
911
        }
899
        if (confframe >= start + count)
912
        if (confframe >= start + count)
900
            panic("Cannot find configuration data for zone.");
913
            panic("Cannot find configuration data for zone.");
901
    }
914
    }
902
 
915
 
903
    z = (zone_t *)PA2KA(PFN2ADDR(confframe));
916
    z = (zone_t *) PA2KA(PFN2ADDR(confframe));
904
    zone_construct(start, count, z, flags);
917
    zone_construct(start, count, z, flags);
905
    znum = zones_add_zone(z);
918
    znum = zones_add_zone(z);
906
    if (znum == -1)
919
    if (znum == -1)
907
        return -1;
920
        return -1;
908
 
921
 
Line 1107... Line 1120...
1107
        frame_mark_unavailable(0, 1);
1120
        frame_mark_unavailable(0, 1);
1108
    }
1121
    }
1109
}
1122
}
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
/** Prints list of zones
1152
/** Prints list of zones
1114
 *
1153
 *
1115
 */
1154
 */
1116
void zone_print_list(void) {
1155
void zone_print_list(void) {
Line 1158... Line 1197...
1158
 
1197
 
1159
    ipl = interrupts_disable();
1198
    ipl = interrupts_disable();
1160
    spinlock_lock(&zones.lock);
1199
    spinlock_lock(&zones.lock);
1161
 
1200
 
1162
    for (i = 0; i < zones.count; i++) {
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
            zone = zones.info[i];
1203
            zone = zones.info[i];
1165
            break;
1204
            break;
1166
        }
1205
        }
1167
    }
1206
    }
1168
    if (!zone) {
1207
    if (!zone) {
Line 1172... Line 1211...
1172
   
1211
   
1173
    spinlock_lock(&zone->lock);
1212
    spinlock_lock(&zone->lock);
1174
    printf("Memory zone information\n");
1213
    printf("Memory zone information\n");
1175
    printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2,
1214
    printf("Zone base address: %#.*p\n", sizeof(uintptr_t) * 2,
1176
        PFN2ADDR(zone->base));
1215
        PFN2ADDR(zone->base));
1177
    printf("Zone size: %zd frames (%zdK)\n", zone->count,
1216
    printf("Zone size: %zd frames (%zd KB)\n", zone->count,
1178
        ((zone->count) * FRAME_SIZE) >> 10);
1217
        SIZE2KB(FRAMES2SIZE(zone->count)));
1179
    printf("Allocated space: %zd frames (%zdK)\n", zone->busy_count,
1218
    printf("Allocated space: %zd frames (%zd KB)\n", zone->busy_count,
1180
        (zone->busy_count * FRAME_SIZE) >> 10);
1219
        SIZE2KB(FRAMES2SIZE(zone->busy_count)));
1181
    printf("Available space: %zd frames (%zdK)\n", zone->free_count,
1220
    printf("Available space: %zd frames (%zd KB)\n", zone->free_count,
1182
        (zone->free_count * FRAME_SIZE) >> 10);
1221
        SIZE2KB(FRAMES2SIZE(zone->free_count)));
1183
    buddy_system_structure_print(zone->buddy_system, FRAME_SIZE);
1222
    buddy_system_structure_print(zone->buddy_system, FRAME_SIZE);
1184
   
-
 
1185
    spinlock_unlock(&zone->lock);
1223
    spinlock_unlock(&zone->lock);
-
 
1224
   
1186
out:
1225
out:
1187
    spinlock_unlock(&zones.lock);
1226
    spinlock_unlock(&zones.lock);
1188
    interrupts_restore(ipl);
1227
    interrupts_restore(ipl);
1189
}
1228
}
1190
 
1229