Changeset 594a468 in mainline
- Timestamp:
- 2005-11-15T16:00:24Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- db79676
- Parents:
- 93354b0
- Location:
- generic
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/mm/buddy.h
r93354b0 r594a468 35 35 #define BUDDY_SYSTEM_INNER_BLOCK 0xff 36 36 37 /** Buddy system operations to be implemented by each implementations. */ 37 38 struct buddy_system_operations { 38 link_t *(* find_buddy)( link_t *);/**< Return pointer to left-side or right-side buddy for block passed as argument. */39 link_t *(* bisect)( link_t *);/**< Bisect the block passed as argument and return pointer to the new right-side buddy. */40 link_t *(* coalesce)( link_t *, link_t *);/**< Coalesce two buddies into a bigger block. */41 void (*set_order)( link_t *, __u8);/**< Set order of block passed as argument. */42 __u8 (*get_order)( link_t *);/**< Return order of block passed as argument. */39 link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */ 40 link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */ 41 link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */ 42 void (*set_order)(buddy_system_t *, link_t *, __u8); /**< Set order of block passed as argument. */ 43 __u8 (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */ 43 44 }; 44 45 … … 47 48 link_t *order; 48 49 buddy_system_operations_t *op; 50 void *data; /**< Pointer to be used by the implementation. */ 49 51 }; 50 52 51 extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op );53 extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data); 52 54 extern link_t *buddy_system_alloc(buddy_system_t *b, __u8 i); 53 55 extern void buddy_system_free(buddy_system_t *b, link_t *block); -
generic/include/mm/frame.h
r93354b0 r594a468 87 87 * Buddy system operations 88 88 */ 89 link_t * zone_buddy_find_buddy( link_t * buddy);90 link_t * zone_buddy_bisect( link_t * block);91 link_t * zone_buddy_coalesce( link_t * buddy_l, link_t * buddy_r);92 void zone_buddy_set_order( link_t * block, __u8 order);93 __u8 zone_buddy_get_order( link_t * block);89 link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy); 90 link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block); 91 link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r); 92 void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order); 93 __u8 zone_buddy_get_order(buddy_system_t *b, link_t * block); 94 94 95 95 __address zone_buddy_frame_alloc(int flags, __u8 order); -
generic/src/mm/buddy.c
r93354b0 r594a468 41 41 * @param max_order The biggest allocable size will be 2^max_order. 42 42 * @param op Operations for new buddy system. 43 * @param data Pointer to be used by implentation. 43 44 * 44 45 * @return New buddy system. 45 46 */ 46 buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op )47 buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data) 47 48 { 48 49 buddy_system_t *b; … … 77 78 b->max_order = max_order; 78 79 b->op = op; 80 b->data = data; 79 81 } 80 82 … … 131 133 * Bisect the block and set order of both of its parts to i. 132 134 */ 133 hlp = b->op->bisect( res);134 b->op->set_order( res, i);135 b->op->set_order( hlp, i);135 hlp = b->op->bisect(b, res); 136 b->op->set_order(b, res, i); 137 b->op->set_order(b, hlp, i); 136 138 137 139 /* … … 159 161 * Determine block's order. 160 162 */ 161 i = b->op->get_order(b lock);163 i = b->op->get_order(b, block); 162 164 163 165 ASSERT(i < b->max_order); … … 167 169 * See if there is any buddy in the list of order i. 168 170 */ 169 buddy = b->op->find_buddy(b lock);171 buddy = b->op->find_buddy(b, block); 170 172 if (buddy) { 171 173 172 ASSERT(b->op->get_order(b uddy) == i);174 ASSERT(b->op->get_order(b, buddy) == i); 173 175 174 176 /* … … 180 182 * Invalidate order of both block and buddy. 181 183 */ 182 b->op->set_order(b lock, BUDDY_SYSTEM_INNER_BLOCK);183 b->op->set_order(b uddy, BUDDY_SYSTEM_INNER_BLOCK);184 b->op->set_order(b, block, BUDDY_SYSTEM_INNER_BLOCK); 185 b->op->set_order(b, buddy, BUDDY_SYSTEM_INNER_BLOCK); 184 186 185 187 /* 186 188 * Coalesce block and buddy into one block. 187 189 */ 188 hlp = b->op->coalesce(b lock, buddy);190 hlp = b->op->coalesce(b, block, buddy); 189 191 190 192 /* 191 193 * Set order of the coalesced block to i + 1. 192 194 */ 193 b->op->set_order( hlp, i + 1);195 b->op->set_order(b, hlp, i + 1); 194 196 195 197 /* -
generic/src/mm/frame.c
r93354b0 r594a468 339 339 */ 340 340 for (max_order = 0; cnt >> max_order; max_order++); 341 z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations );341 z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations, (void *) z); 342 342 } 343 343 … … 544 544 545 545 /** Buddy system find_buddy implementation 546 * 547 * @param b Buddy system. 546 548 * @param block Block for which buddy should be found 547 549 * 548 550 * @return Buddy for given block if found 549 551 */ 550 link_t * zone_buddy_find_buddy( link_t * block) {552 link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) { 551 553 frame_t * frame, * f; 552 554 zone_t * zone; … … 596 598 /** Buddy system bisect implementation 597 599 * 600 * @param b Buddy system. 598 601 * @param block Block to bisect 599 602 * 600 603 * @return right block 601 604 */ 602 link_t * zone_buddy_bisect( link_t * block) {605 link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) { 603 606 frame_t * frame_l, * frame_r; 604 607 … … 613 616 /** Buddy system coalesce implementation 614 617 * 618 * @param b Buddy system. 615 619 * @param block_1 First block 616 620 * @param block_2 First block's buddy … … 618 622 * @return Coalesced block (actually block that represents lower address) 619 623 */ 620 link_t * zone_buddy_coalesce( link_t * block_1, link_t * block_2) {624 link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) { 621 625 frame_t * frame1, * frame2; 622 626 … … 628 632 629 633 /** Buddy system set_order implementation 634 * 635 * @param b Buddy system. 630 636 * @param block Buddy system block 631 637 * @param order Order to set 632 638 */ 633 void zone_buddy_set_order( link_t * block, __u8 order) {639 void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order) { 634 640 frame_t * frame; 635 641 frame = list_get_instance(block, frame_t, buddy_link); … … 638 644 639 645 /** Buddy system get_order implementation 646 * 647 * @param b Buddy system. 640 648 * @param block Buddy system block 641 649 * 642 650 * @return Order of block 643 651 */ 644 __u8 zone_buddy_get_order( link_t * block) {652 __u8 zone_buddy_get_order(buddy_system_t *b, link_t * block) { 645 653 frame_t * frame; 646 654 frame = list_get_instance(block, frame_t, buddy_link);
Note:
See TracChangeset
for help on using the changeset viewer.