Changeset 18 for trunk/kernel/mm/ppm.c
- Timestamp:
- Jun 3, 2017, 4:42:49 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/ppm.c
r14 r18 56 56 57 57 //////////////////////////////////////////// 58 inline page_t * ppm_base2page( void * base ) 58 inline page_t * ppm_base2page( void * base ) 59 59 { 60 60 ppm_t * ppm = &LOCAL_CLUSTER->ppm; … … 105 105 // search the buddy page descriptor 106 106 // - merge with current page descriptor if found 107 // - exit to release the current page descriptor if not found 108 current = page , 107 // - exit to release the current page descriptor if not found 108 current = page , 109 109 current_index = (uint32_t)(page - ppm->pages_tbl); 110 for( current_order = page->order ; 110 for( current_order = page->order ; 111 111 current_order < CONFIG_PPM_MAX_ORDER ; 112 112 current_order++ ) … … 114 114 buddy_index = current_index ^ (1 << current_order); 115 115 buddy = pages_tbl + buddy_index; 116 116 117 117 if( !page_is_flag( buddy , PG_FREE ) || (buddy->order != current_order) ) break; 118 118 119 // remove buddy from free list 119 // remove buddy from free list 120 120 list_unlink( &buddy->list ); 121 121 ppm->free_pages_nr[current_order] --; 122 122 ppm->total_free_pages -= (1 << current_order); 123 123 124 124 // merge buddy with current 125 125 buddy->order = 0; 126 126 current_index &= buddy_index; 127 127 } 128 128 129 129 // update merged page descriptor order 130 130 current = pages_tbl + current_index; … … 162 162 list_root_init( &ppm->dirty_root ); 163 163 164 // initialize pointer on page descriptors array 164 // initialize pointer on page descriptors array 165 165 ppm->pages_tbl = (page_t*)( pages_offset << CONFIG_PPM_PAGE_SHIFT ); 166 166 … … 174 174 uint32_t reserved_pages = pages_offset + pages_array; 175 175 176 // set pages numbers 176 // set pages numbers 177 177 ppm->pages_nr = pages_nr; 178 178 ppm->pages_offset = reserved_pages; … … 180 180 // initialises all page descriptors in pages_tbl[] 181 181 for( i = 0 ; i < pages_nr ; i++ ) 182 { 182 { 183 183 page_init( &ppm->pages_tbl[i] ); 184 184 … … 186 186 // complete the initialisation when page is allocated [AG] 187 187 // ppm->pages_tbl[i].flags = 0; 188 } 189 190 // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[]) 188 } 189 190 // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[]) 191 191 // - release all other pages to populate the free lists 192 for( i = 0 ; i < reserved_pages ; i++) 192 for( i = 0 ; i < reserved_pages ; i++) 193 193 { 194 194 page_set_flag( &ppm->pages_tbl[i] , PG_RESERVED ); … … 250 250 return NULL; 251 251 } 252 253 // update free-lists after removing a block 252 253 // update free-lists after removing a block 254 254 ppm->total_free_pages -= (1 << current_order); 255 ppm->free_pages_nr[current_order] --; 255 ppm->free_pages_nr[current_order] --; 256 256 current_size = (1 << current_order); 257 257 … … 262 262 current_order --; 263 263 current_size >>= 1; 264 264 265 265 remaining_block = block + current_size; 266 266 remaining_block->order = current_order; … … 270 270 ppm->total_free_pages += (1 << current_order); 271 271 } 272 272 273 273 // update page descriptor 274 274 page_clear_flag( block , PG_FREE ); … … 278 278 // release lock protecting free lists 279 279 spinlock_unlock( &ppm->free_lock ); 280 280 281 281 ppm_dmsg("\n[INFO] %s : base = %x / order = %d\n", 282 282 __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order ); … … 294 294 { 295 295 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 296 296 297 297 // get lock protecting free_pages[] array 298 298 spinlock_lock( &ppm->free_lock ); 299 299 300 ppm_free_pages_nolock( page ); 300 ppm_free_pages_nolock( page ); 301 301 302 302 // release lock protecting free_pages[] array … … 316 316 317 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 ); 319 318 local_cxy , string , ppm->pages_nr , ppm->pages_offset , ppm->total_free_pages ); 319 320 320 for( order = 0 ; order < CONFIG_PPM_MAX_ORDER ; order++ ) 321 321 { 322 322 printk("- order = %d / free_pages = %d [", 323 323 order , ppm->free_pages_nr[order] ); 324 324 325 325 LIST_FOREACH( &ppm->free_pages_root[order] , iter ) 326 326 { … … 328 328 printk("%d," , page - ppm->pages_tbl ); 329 329 } 330 330 331 331 printk("]\n", NULL ); 332 332 } … … 336 336 337 337 } // end ppm_print() 338 338 339 339 //////////////////////////u///////// 340 340 void ppm_assert_order( ppm_t * ppm ) … … 343 343 list_entry_t * iter; 344 344 page_t * page; 345 345 346 346 for(order=0; order < CONFIG_PPM_MAX_ORDER; order++) 347 347 { 348 348 if( list_is_empty( &ppm->free_pages_root[order] ) ) continue; 349 349 350 350 LIST_FOREACH( &ppm->free_pages_root[order] , iter ) 351 351 {
Note: See TracChangeset
for help on using the changeset viewer.