Rev 552 | Rev 615 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 552 | Rev 564 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2005 Jakub Jermar |
- | 3 | * Copyright (C) 2005 Sergey Bondari |
|
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * are met: |
Line 223... | Line 224... | ||
223 | { |
224 | { |
224 | index_t index; |
225 | index_t index; |
225 | index = zone_blacklist_count++; |
226 | index = zone_blacklist_count++; |
226 | 227 | ||
227 | /* Force base to the nearest lower address frame boundary. */ |
228 | /* Force base to the nearest lower address frame boundary. */ |
228 | base &= ~(FRAME_SIZE - 1); |
229 | base = ALIGN_DOWN(base, FRAME_SIZE); |
229 | /* Align size to frame boundary. */ |
230 | /* Align size to frame boundary. */ |
230 | size = ALIGN(size, FRAME_SIZE); |
231 | size = ALIGN_UP(size, FRAME_SIZE); |
231 | 232 | ||
232 | ASSERT(zone_blacklist_count <= ZONE_BLACKLIST_SIZE); |
233 | ASSERT(index < ZONE_BLACKLIST_SIZE); |
233 | zone_blacklist[index].base = base; |
234 | zone_blacklist[index].base = base; |
234 | zone_blacklist[index].size = size; |
235 | zone_blacklist[index].size = size; |
235 | } |
236 | } |
236 | 237 | ||
237 | 238 | ||
Line 282... | Line 283... | ||
282 | } |
283 | } |
283 | 284 | ||
284 | z = zone_create(base, size, 0); |
285 | z = zone_create(base, size, 0); |
285 | 286 | ||
286 | if (!z) { |
287 | if (!z) { |
287 | panic("Cannot allocate zone (%dB).\n", size); |
288 | panic("Cannot allocate zone (base=%P, size=%d).\n", base, size); |
288 | } |
289 | } |
289 | 290 | ||
290 | zone_attach(z); |
291 | zone_attach(z); |
291 | } |
292 | } |
292 | 293 | ||
Line 391... | Line 392... | ||
391 | * @return Buddy for given block if found |
392 | * @return Buddy for given block if found |
392 | */ |
393 | */ |
393 | link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) { |
394 | link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) { |
394 | frame_t * frame; |
395 | frame_t * frame; |
395 | zone_t * zone; |
396 | zone_t * zone; |
396 | count_t index; |
397 | index_t index; |
397 | bool is_left, is_right; |
398 | bool is_left, is_right; |
398 | 399 | ||
399 | frame = list_get_instance(block, frame_t, buddy_link); |
400 | frame = list_get_instance(block, frame_t, buddy_link); |
400 | zone = (zone_t *) b->data; |
401 | zone = (zone_t *) b->data; |
401 | 402 | ||
- | 403 | ASSERT(IS_BUDDY_ORDER_OK(FRAME_INDEX(zone, frame), frame->buddy_order)); |
|
- | 404 | ||
402 | is_left = IS_BUDDY_LEFT_BLOCK(zone, frame); |
405 | is_left = IS_BUDDY_LEFT_BLOCK(zone, frame); |
- | 406 | is_right = IS_BUDDY_RIGHT_BLOCK(zone, frame); |
|
- | 407 | ||
403 | is_right = !is_left; |
408 | ASSERT(is_left ^ is_right); |
404 | 409 | ||
405 | /* |
- | |
406 | * test left buddy |
- | |
407 | */ |
- | |
408 | if (is_left) { |
410 | if (is_left) { |
409 | index = (FRAME_INDEX(zone, frame)) + (1 << frame->buddy_order); |
411 | index = (FRAME_INDEX(zone, frame)) + (1 << frame->buddy_order); |
410 | } else if (is_right) { |
412 | } else if (is_right) { |
411 | index = (FRAME_INDEX(zone, frame)) - (1 << frame->buddy_order); |
413 | index = (FRAME_INDEX(zone, frame)) - (1 << frame->buddy_order); |
412 | } |
414 | } |
Line 428... | Line 430... | ||
428 | * |
430 | * |
429 | * @return right block |
431 | * @return right block |
430 | */ |
432 | */ |
431 | link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) { |
433 | link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) { |
432 | frame_t * frame_l, * frame_r; |
434 | frame_t * frame_l, * frame_r; |
- | 435 | ||
433 | frame_l = list_get_instance(block, frame_t, buddy_link); |
436 | frame_l = list_get_instance(block, frame_t, buddy_link); |
434 | frame_r = (frame_l + (1 << (frame_l->buddy_order - 1))); |
437 | frame_r = (frame_l + (1 << (frame_l->buddy_order - 1))); |
- | 438 | ||
435 | return &frame_r->buddy_link; |
439 | return &frame_r->buddy_link; |
436 | } |
440 | } |
437 | 441 | ||
438 | /** Buddy system coalesce implementation |
442 | /** Buddy system coalesce implementation |
439 | * |
443 | * |
Line 443... | Line 447... | ||
443 | * |
447 | * |
444 | * @return Coalesced block (actually block that represents lower address) |
448 | * @return Coalesced block (actually block that represents lower address) |
445 | */ |
449 | */ |
446 | link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) { |
450 | link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) { |
447 | frame_t * frame1, * frame2; |
451 | frame_t * frame1, * frame2; |
- | 452 | ||
448 | frame1 = list_get_instance(block_1, frame_t, buddy_link); |
453 | frame1 = list_get_instance(block_1, frame_t, buddy_link); |
449 | frame2 = list_get_instance(block_2, frame_t, buddy_link); |
454 | frame2 = list_get_instance(block_2, frame_t, buddy_link); |
- | 455 | ||
450 | return frame1 < frame2 ? block_1 : block_2; |
456 | return frame1 < frame2 ? block_1 : block_2; |
451 | } |
457 | } |
452 | 458 | ||
453 | /** Buddy system set_order implementation |
459 | /** Buddy system set_order implementation |
454 | * |
460 | * |