- Timestamp:
- Jul 7, 2017, 1:59:39 PM (7 years ago)
- Location:
- trunk/kernel/mm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/kmem.c
r124 r159 54 54 void kmem_print_kcm_table() 55 55 { 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 } // end kmem_print_kcm_table()56 uint32_t index; 57 kcm_t * kcm; 58 cluster_t * cluster = LOCAL_CLUSTER; 59 60 printk("\n *** KCM Pointers Table ***\n"); 61 62 for( index = 0 ; index < KMEM_TYPES_NR ; index++ ) 63 { 64 kcm = cluster->kcm_tbl[index]; 65 if( kcm != NULL ) 66 { 67 if( index == kcm->type ) 68 { 69 printk(" - KCM[%s] (at address %x) is OK\n", 70 kmem_type_str( index ) , (intptr_t)kcm ); 71 } 72 else 73 { 74 printk(" - KCM[%s] (at address %x) is KO : has type %s\n", 75 kmem_type_str( index ) , (intptr_t)kcm , kmem_type_str( kcm->type ) ); 76 } 77 } 78 } 79 } 80 80 81 81 ///////////////////////////////////////// 82 82 uint32_t kmem_type_size( uint32_t type ) 83 83 { 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 84 if ( type == KMEM_PAGE ) return CONFIG_PPM_PAGE_SIZE; 85 else if( type == KMEM_GENERIC ) return 0; 86 else if( type == KMEM_KCM ) return sizeof( kcm_t ); 87 else if( type == KMEM_VSEG ) return sizeof( vseg_t ); 88 else if( type == KMEM_DEVICE ) return sizeof( chdev_t ); 89 else if( type == KMEM_MAPPER ) return sizeof( mapper_t ); 90 else if( type == KMEM_PROCESS ) return sizeof( process_t ); 91 else if( type == KMEM_CPU_CTX ) return sizeof( hal_cpu_context_t ); 92 else if( type == KMEM_FPU_CTX ) return sizeof( hal_fpu_context_t ); 93 else if( type == KMEM_BARRIER ) return sizeof( remote_barrier_t ); 94 95 else if( type == KMEM_FATFS_INODE ) return sizeof( fatfs_inode_t ); 96 else if( type == KMEM_FATFS_CTX ) return sizeof( fatfs_ctx_t ); 97 else if( type == KMEM_DEVFS_INODE ) return sizeof( devfs_inode_t ); 98 else if( type == KMEM_MUTEX ) return sizeof( remote_mutex_t ); 99 else if( type == KMEM_VFS_CTX ) return sizeof( vfs_ctx_t ); 100 else if( type == KMEM_VFS_INODE ) return sizeof( vfs_inode_t ); 101 else if( type == KMEM_VFS_DENTRY ) return sizeof( vfs_dentry_t ); 102 else if( type == KMEM_VFS_FILE ) return sizeof( vfs_file_t ); 103 else if( type == KMEM_SEM ) return sizeof( remote_sem_t ); 104 else if( type == KMEM_CONDVAR ) return sizeof( remote_condvar_t ); 105 106 else if( type == KMEM_512_BYTES ) return 512; 107 108 else return 0; 109 109 } 110 110 … … 112 112 char * kmem_type_str( uint32_t type ) 113 113 { 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 114 if ( type == KMEM_PAGE ) return "KMEM_PAGE"; 115 else if( type == KMEM_GENERIC ) return "KMEM_GENERIC"; 116 else if( type == KMEM_KCM ) return "KMEM_KCM"; 117 else if( type == KMEM_VSEG ) return "KMEM_VSEG"; 118 else if( type == KMEM_DEVICE ) return "KMEM_DEVICE"; 119 else if( type == KMEM_MAPPER ) return "KMEM_MAPPER"; 120 else if( type == KMEM_PROCESS ) return "KMEM_PROCESS"; 121 else if( type == KMEM_CPU_CTX ) return "KMEM_CPU_CTX"; 122 else if( type == KMEM_FPU_CTX ) return "KMEM_FPU_CTX"; 123 else if( type == KMEM_BARRIER ) return "KMEM_BARRIER"; 124 125 else if( type == KMEM_FATFS_INODE ) return "KMEM_FATFS_INODE"; 126 else if( type == KMEM_FATFS_CTX ) return "KMEM_FATFS_CTX"; 127 else if( type == KMEM_DEVFS_INODE ) return "KMEM_DEVFS_INODE"; 128 else if( type == KMEM_MUTEX ) return "KMEM_MUTEX"; 129 else if( type == KMEM_VFS_CTX ) return "KMEM_VFS_CTX"; 130 else if( type == KMEM_VFS_INODE ) return "KMEM_VFS_INODE"; 131 else if( type == KMEM_VFS_DENTRY ) return "KMEM_VFS_DENTRY"; 132 else if( type == KMEM_VFS_FILE ) return "KMEM_VFS_FILE"; 133 else if( type == KMEM_SEM ) return "KMEM_SEM"; 134 else if( type == KMEM_SEM ) return "KMEM_CONDVAR"; 135 136 else if( type == KMEM_512_BYTES ) return "KMEM_512_BYTES"; 137 138 else return "undefined"; 139 139 } 140 140 … … 147 147 kcm_t * kcm; 148 148 149 149 assert( ((type > 1) && (type < KMEM_TYPES_NR) ) , __FUNCTION__ , "illegal KCM type" ); 150 150 151 151 kmem_dmsg("\n[INFO] %s : enters / KCM type %s missing in cluster %x\n", 152 153 154 155 156 157 152 __FUNCTION__ , kmem_type_str( type ) , local_cxy ); 153 154 cluster_t * cluster = LOCAL_CLUSTER; 155 156 // allocates memory for the requested KCM allocator 157 // from the KCM allocator embedded in cluster descriptor 158 158 kcm = kcm_alloc( &cluster->kcm ); 159 159 160 160 if( kcm == NULL ) 161 161 { 162 162 printk("\n[ERROR] in %s : failed to create KCM type %d in cluster %x\n", 163 164 165 166 167 163 __FUNCTION__ , type , local_cxy ); 164 return ENOMEM; 165 } 166 167 // initializes the new KCM allocator 168 168 kcm_init( kcm , type ); 169 169 170 170 // register it if the KCM pointers Table 171 171 cluster->kcm_tbl[type] = kcm; 172 172 … … 174 174 175 175 kmem_dmsg("\n[INFO] %s : exit / KCM type %s created in cluster %x\n", 176 176 __FUNCTION__ , kmem_type_str( type ) , local_cxy ); 177 177 178 178 return 0; 179 180 } // end kmem_create_kcm() 181 182 179 } 183 180 184 181 ///////////////////////////////////// … … 202 199 __FUNCTION__ , local_cxy , kmem_type_str( type ) ); 203 200 204 201 // analyse request type 205 202 if( type == KMEM_PAGE ) // PPM allocator 206 207 203 { 204 // allocate the number of requested pages 208 205 ptr = (void *)ppm_alloc_pages( size ); 209 206 210 207 // reset page if requested 211 208 if( flags & AF_ZERO ) page_zero( (page_t *)ptr ); 212 209 213 214 215 216 } 217 218 219 210 kmem_dmsg("\n[INFO] %s : exit in cluster %x for type %s / page = %x / base = %x\n", 211 __FUNCTION__, local_cxy , kmem_type_str( type ) , 212 (intptr_t)ptr , (intptr_t)ppm_page2base( ptr ) ); 213 } 214 else if( type == KMEM_GENERIC ) // KHM allocator 215 { 216 // allocate memory from KHM 220 217 ptr = khm_alloc( &cluster->khm , size ); 221 218 222 219 // reset memory if requested 223 220 if( flags & AF_ZERO ) memset( ptr , 0 , size ); 224 221 225 226 227 228 } 229 230 231 232 233 234 222 kmem_dmsg("\n[INFO] %s : exit in cluster %x for type %s / base = %x / size = %d\n", 223 __FUNCTION__, local_cxy , kmem_type_str( type ) , 224 (intptr_t)ptr , req->size ); 225 } 226 else // KCM allocator 227 { 228 // initialize the KCM allocator if not already done 229 if( cluster->kcm_tbl[type] == NULL ) 230 { 231 spinlock_lock( &cluster->kcm_lock ); 235 232 error_t error = kmem_create_kcm( type ); 236 237 238 239 240 241 242 243 233 spinlock_unlock( &cluster->kcm_lock ); 234 if ( error ) return NULL; 235 } 236 237 // allocate memory from KCM 238 ptr = kcm_alloc( cluster->kcm_tbl[type] ); 239 240 // reset memory if requested 244 241 if( flags & AF_ZERO ) memset( ptr , 0 , kmem_type_size( type ) ); 245 242 246 247 __FUNCTION__, local_cxy , kmem_type_str( type ) , 248 249 } 250 251 252 253 254 255 256 257 243 kmem_dmsg("\n[INFO] %s : exit in cluster %x for type %s / base = %x / size = %d\n", 244 __FUNCTION__, local_cxy , kmem_type_str( type ) , 245 (intptr_t)ptr , kmem_type_size( type ) ); 246 } 247 248 if( ptr == NULL ) 249 { 250 printk("\n[ERROR] in %s : failed for type %d / size %d in cluster %x\n", 251 __FUNCTION__ , type , size , local_cxy ); 252 253 return NULL; 254 } 258 255 259 256 return ptr; 260 261 } // end kmem_alloc() 257 } 262 258 263 259 ////////////////////////////////// … … 265 261 { 266 262 if( req->type >= KMEM_TYPES_NR ) 267 268 269 270 263 { 264 printk("\n[PANIC] in %s : illegal request type\n", __FUNCTION__ ); 265 hal_core_sleep(); 266 } 271 267 272 268 switch(req->type) 273 269 { 274 270 case KMEM_PAGE: 275 271 ppm_free_pages( (page_t*)req->ptr ); 276 272 return; 277 273 278 279 274 case KMEM_GENERIC: 275 khm_free( req->ptr ); 280 276 return; 281 277 282 278 default: 283 279 kcm_free( req->ptr ); 284 280 return; … … 286 282 } 287 283 288 -
trunk/kernel/mm/kmem.h
r50 r159 60 60 61 61 KMEM_512_BYTES = 20, /*! 512 bytes aligned */ 62 62 63 63 KMEM_TYPES_NR = 21, 64 64 };
Note: See TracChangeset
for help on using the changeset viewer.