Changeset 594a468 in mainline


Ignore:
Timestamp:
2005-11-15T16:00:24Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db79676
Parents:
93354b0
Message:

Make the buddy system more general.
Store implementation defined pointer in buddy_system_t.
Pass buddy system pointer to implementation defined buddy system operations.

Location:
generic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • generic/include/mm/buddy.h

    r93354b0 r594a468  
    3535#define BUDDY_SYSTEM_INNER_BLOCK        0xff
    3636
     37/** Buddy system operations to be implemented by each implementations. */
    3738struct 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. */
    4344};
    4445
     
    4748        link_t *order;
    4849        buddy_system_operations_t *op;
     50        void *data;                             /**< Pointer to be used by the implementation. */
    4951};
    5052
    51 extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op);
     53extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data);
    5254extern link_t *buddy_system_alloc(buddy_system_t *b, __u8 i);
    5355extern void buddy_system_free(buddy_system_t *b, link_t *block);
  • generic/include/mm/frame.h

    r93354b0 r594a468  
    8787 * Buddy system operations
    8888 */
    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);
     89link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy);
     90link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block);
     91link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r);
     92void 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);
    9494
    9595__address zone_buddy_frame_alloc(int flags, __u8 order);
  • generic/src/mm/buddy.c

    r93354b0 r594a468  
    4141 * @param max_order The biggest allocable size will be 2^max_order.
    4242 * @param op Operations for new buddy system.
     43 * @param data Pointer to be used by implentation.
    4344 *
    4445 * @return New buddy system.
    4546 */
    46 buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op)
     47buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data)
    4748{
    4849        buddy_system_t *b;
     
    7778                b->max_order = max_order;
    7879                b->op = op;
     80                b->data = data;
    7981        }
    8082       
     
    131133         * Bisect the block and set order of both of its parts to i.
    132134         */
    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);
    136138       
    137139        /*
     
    159161         * Determine block's order.
    160162         */
    161         i = b->op->get_order(block);
     163        i = b->op->get_order(b, block);
    162164
    163165        ASSERT(i < b->max_order);
     
    167169                 * See if there is any buddy in the list of order i.
    168170                 */
    169                 buddy = b->op->find_buddy(block);
     171                buddy = b->op->find_buddy(b, block);
    170172                if (buddy) {
    171173
    172                         ASSERT(b->op->get_order(buddy) == i);
     174                        ASSERT(b->op->get_order(b, buddy) == i);
    173175               
    174176                        /*
     
    180182                         * Invalidate order of both block and buddy.
    181183                         */
    182                         b->op->set_order(block, BUDDY_SYSTEM_INNER_BLOCK);
    183                         b->op->set_order(buddy, 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);
    184186               
    185187                        /*
    186188                         * Coalesce block and buddy into one block.
    187189                         */
    188                         hlp = b->op->coalesce(block, buddy);
     190                        hlp = b->op->coalesce(b, block, buddy);
    189191
    190192                        /*
    191193                         * Set order of the coalesced block to i + 1.
    192194                         */
    193                         b->op->set_order(hlp, i + 1);
     195                        b->op->set_order(b, hlp, i + 1);
    194196
    195197                        /*
  • generic/src/mm/frame.c

    r93354b0 r594a468  
    339339                 */
    340340                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);
    342342        }
    343343       
     
    544544
    545545/** Buddy system find_buddy implementation
     546 *
     547 * @param b Buddy system.
    546548 * @param block Block for which buddy should be found
    547549 *
    548550 * @return Buddy for given block if found
    549551 */
    550 link_t * zone_buddy_find_buddy(link_t * block) {
     552link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) {
    551553        frame_t * frame, * f;
    552554        zone_t * zone;
     
    596598/** Buddy system bisect implementation
    597599 *
     600 * @param b Buddy system.
    598601 * @param block Block to bisect
    599602 *
    600603 * @return right block
    601604 */
    602 link_t * zone_buddy_bisect(link_t * block) {
     605link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) {
    603606        frame_t * frame_l, * frame_r;
    604607       
     
    613616/** Buddy system coalesce implementation
    614617 *
     618 * @param b Buddy system.
    615619 * @param block_1 First block
    616620 * @param block_2 First block's buddy
     
    618622 * @return Coalesced block (actually block that represents lower address)
    619623 */
    620 link_t * zone_buddy_coalesce(link_t * block_1, link_t * block_2) {
     624link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) {
    621625        frame_t * frame1, * frame2;
    622626       
     
    628632
    629633/** Buddy system set_order implementation
     634 *
     635 * @param b Buddy system.
    630636 * @param block Buddy system block
    631637 * @param order Order to set
    632638 */
    633 void zone_buddy_set_order(link_t * block, __u8 order) {
     639void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order) {
    634640        frame_t * frame;
    635641        frame = list_get_instance(block, frame_t, buddy_link);
     
    638644
    639645/** Buddy system get_order implementation
     646 *
     647 * @param b Buddy system.
    640648 * @param block Buddy system block
    641649 *
    642650 * @return Order of block
    643651 */
    644 __u8 zone_buddy_get_order(link_t * block) {
     652__u8 zone_buddy_get_order(buddy_system_t *b, link_t * block) {
    645653        frame_t * frame;
    646654        frame = list_get_instance(block, frame_t, buddy_link);
Note: See TracChangeset for help on using the changeset viewer.