Changeset 18 for trunk/kernel/mm/kcm.c
- Timestamp:
- Jun 3, 2017, 4:42:49 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/kcm.c
r14 r18 1 1 /* 2 2 * kcm.c - Per cluster & per type Kernel Cache Manager access functions 3 * 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Alain Greiner (2016) … … 50 50 51 51 // get first block available 52 int32_t index = bitmap_ffs( page->bitmap , kcm->blocks_nr ); 52 int32_t index = bitmap_ffs( page->bitmap , kcm->blocks_nr ); 53 53 54 54 assert( (index != -1) , __FUNCTION__ , "kcm page should not be full" ); 55 55 56 56 // allocate block 57 57 bitmap_clear( page->bitmap , index ); … … 87 87 { 88 88 kcm_page_t * page; 89 uint32_t index; 90 89 uint32_t index; 90 91 91 page = (kcm_page_t*)((intptr_t)ptr & CONFIG_PPM_PAGE_MASK); 92 92 index = ((uint8_t*)ptr - page->base) / kcm->block_size; 93 93 94 94 bitmap_set( page->bitmap , index ); 95 95 page->refcount --; 96 96 97 97 // change the page to active if it was busy 98 98 if( page->busy ) … … 121 121 ///////////////////////////////////////////////////////////////////////////////////// 122 122 // This static function allocates one page from PPM. It initializes 123 // the KCM-page descriptor, and introduces the new page into freelist. 123 // the KCM-page descriptor, and introduces the new page into freelist. 124 124 ///////////////////////////////////////////////////////////////////////////////////// 125 125 static error_t freelist_populate( kcm_t * kcm ) … … 134 134 req.flags = AF_KERNEL; 135 135 page = kmem_alloc( &req ); 136 136 137 137 if( page == NULL ) 138 138 { 139 printk("\n[ERROR] in %s : failed to allocate page in cluster %d\n", 139 printk("\n[ERROR] in %s : failed to allocate page in cluster %d\n", 140 140 __FUNCTION__ , local_cxy ); 141 141 return ENOMEM; … … 158 158 list_add_first( &kcm->free_root , &ptr->list ); 159 159 kcm->free_pages_nr ++; 160 160 161 161 return 0; 162 162 … … 179 179 } 180 180 181 // get first KCM page from freelist and change its status to active 181 // get first KCM page from freelist and change its status to active 182 182 page = LIST_FIRST( &kcm->free_root, kcm_page_t , list ); 183 183 list_unlink( &page->list ); … … 200 200 spinlock_init( &kcm->lock ); 201 201 202 // initialize KCM type 202 // initialize KCM type 203 203 kcm->type = type; 204 204 … … 219 219 kcm->blocks_nr = blocks_nr; 220 220 kcm->block_size = block_size; 221 221 222 222 kcm_dmsg("\n[INFO] %s : KCM %s initialised / block_size = %d / blocks_nr = %d\n", 223 223 __FUNCTION__ , kmem_type_str( type ) , block_size , blocks_nr ); … … 230 230 kcm_page_t * page; 231 231 list_entry_t * iter; 232 232 233 233 // get KCM lock 234 234 spinlock_lock( &kcm->lock ); … … 274 274 // get lock 275 275 spinlock_lock( &kcm->lock ); 276 276 277 277 // get an active page 278 278 if( list_is_empty( &kcm->active_root ) ) // no active page => get one … … 303 303 ptr = kcm_get_block( kcm , page ); 304 304 305 // release lock 305 // release lock 306 306 spinlock_unlock(&kcm->lock); 307 307 … … 318 318 kcm_page_t * page; 319 319 kcm_t * kcm; 320 320 321 321 if( ptr == NULL ) return; 322 322 323 323 page = (kcm_page_t *)((intptr_t)ptr & CONFIG_PPM_PAGE_MASK); 324 324 kcm = page->kcm; … … 330 330 kcm_put_block( kcm , ptr ); 331 331 332 // release lock 332 // release lock 333 333 spinlock_unlock( &kcm->lock ); 334 334 } … … 338 338 { 339 339 printk("*** KCM type = %s / free_pages = %d / busy_pages = %d / active_pages = %d\n", 340 kmem_type_str( kcm->type ) , 341 kcm->free_pages_nr , 340 kmem_type_str( kcm->type ) , 341 kcm->free_pages_nr , 342 342 kcm->busy_pages_nr , 343 343 kcm->active_pages_nr );
Note: See TracChangeset
for help on using the changeset viewer.