Changeset 50 for trunk/kernel/mm/ppm.c


Ignore:
Timestamp:
Jun 26, 2017, 3:15:11 PM (5 years ago)
Author:
alain
Message:

bloup

File:
1 edited

Legend:

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

    r18 r50  
    33 *
    44 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *          Alain Greiner    (2016)
     5 *          Alain Greiner    (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    4848}
    4949
    50 ////////////////////////////////////////////
    51 inline void * ppm_page2base( page_t * page )
     50
     51
     52/////////////////////////////////////////////
     53inline void * ppm_page2vaddr( page_t * page )
    5254{
    5355        ppm_t * ppm = &LOCAL_CLUSTER->ppm;
    54         return (void*)((page - ppm->pages_tbl) << CONFIG_PPM_PAGE_SHIFT);
    55 }
    56 
    57 ////////////////////////////////////////////
    58 inline page_t * ppm_base2page( void * base )
     56        return ppm->vaddr_base + ((page - ppm->pages_tbl) << CONFIG_PPM_PAGE_SHIFT);
     57}
     58
     59//////////////////////////////////////////////
     60inline page_t * ppm_vaddr2page( void * vaddr )
    5961{
    6062        ppm_t * ppm = &LOCAL_CLUSTER->ppm;
    61         return (ppm->pages_tbl + (((uint32_t)base ) >> CONFIG_PPM_PAGE_SHIFT));
    62 }
     63        return ppm->pages_tbl + (vaddr - ppm->vaddr_base);
     64}
     65
     66
    6367
    6468//////////////////////////////////////////
     
    7680}
    7781
     82
     83
    7884///////////////////////////////////////
    79 inline void * ppm_ppn2base( ppn_t ppn )
    80 {
    81         return (void*)( ppn << CONFIG_PPM_PAGE_SHIFT );
    82 }
    83 
    84 ////////////////////////////////////////
    85 inline ppn_t ppm_base2ppn( void * base )
    86 {
    87         return (ppn_t)( (uint32_t)base >> CONFIG_PPM_PAGE_SHIFT );
    88 }
    89 
    90 //////////////////////////////////////////////////
    91 static void ppm_free_pages_nolock( page_t * page )
     85inline void * ppm_ppn2vaddr( ppn_t ppn )
     86{
     87        ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
     88        return ppm->vaddr_base + (ppn << CONFIG_PPM_PAGE_SHIFT);
     89}
     90
     91//////////////////////////////////////////
     92inline ppn_t ppm_vaddr2ppn( void * vaddr )
     93{
     94        ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
     95        return  ( (ppm->vaddr_base - vaddr) >> CONFIG_PPM_PAGE_SHIFT );
     96}
     97
     98
     99
     100///////////////////////////////////////////
     101void ppm_free_pages_nolock( page_t * page )
    92102{
    93103        page_t   * buddy;            // searched buddy page descriptor
     
    95105        page_t   * current;          // current (merged) page descriptor
    96106        uint32_t   current_index;    // current (merged) page index
    97         uint32_t   current_order;    // current (merget) page order
     107        uint32_t   current_order;    // current (merged) page order
    98108
    99109    ppm_t    * ppm         = &LOCAL_CLUSTER->ppm;
     
    120130                list_unlink( &buddy->list );
    121131                ppm->free_pages_nr[current_order] --;
    122         ppm->total_free_pages -= (1 << current_order);
    123132
    124133        // merge buddy with current
     
    134143        list_add_first( &ppm->free_pages_root[current_order] , &current->list );
    135144        ppm->free_pages_nr[current_order] ++;
    136     ppm->total_free_pages += (1 << current_order);
    137145
    138146}  // end ppm_free_pages_nolock()
    139 
    140 //////////////////////////////
    141 void ppm_init( ppm_t    * ppm,
    142                uint32_t   pages_nr,        // total pages number
    143                uint32_t   pages_offset )   // occupied pages
    144 {
    145         uint32_t   i;
    146 
    147     // set signature
    148         ppm->signature = PPM_SIGNATURE;
    149 
    150     // initialize lock protecting the free_pages[] array
    151         spinlock_init( &ppm->free_lock );
    152 
    153     // initialize free_pages[] array as empty
    154         ppm->total_free_pages = 0;
    155         for( i = 0 ; i < CONFIG_PPM_MAX_ORDER ; i++ )
    156         {
    157                 list_root_init( &ppm->free_pages_root[i] );
    158                 ppm->free_pages_nr[i] = 0;
    159         }
    160 
    161     // initialize dirty_list as empty
    162     list_root_init( &ppm->dirty_root );
    163 
    164     // initialize pointer on page descriptors array
    165         ppm->pages_tbl = (page_t*)( pages_offset << CONFIG_PPM_PAGE_SHIFT );
    166 
    167     // compute size of pages descriptor array rounded to an integer number of pages
    168     uint32_t bytes = ARROUND_UP( pages_nr * sizeof(page_t), CONFIG_PPM_PAGE_SIZE );
    169 
    170     // compute number of pages required to store page descriptor array
    171         uint32_t pages_array  = bytes >> CONFIG_PPM_PAGE_SHIFT;
    172 
    173     // compute total number of reserved pages (kernel code & pages_tbl[])
    174         uint32_t reserved_pages = pages_offset + pages_array;
    175 
    176         // set pages numbers
    177         ppm->pages_nr      = pages_nr;
    178     ppm->pages_offset  = reserved_pages;
    179 
    180     // initialises all page descriptors in pages_tbl[]
    181         for( i = 0 ; i < pages_nr ; i++ )
    182     {
    183         page_init( &ppm->pages_tbl[i] );
    184 
    185         // TODO optimisation : make only a partial init [AG]
    186         // complete the initialisation when page is allocated [AG]
    187         // ppm->pages_tbl[i].flags = 0;
    188     }
    189 
    190     // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[])
    191     // - release all other pages to populate the free lists
    192         for( i = 0 ; i < reserved_pages ; i++)
    193     {
    194         page_set_flag( &ppm->pages_tbl[i] , PG_RESERVED );
    195     }
    196         for( i = reserved_pages ; i < pages_nr ; i++ )
    197         {
    198             ppm_free_pages_nolock( &ppm->pages_tbl[i] );
    199 
    200         // TODO optimisation : decompose this enormous set of small pages
    201         // to a set big pages with various order values
    202         }
    203 
    204     // check consistency
    205     ppm_assert_order( ppm );
    206 
    207 } // end ppm_init()
    208147
    209148////////////////////////////////////////////
     
    216155    ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
    217156
    218         assert( (ppm->signature == PPM_SIGNATURE) , __FUNCTION__ , "PPM non initialised" );
    219 
    220157        assert( (order < CONFIG_PPM_MAX_ORDER) , __FUNCTION__ , "illegal order argument" );
    221158
     
    224161    ppm_dmsg("\n[INFO] %s : enters / order = %d\n",
    225162             __FUNCTION__ , order );
    226 
    227 #if( CONFIG_PPM_DEBUG )
    228 ppm_print( ppm , "before allocation" );
    229 #endif
    230163
    231164    // take lock protecting free lists
     
    252185
    253186    // update free-lists after removing a block
    254         ppm->total_free_pages -= (1 << current_order);
    255187        ppm->free_pages_nr[current_order] --;
    256188        current_size = (1 << current_order);
     
    268200                list_add_first( &ppm->free_pages_root[current_order] , &remaining_block->list );
    269201                ppm->free_pages_nr[current_order] ++;
    270         ppm->total_free_pages += (1 << current_order);
    271202        }
    272203
     
    282213             __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order );
    283214
    284 #if CONFIG_PPM_DEBUG
    285 ppm_print( ppm , "after allocation" );
    286 #endif
    287 
    288215        return block;
    289216}  // end pmm_alloc-pages()
     
    315242        spinlock_lock( &ppm->free_lock );
    316243
    317         printk("\n***  PPM state in cluster %x %s : pages = %d / offset = %d / free = %d ***\n",
    318                local_cxy , string , ppm->pages_nr , ppm->pages_offset , ppm->total_free_pages );
     244        printk("\n***  PPM in cluster %x : %d pages / &pages_tbl = %x / vaddr_base = %x ***\n",
     245               local_cxy , ppm->pages_nr , (intptr_t)ppm->pages_tbl , (intptr_t)ppm->vaddr_base );
    319246
    320247        for( order = 0 ; order < CONFIG_PPM_MAX_ORDER ; order++ )
Note: See TracChangeset for help on using the changeset viewer.