Changeset 50 for trunk/kernel/mm/ppm.c
- Timestamp:
- Jun 26, 2017, 3:15:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/ppm.c
r18 r50 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016 )5 * Alain Greiner (2016,2017) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 48 48 } 49 49 50 //////////////////////////////////////////// 51 inline void * ppm_page2base( page_t * page ) 50 51 52 ///////////////////////////////////////////// 53 inline void * ppm_page2vaddr( page_t * page ) 52 54 { 53 55 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 ////////////////////////////////////////////// 60 inline page_t * ppm_vaddr2page( void * vaddr ) 59 61 { 60 62 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 63 67 64 68 ////////////////////////////////////////// … … 76 80 } 77 81 82 83 78 84 /////////////////////////////////////// 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 ) 85 inline 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 ////////////////////////////////////////// 92 inline 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 /////////////////////////////////////////// 101 void ppm_free_pages_nolock( page_t * page ) 92 102 { 93 103 page_t * buddy; // searched buddy page descriptor … … 95 105 page_t * current; // current (merged) page descriptor 96 106 uint32_t current_index; // current (merged) page index 97 uint32_t current_order; // current (merge t) page order107 uint32_t current_order; // current (merged) page order 98 108 99 109 ppm_t * ppm = &LOCAL_CLUSTER->ppm; … … 120 130 list_unlink( &buddy->list ); 121 131 ppm->free_pages_nr[current_order] --; 122 ppm->total_free_pages -= (1 << current_order);123 132 124 133 // merge buddy with current … … 134 143 list_add_first( &ppm->free_pages_root[current_order] , ¤t->list ); 135 144 ppm->free_pages_nr[current_order] ++; 136 ppm->total_free_pages += (1 << current_order);137 145 138 146 } // end ppm_free_pages_nolock() 139 140 //////////////////////////////141 void ppm_init( ppm_t * ppm,142 uint32_t pages_nr, // total pages number143 uint32_t pages_offset ) // occupied pages144 {145 uint32_t i;146 147 // set signature148 ppm->signature = PPM_SIGNATURE;149 150 // initialize lock protecting the free_pages[] array151 spinlock_init( &ppm->free_lock );152 153 // initialize free_pages[] array as empty154 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 empty162 list_root_init( &ppm->dirty_root );163 164 // initialize pointer on page descriptors array165 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 pages168 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 array171 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 numbers177 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 lists192 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 pages201 // to a set big pages with various order values202 }203 204 // check consistency205 ppm_assert_order( ppm );206 207 } // end ppm_init()208 147 209 148 //////////////////////////////////////////// … … 216 155 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 217 156 218 assert( (ppm->signature == PPM_SIGNATURE) , __FUNCTION__ , "PPM non initialised" );219 220 157 assert( (order < CONFIG_PPM_MAX_ORDER) , __FUNCTION__ , "illegal order argument" ); 221 158 … … 224 161 ppm_dmsg("\n[INFO] %s : enters / order = %d\n", 225 162 __FUNCTION__ , order ); 226 227 #if( CONFIG_PPM_DEBUG )228 ppm_print( ppm , "before allocation" );229 #endif230 163 231 164 // take lock protecting free lists … … 252 185 253 186 // update free-lists after removing a block 254 ppm->total_free_pages -= (1 << current_order);255 187 ppm->free_pages_nr[current_order] --; 256 188 current_size = (1 << current_order); … … 268 200 list_add_first( &ppm->free_pages_root[current_order] , &remaining_block->list ); 269 201 ppm->free_pages_nr[current_order] ++; 270 ppm->total_free_pages += (1 << current_order);271 202 } 272 203 … … 282 213 __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order ); 283 214 284 #if CONFIG_PPM_DEBUG285 ppm_print( ppm , "after allocation" );286 #endif287 288 215 return block; 289 216 } // end pmm_alloc-pages() … … 315 242 spinlock_lock( &ppm->free_lock ); 316 243 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 ); 319 246 320 247 for( order = 0 ; order < CONFIG_PPM_MAX_ORDER ; order++ )
Note: See TracChangeset
for help on using the changeset viewer.