Changeset 683 for trunk/kernel/libk/user_dir.c
- Timestamp:
- Jan 13, 2021, 12:36:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/user_dir.c
r671 r683 2 2 * user_dir.c - kernel DIR related operations implementation. 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,2019 )4 * Authors Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 105 105 list_entry_t root; // root of temporary list of allocated pages 106 106 uint32_t page_id; // page index in list of physical pages 107 kmem_req_t req; // kmem request descriptor108 107 ppn_t fake_ppn; // unused, but required by hal_gptlock_pte() 109 108 uint32_t fake_attr; // unused, but required by hal_gptlock_pte() 110 109 error_t error; 110 111 #if DEBUG_USER_DIR_CREATE || DEBUG_USER_DIR_ERROR 112 uint32_t cycle = (uint32_t)hal_get_cycles(); 113 thread_t * this = CURRENT_THREAD; 114 #endif 111 115 112 116 // get cluster, local pointer, and pid of reference process … … 115 119 ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) ); 116 120 117 #if DEBUG_USER_DIR 118 uint32_t cycle = (uint32_t)hal_get_cycles(); 119 thread_t * this = CURRENT_THREAD; 120 if( cycle > DEBUG_USER_DIR ) 121 #if DEBUG_USER_DIR_CREATE 122 if( DEBUG_USER_DIR_CREATE < cycle ) 121 123 printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) and process %x / cycle %d\n", 122 124 __FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, ref_pid, cycle ); … … 133 135 134 136 // allocate memory for a local user_dir descriptor 135 req.type = KMEM_KCM; 136 req.order = bits_log2( sizeof(user_dir_t) ); 137 req.flags = AF_ZERO | AF_KERNEL; 138 dir = kmem_alloc( &req ); 137 dir = kmem_alloc( bits_log2(sizeof(user_dir_t)) , AF_ZERO ); 139 138 140 139 if( dir == NULL ) 141 140 { 142 printk("\n[ERROR] in %s : cannot allocate user_dir_t in cluster %x\n", 143 __FUNCTION__, local_cxy ); 141 142 #if DEBUG_USER_DIR_ERROR 143 printk("\n[ERROR] in %s : thread[%x,%x] cannot allocate user_dir_t in cluster %x / cycle %d\n", 144 __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); 145 #endif 144 146 return NULL; 145 147 } 146 148 147 // Build and initialize the dirent array as a list of pages.148 // For each iteration in this while loop:149 // First loop to build and initialize the dirent array 150 // as a temporary list of pages. For each iteration : 149 151 // - allocate one physical 4 Kbytes (64 dirent slots) 150 152 // - call the relevant FS specific function to scan the directory mapper, … … 162 164 { 163 165 // allocate one physical page 164 req.type = KMEM_PPM; 165 req.order = 0; 166 req.flags = AF_ZERO; 167 base = kmem_alloc( &req ); 166 base = kmem_alloc( CONFIG_PPM_PAGE_ORDER , AF_ZERO ); 168 167 169 168 if( base == NULL ) 170 169 { 171 printk("\n[ERROR] in %s : cannot allocate page in cluster %x\n", 172 __FUNCTION__, ref_cxy ); 170 171 #if DEBUG_USER_DIR_ERROR 172 printk("\n[ERROR] in %s : thread[%x,%x] cannot allocate page in cluster %x / cycle %d\n", 173 __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); 174 #endif 173 175 goto user_dir_create_failure; 174 176 } … … 184 186 if( error ) 185 187 { 186 printk("\n[ERROR] in %s : cannot initialise dirent array in cluster %x\n", 187 __FUNCTION__, ref_cxy ); 188 189 #if DEBUG_USER_DIR_ERROR 190 printk("\n[ERROR] in %s : thread[%x,%x] cannot initialize dirent array in cluster %x / cycle %d\n", 191 __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); 192 #endif 188 193 goto user_dir_create_failure; 189 194 } … … 204 209 } // end while 205 210 206 #if DEBUG_USER_DIR 207 if( cycle > DEBUG_USER_DIR)211 #if DEBUG_USER_DIR_CREATE 212 if( DEBUG_USER_DIR_CREATE < cycle ) 208 213 printk("\n[%s] thread[%x,%x] initialised dirent array / %d entries\n", 209 214 __FUNCTION__, this->process->pid, this->trdid, total_dirents, cycle ); … … 241 246 if( vseg == NULL ) 242 247 { 243 printk("\n[ERROR] in %s : cannot create vseg for user_dir in cluster %x\n", 244 __FUNCTION__, ref_cxy); 248 249 #if DEBUG_USER_DIR_ERROR 250 printk("\n[ERROR] in %s : thread[%x,%x] cannot create vseg in cluster %x / cycle %d\n", 251 __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); 252 #endif 245 253 goto user_dir_create_failure; 246 254 } 247 255 248 #if DEBUG_USER_DIR 249 if( cycle > DEBUG_USER_DIR)256 #if DEBUG_USER_DIR_CREATE 257 if( DEBUG_USER_DIR_CREATE < cycle ) 250 258 printk("\n[%s] thread[%x,%x] allocated vseg ANON / base %x / size %x\n", 251 259 __FUNCTION__, this->process->pid, this->trdid, vseg->min, vseg->max - vseg->min ); … … 269 277 vpn_base = hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_base ) ); 270 278 271 // scan the list ofallocated physical pages to map279 // Second loop on the allocated physical pages to map 272 280 // all physical pages in the reference process GPT 281 // The pages are mapped in the user process GPT, but 282 // are removed from the temporary list 283 273 284 page_id = 0; 285 274 286 while( list_is_empty( &root ) == false ) 275 287 { … … 290 302 if( error ) 291 303 { 292 printk("\n[ERROR] in %s : cannot map vpn %x in GPT\n", 293 __FUNCTION__, vpn ); 294 304 305 #if DEBUG_USER_DIR_ERROR 306 printk("\n[ERROR] in %s : thread[%x,%x] cannot map vpn %x in cluster %x / cycle %d\n", 307 __FUNCTION__, this->process->pid, this->trdid, vpn, local_cxy, cycle ); 308 #endif 295 309 // delete the vseg 296 310 intptr_t base = (intptr_t)hal_remote_lpt( XPTR( ref_cxy , &vseg->min ) ); … … 298 312 299 313 // release the user_dir descriptor 300 req.type = KMEM_KCM; 301 req.ptr = dir; 302 kmem_free( &req ); 314 kmem_free( dir , bits_log2(sizeof(user_dir_t)) ); 303 315 return NULL; 304 316 } … … 310 322 ppn ); 311 323 312 #if DEBUG_USER_DIR 313 if( cycle > DEBUG_USER_DIR)324 #if DEBUG_USER_DIR_CREATE 325 if( DEBUG_USER_DIR_CREATE < cycle ) 314 326 printk("\n[%s] thread[%x,%x] mapped vpn %x to ppn %x\n", 315 327 __FUNCTION__, this->process->pid, this->trdid, vpn + page_id, ppn ); … … 329 341 dir->current = 0; 330 342 dir->entries = total_dirents; 331 dir->ident = (intptr_t)(vpn_base << CONFIG_PPM_PAGE_ SHIFT);343 dir->ident = (intptr_t)(vpn_base << CONFIG_PPM_PAGE_ORDER); 332 344 333 345 // build extended pointers on root and lock of user_dir xlist in ref process … … 347 359 remote_queuelock_release( lock_xp ); 348 360 349 #if DEBUG_USER_DIR 350 cycle = (uint32_t)hal_get_cycles(); 351 if( cycle > DEBUG_USER_DIR ) 361 #if DEBUG_USER_DIR_CREATE 362 if( DEBUG_USER_DIR_CREATE < cycle ) 352 363 printk("\n[%s] thread[%x,%x] created user_dir (%x,%x) / %d entries / cycle %d\n", 353 364 __FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, total_dirents, cycle ); … … 358 369 user_dir_create_failure: 359 370 360 // release local user_dir_t structure 361 req.type = KMEM_KCM; 362 req.ptr = dir; 363 kmem_free( &req ); 364 365 // release local physical pages 371 // release user_dir_t structure 372 kmem_free( dir , bits_log2(sizeof(user_dir_t)) ); 373 374 // release physical pages 366 375 while( list_is_empty( &root ) == false ) 367 376 { 377 // get page descriptor 368 378 page = LIST_FIRST( &root , page_t , list ); 369 379 … … 371 381 base = GET_PTR( ppm_page2base( XPTR( local_cxy , page ) ) ); 372 382 373 req.type = KMEM_PPM; 374 req.ptr = base; 375 kmem_free( &req ); 383 // release the page 384 kmem_free( base , CONFIG_PPM_PAGE_ORDER ); 376 385 } 377 386 … … 402 411 cluster = LOCAL_CLUSTER; 403 412 413 #if DEBUG_USER_DIR_DESTROY 414 uint32_t cycle = (uint32_t)hal_get_cycles(); 415 #endif 416 404 417 // get cluster, local pointer, and PID of reference user process 405 418 ref_cxy = GET_CXY( ref_xp ); … … 407 420 ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) ); 408 421 409 #if DEBUG_USER_DIR 410 uint32_t cycle = (uint32_t)hal_get_cycles(); 411 if( cycle > DEBUG_USER_DIR ) 422 #if DEBUG_USER_DIR_DESTROY 423 if( DEBUG_USER_DIR_DESTROY < cycle ) 412 424 printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) and process %x / cycle %d\n", 413 425 __FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, ref_pid, cycle ); … … 475 487 hal_atomic_add( &responses , 1 ); 476 488 477 #if (DEBUG_USER_DIR & 1) 478 uint32_t cycle = (uint32_t)hal_get_cycles(); 479 if( cycle > DEBUG_USER_DIR ) 489 #if (DEBUG_USER_DIR_DESTROY & 1) 490 if( DEBUG_USER_DIR_DESTROY < cycle ) 480 491 printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n", 481 492 __FUNCTION__, this->process->pid, this->trdid, process_cxy ); … … 496 507 497 508 // release local user_dir_t structure 498 kmem_req_t req; 499 req.type = KMEM_KCM; 500 req.ptr = dir; 501 kmem_free( &req ); 502 503 #if DEBUG_USER_DIR 509 kmem_free( dir , bits_log2(sizeof(user_dir_t)) ); 510 511 #if DEBUG_USER_DIR_DESTROY 504 512 cycle = (uint32_t)hal_get_cycles(); 505 if( cycle > DEBUG_USER_DIR)513 if( DEBUG_USER_DIR_DESTROY < cycle ) 506 514 printk("\n[%s] thread[%x,%x] deleted user_dir (%x,%x) / cycle %d\n", 507 515 __FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, cycle );
Note: See TracChangeset
for help on using the changeset viewer.