Changeset 160 for trunk/kernel/mm


Ignore:
Timestamp:
Jul 7, 2017, 2:03:01 PM (7 years ago)
Author:
max@…
Message:

style

Location:
trunk/kernel/mm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/ppm.c

    r53 r160  
    3838#include <ppm.h>
    3939
    40 
    41 
    4240////////////////////////////////////////////////
    4341inline bool_t ppm_page_is_valid( page_t * page )
    4442{
    45     ppm_t    * ppm  = &LOCAL_CLUSTER->ppm;
     43        ppm_t    * ppm  = &LOCAL_CLUSTER->ppm;
    4644        uint32_t   pgnr = (uint32_t)( page - ppm->pages_tbl );
    4745        return (pgnr <= ppm->pages_nr);
     
    4947
    5048
    51 
    5249/////////////////////////////////////////////
    5350inline void * ppm_page2vaddr( page_t * page )
     
    6461}
    6562
    66 
    67 
    6863//////////////////////////////////////////
    6964inline ppn_t ppm_page2ppn( page_t * page )
    7065{
    71         ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
     66        ppm_t  * ppm = &LOCAL_CLUSTER->ppm;
    7267        return (ppn_t)( page - ppm->pages_tbl );
    7368}
     
    7671inline page_t * ppm_ppn2page( ppn_t ppn )
    7772{
    78         ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
     73        ppm_t  * ppm = &LOCAL_CLUSTER->ppm;
    7974        return &ppm->pages_tbl[ppn];
    8075}
    81 
    82 
    8376
    8477///////////////////////////////////////
     
    9386{
    9487        ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
    95         return  ( (ppm->vaddr_base - vaddr) >> CONFIG_PPM_PAGE_SHIFT );
    96 }
    97 
     88        return ( (ppm->vaddr_base - vaddr) >> CONFIG_PPM_PAGE_SHIFT );
     89}
    9890
    9991
     
    10799        uint32_t   current_order;    // current (merged) page order
    108100
    109     ppm_t    * ppm         = &LOCAL_CLUSTER->ppm;
    110     page_t   * pages_tbl   = ppm->pages_tbl;
    111 
    112     // update released page descriptor flags
     101        ppm_t    * ppm         = &LOCAL_CLUSTER->ppm;
     102        page_t   * pages_tbl   = ppm->pages_tbl;
     103
     104        // update released page descriptor flags
    113105        page_set_flag( page , PG_FREE );
    114106
    115     // search the buddy page descriptor
    116     // - merge with current page descriptor if found
    117     // - exit to release the current page descriptor if not found
    118     current       = page ,
    119     current_index = (uint32_t)(page - ppm->pages_tbl);
     107        // search the buddy page descriptor
     108        // - merge with current page descriptor if found
     109        // - exit to release the current page descriptor if not found
     110        current       = page ,
     111        current_index = (uint32_t)(page - ppm->pages_tbl);
    120112        for( current_order = page->order ;
    121          current_order < CONFIG_PPM_MAX_ORDER ;
    122          current_order++ )
    123     {
     113             current_order < CONFIG_PPM_MAX_ORDER ;
     114             current_order++ )
     115        {
    124116                buddy_index = current_index ^ (1 << current_order);
    125117                buddy       = pages_tbl + buddy_index;
     
    127119                if( !page_is_flag( buddy , PG_FREE ) || (buddy->order != current_order) ) break;
    128120
    129         // remove buddy from free list
     121                // remove buddy from free list
    130122                list_unlink( &buddy->list );
    131123                ppm->free_pages_nr[current_order] --;
    132124
    133         // merge buddy with current
     125                // merge buddy with current
    134126                buddy->order = 0;
    135127                current_index &= buddy_index;
    136128        }
    137129
    138     // update merged page descriptor order
     130        // update merged page descriptor order
    139131        current        = pages_tbl + current_index;
    140132        current->order = current_order;
    141133
    142     // insert current in free list
     134        // insert current in free list
    143135        list_add_first( &ppm->free_pages_root[current_order] , &current->list );
    144136        ppm->free_pages_nr[current_order] ++;
    145 
    146 }  // end ppm_free_pages_nolock()
     137}
    147138
    148139////////////////////////////////////////////
    149140page_t * ppm_alloc_pages( uint32_t   order )
    150141{
    151     uint32_t   current_order;
     142        uint32_t   current_order;
    152143        page_t   * remaining_block;
    153144        uint32_t   current_size;
    154145
    155     ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
     146        ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
    156147
    157148        assert( (order < CONFIG_PPM_MAX_ORDER) , __FUNCTION__ , "illegal order argument" );
     
    159150        page_t * block = NULL;
    160151
    161     ppm_dmsg("\n[INFO] %s : enters / order = %d\n",
    162              __FUNCTION__ , order );
    163 
    164     // take lock protecting free lists
     152        ppm_dmsg("\n[INFO] %s : enters / order = %d\n",
     153                 __FUNCTION__ , order );
     154
     155        // take lock protecting free lists
    165156        spinlock_lock( &ppm->free_lock );
    166157
    167     // find a free block equal or larger to requested size
     158        // find a free block equal or larger to requested size
    168159        for( current_order = order ; current_order < CONFIG_PPM_MAX_ORDER ; current_order ++ )
    169160        {
     
    178169        if( block == NULL ) // return failure
    179170        {
    180         // release lock protecting free lists
    181             spinlock_unlock( &ppm->free_lock );
    182 
    183         return NULL;
    184     }
    185 
    186     // update free-lists after removing a block
     171                // release lock protecting free lists
     172                spinlock_unlock( &ppm->free_lock );
     173
     174                return NULL;
     175        }
     176
     177        // update free-lists after removing a block
    187178        ppm->free_pages_nr[current_order] --;
    188179        current_size = (1 << current_order);
    189180
    190     // split the removed block in smaller sub-blocks if required
    191     // and update the free-lists accordingly
     181        // split the removed block in smaller sub-blocks if required
     182        // and update the free-lists accordingly
    192183        while( current_order > order )
    193184        {
     
    202193        }
    203194
    204     // update page descriptor
    205     page_clear_flag( block , PG_FREE );
     195        // update page descriptor
     196        page_clear_flag( block , PG_FREE );
    206197        page_refcount_up( block );
    207198        block->order = order;
    208199
    209     // release lock protecting free lists
     200        // release lock protecting free lists
    210201        spinlock_unlock( &ppm->free_lock );
    211202
    212     ppm_dmsg("\n[INFO] %s : base = %x / order = %d\n",
    213              __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order );
     203        ppm_dmsg("\n[INFO] %s : base = %x / order = %d\n",
     204                 __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order );
    214205
    215206        return block;
    216 }  // end pmm_alloc-pages()
     207}
    217208
    218209
     
    222213        ppm_t * ppm = &LOCAL_CLUSTER->ppm;
    223214
    224     // get lock protecting free_pages[] array
     215        // get lock protecting free_pages[] array
    225216        spinlock_lock( &ppm->free_lock );
    226217
    227218        ppm_free_pages_nolock( page );
    228219
    229     // release lock protecting free_pages[] array
     220        // release lock protecting free_pages[] array
    230221        spinlock_unlock( &ppm->free_lock );
    231222}
     
    239230        page_t       * page;
    240231
    241     // get lock protecting free lists
     232        // get lock protecting free lists
    242233        spinlock_lock( &ppm->free_lock );
    243234
     
    248239        {
    249240                printk("- order = %d / free_pages = %d  [",
    250                order , ppm->free_pages_nr[order] );
     241                       order , ppm->free_pages_nr[order] );
    251242
    252243                LIST_FOREACH( &ppm->free_pages_root[order] , iter )
     
    259250        }
    260251
    261     // release lock protecting free lists
     252        // release lock protecting free lists
    262253        spinlock_unlock( &ppm->free_lock );
    263 
    264 }  // end ppm_print()
     254}
    265255
    266256///////////////////////////////////////
     
    279269                        page = LIST_ELEMENT( iter , page_t , list );
    280270
    281                         if( page->order != order )  return -1; 
     271                        if( page->order != order )  return -1;
    282272                }
    283273        }
    284274
    285     return 0;
    286 
    287 }  // end ppm_assert_order()
    288 
     275        return 0;
     276}
     277
  • trunk/kernel/mm/ppm.h

    r53 r160  
    4848 *   architecture specific bootloader. The reserved pages are defined in the boot_info
    4949 *   structure.
    50  * 
     50 *
    5151 * The main service provided by the PMM is the dynamic allocation of physical pages
    5252 * from the "kernel_heap" section.
     
    6464    spinlock_t     dirty_lock;              /*! lock protecting the dirty pages list    */
    6565    list_entry_t   dirty_root;              /*! root of dirty pages list                */
    66     void         * vaddr_base;              /*! pointer on local physical memory base   */ 
     66    void         * vaddr_base;              /*! pointer on local physical memory base   */
    6767}
    6868ppm_t;
Note: See TracChangeset for help on using the changeset viewer.