Changeset 161
- Timestamp:
- Jul 7, 2017, 2:14:49 PM (7 years ago)
- Location:
- trunk/kernel/mm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/kcm.c
r101 r161 49 49 kcm_dmsg("\n[INFO] %s : enters for %s / page %x / count = %d / active = %d\n", 50 50 __FUNCTION__ , kmem_type_str( kcm->type ) , 51 51 (intptr_t)kcm_page , kcm_page->count , kcm_page->active ); 52 52 53 53 assert( kcm_page->active , __FUNCTION__ , "kcm_page should be active" ); … … 67 67 if( kcm_page->count >= kcm->blocks_nr ) 68 68 { 69 69 kcm_page->active = 0; 70 70 list_unlink( &kcm_page->list); 71 71 kcm->active_pages_nr --; … … 76 76 } 77 77 78 79 80 78 // compute return pointer 79 void * ptr = (void *)((intptr_t)kcm_page + CONFIG_KCM_SLOT_SIZE 80 + (index * kcm->block_size) ); 81 81 82 82 kcm_dmsg("\n[INFO] %s : allocated one block %s / ptr = %p / page = %x / count = %d\n", 83 83 __FUNCTION__ , kmem_type_str( kcm->type ) , ptr , 84 84 (intptr_t)kcm_page , kcm_page->count ); 85 85 86 86 return ptr; 87 88 } // kcm_get_block() 87 } 89 88 90 89 ///////////////////////////////////////////////////////////////////////////////////// … … 101 100 uint32_t index; 102 101 103 102 // compute pointer on kcm_page from block pointer 104 103 kcm_page = (kcm_page_t*)((intptr_t)ptr & ~CONFIG_PPM_PAGE_MASK); 105 104 106 105 // compute block index from block pointer 107 106 index = ((uint8_t *)ptr - (uint8_t *)kcm_page - CONFIG_KCM_SLOT_SIZE) / kcm->block_size; 108 107 … … 132 131 kcm->free_pages_nr ++; 133 132 } 134 } // kcm_put_block()133 } 135 134 136 135 ///////////////////////////////////////////////////////////////////////////////////// … … 174 173 175 174 return 0; 176 177 } // freelist_populate() 175 } 178 176 179 177 ///////////////////////////////////////////////////////////////////////////////////// … … 199 197 200 198 return kcm_page; 201 202 } // freelist_get() 203 199 } 204 200 205 201 ////////////////////////////// … … 207 203 uint32_t type ) 208 204 { 209 210 211 205 // the kcm_page descriptor mut fit in the KCM slot 206 assert( (sizeof(kcm_page_t) <= CONFIG_KCM_SLOT_SIZE) , 207 __FUNCTION__ , "KCM slot too small\n" ); 212 208 213 209 // initialize lock … … 225 221 list_root_init( &kcm->active_root ); 226 222 227 // initialize block size 223 // initialize block size 228 224 uint32_t block_size = ARROUND_UP( kmem_type_size( type ) , CONFIG_KCM_SLOT_SIZE ); 229 225 kcm->block_size = block_size; … … 231 227 // initialize number of blocks per page 232 228 uint32_t blocks_nr = (CONFIG_PPM_PAGE_SIZE - CONFIG_KCM_SLOT_SIZE) / block_size; 233 229 kcm->blocks_nr = blocks_nr; 234 230 235 231 kcm_dmsg("\n[INFO] %s : KCM %s initialised / block_size = %d / blocks_nr = %d\n", 236 232 __FUNCTION__ , kmem_type_str( type ) , kcm->block_size , kcm->blocks_nr ); 237 238 } // kcm_init() 233 } 239 234 240 235 /////////////////////////////// … … 276 271 // release KCM lock 277 272 spinlock_unlock( &kcm->lock ); 278 279 } // kcm_destroy() 273 } 280 274 281 275 /////////////////////////////// … … 299 293 list_add_first( &kcm->active_root , &kcm_page->list ); 300 294 kcm->active_pages_nr ++; 301 302 303 295 kcm_page->active = 1; 296 297 kcm_dmsg("\n[INFO] %s : enters for type %s at cycle %d / new page = %x / count = %d\n", 304 298 __FUNCTION__ , kmem_type_str( kcm->type ) , hal_get_cycles() , 305 299 (intptr_t)kcm_page , kcm_page->count ); 306 300 307 301 } … … 312 306 313 307 kcm_dmsg("\n[INFO] %s : enters for type %s at cycle %d / page = %x / count = %d\n", 314 __FUNCTION__ , kmem_type_str( kcm->type ) , hal_get_cycles() , 315 308 __FUNCTION__ , kmem_type_str( kcm->type ) , hal_get_cycles() , 309 (intptr_t)kcm_page , kcm_page->count ); 316 310 } 317 311 … … 324 318 325 319 return ptr; 326 327 } // end kcm_allo() 320 } 328 321 329 322 /////////////////////////// … … 346 339 // release lock 347 340 spinlock_unlock( &kcm->lock ); 348 349 } // end kcm_free() 341 } 350 342 351 343 //////////////////////////// -
trunk/kernel/mm/kcm.h
r50 r161 58 58 uint32_t active_pages_nr; /*! number of active pages */ 59 59 60 60 uint32_t type; /*! KCM type */ 61 61 } 62 62 kcm_t; … … 73 73 uint32_t bitmap[2]; /*! at most 64 blocks in a single page */ 74 74 list_entry_t list; /*! [active / busy / free] list member */ 75 kcm_t * kcm; /*! pointer on kcm allocator */ 75 kcm_t * kcm; /*! pointer on kcm allocator */ 76 76 page_t * page; /*! pointer on the physical page descriptor */ 77 77 uint32_t count; /*! number of allocated blocks */ … … 88 88 ***************************************************************************************/ 89 89 void kcm_init( kcm_t * kcm, 90 90 uint32_t type ); 91 91 92 92 /**************************************************************************************** … … 111 111 * @ ptr : local pointer on the allocated buffer. 112 112 ***************************************************************************************/ 113 void 113 void kcm_free( void * ptr ); 114 114 115 115 /**************************************************************************************** … … 120 120 void kcm_print( kcm_t * kcm ); 121 121 122 123 124 122 #endif /* _KCM_H_ */
Note: See TracChangeset
for help on using the changeset viewer.