Changeset 469
- Timestamp:
- Aug 20, 2018, 1:04:16 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 54 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/core/hal_exception.c
r459 r469 146 146 147 147 // restore FPU registers from requesting thread context 148 hal_fpu_context_restore( this ->fpu_context);148 hal_fpu_context_restore( this ); 149 149 150 150 // attach the FPU to the requesting thread … … 155 155 { 156 156 // restore FPU registers from requesting thread context 157 hal_fpu_context_restore( this ->fpu_context);157 hal_fpu_context_restore( this ); 158 158 159 159 // attach the FPU to the requesting thread … … 218 218 if( DEBUG_HAL_EXCEPTIONS < cycle ) 219 219 printk("\n[DBG] %s : thread %x in process %x enter / is_ins %d / %s / vaddr %x / cycle %d\n", 220 __FUNCTION__, this->trdid, process->pid, is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle); 220 __FUNCTION__, this->trdid, process->pid, 221 is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle); 221 222 #endif 222 223 … … 235 236 if( error ) 236 237 { 237 printk("\n[ERROR] in %s for thread %x : cannot map vaddr = %x\n", 238 __FUNCTION__ , this->trdid , bad_vaddr ); 238 printk("\n[USER ERROR] in %s for thread %x in process %x\n" 239 " cannot map vaddr = %x / is_ins %d / epc %x\n", 240 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); 239 241 240 242 return EXCP_USER_ERROR; … … 256 258 case MMU_READ_PRIVILEGE_VIOLATION: 257 259 { 258 printk("\n[ERROR] in %s for thread %x : illegal user access to vaddr = %x\n", 259 __FUNCTION__ , this->trdid , bad_vaddr ); 260 printk("\n[USER ERROR] in %s for thread %x in process %x\n" 261 " illegal user access to vaddr = %x / is_ins %d / epc %x\n", 262 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); 260 263 261 264 return EXCP_USER_ERROR; … … 275 278 if( error ) 276 279 { 277 printk("\n[ERROR] in %s for thread %x : cannot cow vaddr = %x\n", 278 __FUNCTION__ , this->trdid , bad_vaddr ); 280 printk("\n[USER ERROR] in %s for thread %x in process %x\n" 281 " cannot cow vaddr = %x / is_ins %d / epc %x\n", 282 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); 279 283 280 284 return EXCP_USER_ERROR; … … 295 299 else // non writable user error 296 300 { 297 printk("\n[ERROR] in %s for thread %x : non-writable vaddr = %x\n", 298 __FUNCTION__ , this->trdid , bad_vaddr ); 301 printk("\n[USER ERROR] in %s for thread %x in process %x\n" 302 " non-writable vaddr = %x / is_ins %d / epc %x\n", 303 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); 299 304 300 305 return EXCP_USER_ERROR; … … 303 308 case MMU_READ_EXEC_VIOLATION: // user error 304 309 { 305 printk("\n[ERROR] in %s for thread %x : read to non-executable vaddr = %x\n", 306 __FUNCTION__ , this->trdid , bad_vaddr ); 310 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 311 " non-executable vaddr = %x / is_ins %d / epc %x\n", 312 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC ); 307 313 308 314 return EXCP_USER_ERROR; 309 315 } 310 default: // this is a kernel error => panic311 { 312 assert( false , __FUNCTION__ ,313 " thread %x in process %x / epc %x / badvaddr %x / cycle%d\n",314 this->trdid, this->process->pid, excPC, bad_vaddr, (uint32_t)hal_get_cycles());316 default: // this is a kernel error 317 { 318 printk("\n[KERNEL ERROR] in %s for thread %x in process %x\n" 319 " epc %x / badvaddr %x / is_ins %d\n", 320 __FUNCTION__, this->trdid, this->process->pid, excPC, bad_vaddr, is_ins ); 315 321 316 322 return EXCP_KERNEL_PANIC; … … 353 359 else 354 360 { 355 nolock_printk("\n=== KERNEL PANIC/ trdid %x / pid %x / core[%x,%d] / cycle %d ===\n",361 nolock_printk("\n=== KERNEL ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n", 356 362 this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() ); 357 363 } … … 415 421 switch(excCode) 416 422 { 417 case XCODE_DBE: // can be non fatal423 case XCODE_DBE: // Data Bus Error : can be non fatal if page fault 418 424 { 419 425 error = hal_mmu_exception( this , excPC , false ); // data MMU exception 420 426 break; 421 427 } 422 case XCODE_IBE: // can be non fatal428 case XCODE_IBE: // Instruction Bus Error : can be non fatal if page fault 423 429 { 424 430 error = hal_mmu_exception( this , excPC , true ); // ins MMU exception 425 431 break; 426 432 } 427 case XCODE_CPU: // can be non fatal428 { 429 if( ((uzone[UZ_CR] >> 28) & 0x3) == 1 ) // FPU433 case XCODE_CPU: // Coprocessor unavailable : can be non fatal if FPU 434 { 435 if( ((uzone[UZ_CR] >> 28) & 0x3) == 1 ) // FPU 430 436 { 431 error = hal_fpu_exception( this ); // FPU exception437 error = hal_fpu_exception( this ); 432 438 } 433 else 439 else // undefined coprocessor 434 440 { 441 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 442 " undefined coprocessor / epc %x\n", 443 __FUNCTION__, this->trdid, this->process->pid, excPC ); 444 435 445 error = EXCP_USER_ERROR; 436 446 } 437 447 break; 438 448 } 439 case XCODE_OVR: // user fatal error 440 case XCODE_RI: // user fatal error 449 case XCODE_OVR: // Arithmetic Overflow : user fatal error 450 { 451 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 452 " arithmetic overflow / epc %x\n", 453 __FUNCTION__, this->trdid, this->process->pid, excPC ); 454 455 error = EXCP_USER_ERROR; 456 break; 457 } 458 case XCODE_RI: // Reserved Instruction : user fatal error 459 { 460 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 461 " reserved instruction / epc %x\n", 462 __FUNCTION__, this->trdid, this->process->pid, excPC ); 463 464 error = EXCP_USER_ERROR; 465 break; 466 } 441 467 case XCODE_ADEL: // user fatal error 442 case XCODE_ADES: // user fatal error 443 { 468 { 469 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 470 " illegal data load address / epc %x\n", 471 __FUNCTION__, this->trdid, this->process->pid, excPC ); 472 473 error = EXCP_USER_ERROR; 474 break; 475 } 476 case XCODE_ADES: // user fatal error 477 { 478 printk("\n[USER_ERROR] in %s for thread %x in process %x\n" 479 " illegal data store address / epc %x\n", 480 __FUNCTION__, this->trdid, this->process->pid, excPC ); 481 444 482 error = EXCP_USER_ERROR; 445 483 break; … … 462 500 hal_exception_dump( this , uzone , error ); 463 501 464 assert( false , __FUNCTION__ , "thread %x in process %x on core [%x,%d]", 465 this , this->process->pid , local_cxy , this->core->lid ); 502 assert( false , __FUNCTION__ , "core[%x,%d] blocked\n", local_cxy, this->core->lid ); 466 503 } 467 504 -
trunk/kernel/kern/printk.c
r459 r469 407 407 408 408 // call nolock_printk to print core, function_name, and cycle 409 nolock_printk("\n[PANIC] on core[%x,%d] in %sat cycle %d : " ,410 local_cxy, CURRENT_THREAD->core->lid, function_name, (uint32_t)hal_get_cycles() );409 nolock_printk("\n[PANIC] in %s => core[%x,%d] blocked at cycle %d : " , 410 function_name, local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() ); 411 411 412 412 // call kernel_printf on TXT0, in busy waiting to print format -
trunk/kernel/kern/process.c
r459 r469 1163 1163 } 1164 1164 1165 #if DEBUG_PROCESS_MAKE_FORK1165 #if( DEBUG_PROCESS_MAKE_FORK & 1 ) 1166 1166 cycle = (uint32_t)hal_get_cycles(); 1167 1167 if( DEBUG_PROCESS_MAKE_FORK < cycle ) … … 1240 1240 "main thread must have LTID == 0\n" ); 1241 1241 1242 #if( DEBUG_PROCESS_MAKE_FORK & 1 ) 1242 //#if( DEBUG_PROCESS_MAKE_FORK & 1 ) 1243 #if DEBUG_PROCESS_MAKE_FORK 1243 1244 cycle = (uint32_t)hal_get_cycles(); 1244 1245 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1245 printk("\n[DBG] %s : thread %x in process %x created main thread %x on core[%x,%d] / cycle %d\n", 1246 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, 1247 thread, local_cxy, thread->core->lid, cycle ); 1246 printk("\n[DBG] %s : thread %x in process %x created main thread %x / cycle %d\n", 1247 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, thread, cycle ); 1248 1248 #endif 1249 1249 … … 1342 1342 1343 1343 #if (DEBUG_PROCESS_MAKE_EXEC & 1) 1344 cycle = (uint32_t)hal_get_cycles(); 1344 1345 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1345 printk("\n[DBG] %s : open file <%s>\n", __FUNCTION__, path ); 1346 printk("\n[DBG] %s : thread %x in process %x opened file <%s> / cycle %d\n", 1347 __FUNCTION__, thread->trdid, pid, path, cycle ); 1346 1348 #endif 1347 1349 … … 1349 1351 process_sigaction( pid , DELETE_ALL_THREADS ); 1350 1352 1353 #if (DEBUG_PROCESS_MAKE_EXEC & 1) 1354 cycle = (uint32_t)hal_get_cycles(); 1355 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1356 printk("\n[DBG] %s : thread %x in process %x deleted all threads / cycle %d\n", 1357 __FUNCTION__, thread->trdid, pid, cycle ); 1358 #endif 1359 1351 1360 // reset local process VMM 1352 1361 vmm_destroy( process ); … … 1355 1364 cycle = (uint32_t)hal_get_cycles(); 1356 1365 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1357 printk("\n[DBG] %s : thread %x in process %x /reset VMM / cycle %d\n",1366 printk("\n[DBG] %s : thread %x in process %x reset VMM / cycle %d\n", 1358 1367 __FUNCTION__, thread->trdid, pid, cycle ); 1359 1368 #endif … … 1400 1409 if( error ) 1401 1410 { 1402 printk("\n[ERROR] in %s : cannot resetmain thread for %s\n", __FUNCTION__ , path );1411 printk("\n[ERROR] in %s : cannot update main thread for %s\n", __FUNCTION__ , path ); 1403 1412 vfs_close( file_xp , file_id ); 1404 1413 // FIXME restore old process VMM -
trunk/kernel/kern/scheduler.c
r462 r469 63 63 list_root_init( &sched->k_root ); 64 64 65 // init spinlock 66 spinlock_init( &sched->lock ); 67 65 68 sched->req_ack_pending = false; // no pending request 66 69 sched->trace = false; // context switches trace desactivated -
trunk/kernel/kern/thread.c
r457 r469 86 86 // return pointer on new thread descriptor 87 87 xptr_t base_xp = ppm_page2base( XPTR(local_cxy , page ) ); 88 return (thread_t *)GET_PTR( base_xp );88 return GET_PTR( base_xp ); 89 89 90 90 } // end thread_alloc() … … 419 419 uint32_t cycle = (uint32_t)hal_get_cycles(); 420 420 if( DEBUG_THREAD_USER_FORK < cycle ) 421 printk("\n[DBG] %s : thread %x enter / child_process %x / cycle %d\n",422 __FUNCTION__, CURRENT_THREAD , child_process->pid, cycle );421 printk("\n[DBG] %s : thread %x in process %x enter / child_process %x / cycle %d\n", 422 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, child_process->pid, cycle ); 423 423 #endif 424 424 … … 428 428 // get cluster and local pointer on parent thread descriptor 429 429 parent_cxy = GET_CXY( parent_thread_xp ); 430 parent_ptr = (thread_t *)GET_PTR( parent_thread_xp );430 parent_ptr = GET_PTR( parent_thread_xp ); 431 431 432 432 // get relevant fields from parent thread … … 538 538 if( mapped ) 539 539 { 540 // get pointers on the page descriptor 540 541 xptr_t page_xp = ppm_ppn2page( ppn ); 541 542 cxy_t page_cxy = GET_CXY( page_xp ); 542 page_t * page_ptr = (page_t *)GET_PTR( page_xp ); 543 page_t * page_ptr = GET_PTR( page_xp ); 544 545 // get extended pointers on forks and lock fields 546 xptr_t forks_xp = XPTR( page_cxy , &page_ptr->forks ); 547 xptr_t lock_xp = XPTR( page_cxy , &page_ptr->lock ); 548 549 // increment the forks counter 550 remote_spinlock_lock( lock_xp ); 543 551 hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , 1 ); 552 remote_spinlock_unlock( lock_xp ); 544 553 545 554 #if (DEBUG_THREAD_USER_FORK & 1) 546 555 cycle = (uint32_t)hal_get_cycles(); 547 556 if( DEBUG_THREAD_USER_FORK < cycle ) 548 printk("\n[DBG] %s : thread %x copied stack PTE to child GPT : vpn %x\n", 549 __FUNCTION__, CURRENT_THREAD, vpn ); 557 printk("\n[DBG] %s : thread %x in process %x copied one PTE to child GPT : vpn %x / forks %d\n", 558 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, vpn, 559 hal_remote_lw( XPTR( page_cxy , &page_ptr->forks) ) ); 550 560 #endif 551 561 … … 561 571 cycle = (uint32_t)hal_get_cycles(); 562 572 if( DEBUG_THREAD_USER_FORK < cycle ) 563 printk("\n[DBG] %s : thread %x exit / child_process %x/ child_thread %x / cycle %d\n",564 __FUNCTION__, CURRENT_THREAD , child_process->pid, child_ptr, cycle );573 printk("\n[DBG] %s : thread %x in process %x exit / child_thread %x / cycle %d\n", 574 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, child_ptr, cycle ); 565 575 #endif 566 576 … … 631 641 } 632 642 633 // update user stack in stackdescriptor643 // update user stack in thread descriptor 634 644 thread->u_stack_base = vseg->min; 635 645 thread->u_stack_size = vseg->max - vseg->min; … … 1172 1182 { 1173 1183 target_process_xp = XLIST_ELEMENT( iter , process_t , local_list ); 1174 target_process_ptr = (process_t *)GET_PTR( target_process_xp );1184 target_process_ptr = GET_PTR( target_process_xp ); 1175 1185 target_process_pid = hal_remote_lw( XPTR( target_cxy , &target_process_ptr->pid ) ); 1176 1186 if( target_process_pid == pid ) -
trunk/kernel/kernel_config.h
r459 r469 123 123 #define DEBUG_SYSCALLS_ERROR 2 124 124 125 #define DEBUG_SYS_CLOSE 2125 #define DEBUG_SYS_CLOSE 0 126 126 #define DEBUG_SYS_DISPLAY 0 127 127 #define DEBUG_SYS_EXEC 0 128 #define DEBUG_SYS_EXIT 1128 #define DEBUG_SYS_EXIT 0 129 129 #define DEBUG_SYS_FG 0 130 130 #define DEBUG_SYS_FORK 0 … … 133 133 #define DEBUG_SYS_IS_FG 0 134 134 #define DEBUG_SYS_KILL 0 135 #define DEBUG_SYS_OPEN 2135 #define DEBUG_SYS_OPEN 0 136 136 #define DEBUG_SYS_MMAP 0 137 137 #define DEBUG_SYS_READ 0 … … 189 189 190 190 #define CONFIG_KERNEL_IDENTITY_MAP true // True for 32 bits cores 191 #define CONFIG_MAX_CLUSTER 191 #define CONFIG_MAX_CLUSTERS 256 // max number of clusters 192 192 #define CONFIG_MAX_LOCAL_CORES 4 // max number of cores per cluster 193 193 #define CONFIG_MAX_INT_DEV 4 // max number of internal peripherals … … 206 206 #define CONFIG_MAX_DMA_CHANNELS 4 // max number of DMA device channels 207 207 #define CONFIG_MAX_NIC_CHANNELS 4 // max number of NIC device channels 208 209 #define CONFIG_MAX_CLUSTERS 256 // max number of clusters210 208 211 209 #define CONFIG_TXT_ECHO_MODE 1 // echo mode for TXT peripheral -
trunk/kernel/libk/remote_sem.c
r457 r469 43 43 // get cluster and local pointer on reference process 44 44 cxy_t ref_cxy = GET_CXY( ref_xp ); 45 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );45 process_t * ref_ptr = GET_PTR( ref_xp ); 46 46 47 47 // get extended pointer on root of semaphores list … … 60 60 sem_xp = XLIST_ELEMENT( iter_xp , remote_sem_t , list ); 61 61 sem_cxy = GET_CXY( sem_xp ); 62 sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );62 sem_ptr = GET_PTR( sem_xp ); 63 63 ident = (intptr_t)hal_remote_lpt( XPTR( sem_cxy , &sem_ptr->ident ) ); 64 64 65 if( ident == vaddr ) 65 66 { -
trunk/kernel/mm/page.h
r457 r469 56 56 * This structure defines a physical page descriptor. 57 57 * Size is 64 bytes for a 32 bits core... 58 * The spinlock is used to test/modify the forks counter. 58 59 * TODO : the list of waiting threads seems to be unused [AG] 59 $ TODO : the spinlock use has to be clarified [AG]60 * TODO : the refcount use has to be clarified 60 61 ************************************************************************************/ 61 62 … … 70 71 uint32_t refcount; /*! reference counter (4) */ 71 72 uint32_t forks; /*! number of pending forks (4) */ 72 spinlock_t lock; /*! To Be Defined [AG] (16)*/73 spinlock_t lock; /*! protect the forks field (4) */ 73 74 } 74 75 page_t; -
trunk/kernel/mm/vmm.c
r457 r469 411 411 page_t * page_ptr; 412 412 xptr_t forks_xp; 413 xptr_t lock_xp; 413 414 414 415 // update flags in remote GPT … … 433 434 if( attr & GPT_MAPPED ) 434 435 { 436 // get pointers and cluster on page descriptor 435 437 page_xp = ppm_ppn2page( ppn ); 436 438 page_cxy = GET_CXY( page_xp ); 437 439 page_ptr = GET_PTR( page_xp ); 440 441 // get extended pointers on "forks" and "lock" 438 442 forks_xp = XPTR( page_cxy , &page_ptr->forks ); 443 lock_xp = XPTR( page_cxy , &page_ptr->lock ); 444 445 // increment "forks" 446 remote_spinlock_lock( lock_xp ); 439 447 hal_remote_atomic_add( forks_xp , 1 ); 448 remote_spinlock_unlock( lock_xp ); 440 449 } 441 450 } // end loop on vpn … … 473 482 vpn_t vpn_base; 474 483 vpn_t vpn_size; 475 xptr_t page_xp; 484 xptr_t page_xp; // extended pointer on page descriptor 476 485 page_t * page_ptr; 477 486 cxy_t page_cxy; 487 xptr_t forks_xp; // extended pointer on forks counter in page descriptor 488 xptr_t lock_xp; // extended pointer on lock protecting the forks counter 478 489 xptr_t parent_root_xp; 479 490 bool_t mapped; … … 592 603 if( mapped ) 593 604 { 594 page_xp = ppm_ppn2page( ppn ); 605 // get pointers and cluster on page descriptor 606 page_xp = ppm_ppn2page( ppn ); 595 607 page_cxy = GET_CXY( page_xp ); 596 608 page_ptr = GET_PTR( page_xp ); 597 hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , 1 ); 609 610 // get extended pointers on "forks" and "lock" 611 forks_xp = XPTR( page_cxy , &page_ptr->forks ); 612 lock_xp = XPTR( page_cxy , &page_ptr->lock ); 613 614 // increment "forks" 615 remote_spinlock_lock( lock_xp ); 616 hal_remote_atomic_add( forks_xp , 1 ); 617 remote_spinlock_unlock( lock_xp ); 598 618 599 619 #if DEBUG_VMM_FORK_COPY … … 603 623 __FUNCTION__ , CURRENT_THREAD , vpn , cycle ); 604 624 #endif 605 606 625 } 607 626 } … … 670 689 if( DEBUG_VMM_DESTROY < cycle ) 671 690 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n", 672 __FUNCTION__ , CURRENT_THREAD , process->pid , local_cxy, cycle );691 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, local_cxy, cycle ); 673 692 #endif 674 693 … … 695 714 vseg = GET_PTR( vseg_xp ); 696 715 697 #if( DEBUG_VMM_DESTROY & 1 )698 if( DEBUG_VMM_DESTROY < cycle )699 printk("\n[DBG] %s : found %s vseg / vpn_base %x / vpn_size %d\n",700 __FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );701 #endif702 716 // unmap and release physical pages 703 717 vmm_unmap_vseg( process , vseg ); … … 751 765 if( DEBUG_VMM_DESTROY < cycle ) 752 766 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n", 753 __FUNCTION__ , CURRENT_THREAD , process->pid, local_cxy , cycle );767 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, local_cxy , cycle ); 754 768 #endif 755 769 … … 1069 1083 page_t * page_ptr; // page descriptor pointer 1070 1084 xptr_t forks_xp; // extended pointer on pending forks counter 1071 uint32_t count; // actual number of pendinf forks 1085 xptr_t lock_xp; // extended pointer on lock protecting forks counter 1086 uint32_t forks; // actual number of pendinf forks 1072 1087 1073 1088 #if DEBUG_VMM_UNMAP_VSEG … … 1115 1130 page_ptr = GET_PTR( page_xp ); 1116 1131 1117 // FIXME lock the physical page 1132 // get extended pointers on forks and lock fields 1133 forks_xp = XPTR( page_cxy , &page_ptr->forks ); 1134 lock_xp = XPTR( page_cxy , &page_ptr->lock ); 1135 1136 // get lock protecting page descriptor 1137 remote_spinlock_lock( lock_xp ); 1118 1138 1119 1139 // get pending forks counter 1120 count = hal_remote_lw( XPTR( page_cxy , &page_ptr->forks ));1140 forks = hal_remote_lw( forks_xp ); 1121 1141 1122 if( count) // decrement pending forks counter1142 if( forks ) // decrement pending forks counter 1123 1143 { 1124 forks_xp = XPTR( page_cxy , &page_ptr->forks );1125 1144 hal_remote_atomic_add( forks_xp , -1 ); 1126 1145 } … … 1139 1158 } 1140 1159 1141 // FIXME unlock the physical page 1160 // release lock protecting page descriptor 1161 remote_spinlock_unlock( lock_xp ); 1142 1162 } 1143 1163 } … … 1418 1438 #if DEBUG_VMM_GET_ONE_PPN 1419 1439 thread_t * this = CURRENT_THREAD; 1420 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1421 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1440 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1422 1441 printk("\n[DBG] %s : thread %x enter for vpn = %x / type = %s / index = %d\n", 1423 1442 __FUNCTION__, this, vpn, vseg_type_str(type), index ); … … 1482 1501 1483 1502 #if (DEBUG_VMM_GET_ONE_PPN & 0x1) 1484 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1485 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1503 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1486 1504 printk("\n[DBG] %s : thread %x for vpn = %x / elf_offset = %x\n", 1487 1505 __FUNCTION__, this, vpn, elf_offset ); … … 1499 1517 1500 1518 #if (DEBUG_VMM_GET_ONE_PPN & 0x1) 1501 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1502 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1519 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1503 1520 printk("\n[DBG] %s : thread%x for vpn = %x / fully in BSS\n", 1504 1521 __FUNCTION__, this, vpn ); … … 1519 1536 1520 1537 #if (DEBUG_VMM_GET_ONE_PPN & 0x1) 1521 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1522 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1538 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1523 1539 printk("\n[DBG] %s : thread %x, for vpn = %x / fully in mapper\n", 1524 1540 __FUNCTION__, this, vpn ); … … 1551 1567 1552 1568 #if (DEBUG_VMM_GET_ONE_PPN & 0x1) 1553 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1554 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1569 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1555 1570 printk("\n[DBG] %s : thread %x for vpn = %x / both mapper & BSS\n" 1556 1571 " %d bytes from mapper / %d bytes from BSS\n", … … 1599 1614 1600 1615 #if DEBUG_VMM_GET_ONE_PPN 1601 // if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1602 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1616 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() ) 1603 1617 printk("\n[DBG] %s : thread %x exit for vpn = %x / ppn = %x\n", 1604 1618 __FUNCTION__ , this , vpn , *ppn ); … … 1628 1642 #if DEBUG_VMM_GET_PTE 1629 1643 uint32_t cycle = (uint32_t)hal_get_cycles(); 1630 // if( DEBUG_VMM_GET_PTE < cycle ) 1631 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1632 printk("\n[DBG] %s : thread %x enter / vpn %x / process %x / cow %d / cycle %d\n", 1633 __FUNCTION__ , this , vpn , process->pid , cow , cycle ); 1644 if( DEBUG_VMM_GET_PTE < cycle ) 1645 printk("\n[DBG] %s : thread %x in process %x enter / vpn %x / cow %d / cycle %d\n", 1646 __FUNCTION__, this->trdid, process->pid, vpn, cow, cycle ); 1634 1647 #endif 1635 1648 … … 1644 1657 // vseg has been checked by the vmm_handle_page_fault() function 1645 1658 assert( (vseg != NULL) , __FUNCTION__, 1646 "vseg undefined / vpn %x / thread %x /process %x / core[%x,%d] / cycle %d\n",1647 vpn, this , process->pid, local_cxy, this->core->lid,1659 "vseg undefined / vpn %x / thread %x in process %x / core[%x,%d] / cycle %d\n", 1660 vpn, this->trdid, process->pid, local_cxy, this->core->lid, 1648 1661 (uint32_t)hal_get_cycles() ); 1649 1662 … … 1658 1671 1659 1672 assert( (old_attr & GPT_MAPPED), __FUNCTION__, 1660 "PTE unmapped for a COW exception / vpn %x / thread %x /process %x / cycle %d\n",1673 "PTE unmapped for a COW exception / vpn %x / thread %x in process %x / cycle %d\n", 1661 1674 vpn, this, process->pid, (uint32_t)hal_get_cycles() ); 1662 1675 1663 1676 #if( DEBUG_VMM_GET_PTE & 1 ) 1664 // if( DEBUG_VMM_GET_PTE < cycle ) 1665 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1666 printk("\n[DBG] %s : thread %x handling COW for vpn %x in process %x\n", 1667 __FUNCTION__, this, vpn, process->pid ); 1677 if( DEBUG_VMM_GET_PTE < cycle ) 1678 printk("\n[DBG] %s : thread %x in process %x handling COW for vpn %x\n", 1679 __FUNCTION__, this->trdid, process->pid, vpn ); 1668 1680 #endif 1669 1681 … … 1673 1685 page_t * page_ptr = GET_PTR( page_xp ); 1674 1686 1687 // get extended pointers on forks and lock field in page descriptor 1688 xptr_t forks_xp = XPTR( page_cxy , &page_ptr->forks ); 1689 xptr_t lock_xp = XPTR( page_cxy , &page_ptr->lock ); 1690 1691 // take lock protecting page descriptor 1692 remote_spinlock_lock( lock_xp ); 1693 1675 1694 // get number of pending forks in page descriptor 1676 uint32_t forks = hal_remote_lw( XPTR( page_cxy , &page_ptr->forks ));1695 uint32_t forks = hal_remote_lw( forks_xp ); 1677 1696 1678 1697 if( forks ) // pending fork => allocate a new page, copy old to new … … 1696 1715 GET_PTR( old_base_xp ), 1697 1716 CONFIG_PPM_PAGE_SIZE ); 1717 1718 // decrement pending forks counter in page descriptor 1719 hal_remote_atomic_add( forks_xp , -1 ); 1698 1720 } 1699 else // no pending fork => keep the existing page , reset COW1721 else // no pending fork => keep the existing page 1700 1722 { 1701 1723 new_ppn = old_ppn; 1702 1724 } 1703 1725 1726 // release lock protecting page descriptor 1727 remote_spinlock_unlock( lock_xp ); 1728 1704 1729 // build new_attr : reset COW and set WRITABLE, 1705 1730 new_attr = (old_attr | GPT_WRITABLE) & (~GPT_COW); … … 1707 1732 // update GPT[vpn] for all GPT copies 1708 1733 vmm_global_update_pte( process, vpn, new_attr, new_ppn ); 1709 1710 // decrement pending forks counter in page descriptor1711 hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , -1 );1712 1734 } 1713 1735 else //////////// page_fault request /////////////////////////// … … 1724 1746 1725 1747 #if( DEBUG_VMM_GET_PTE & 1 ) 1726 // if( DEBUG_VMM_GET_PTE < cycle ) 1727 if( (vpn == 0x403) && ((local_cxy == 0) || (this->type == THREAD_RPC)) ) 1728 printk("\n[DBG] %s : thread %x handling page fault for vpn %x in process %x\n", 1729 __FUNCTION__, this, vpn, process->pid ); 1748 if( DEBUG_VMM_GET_PTE < cycle ) 1749 printk("\n[DBG] %s : thread %x in process %x handling page fault for vpn %x\n", 1750 __FUNCTION__, this->trdid, process->pid, vpn ); 1730 1751 #endif 1731 1752 // allocate new_ppn, and initialize the new page … … 1767 1788 #if DEBUG_VMM_GET_PTE 1768 1789 cycle = (uint32_t)hal_get_cycles(); 1769 // if( DEBUG_VMM_GET_PTE < cycle ) 1770 if( (vpn == 0x403) && (local_cxy == 0) ) 1771 printk("\n[DBG] %s : thread %x exit / vpn %x in process %x / ppn %x / attr %x / cycle %d\n", 1772 __FUNCTION__, this, vpn, process->pid, new_ppn, new_attr, cycle ); 1790 if( DEBUG_VMM_GET_PTE < cycle ) 1791 printk("\n[DBG] %s : thread %x in process %x exit / vpn %x / ppn %x / attr %x / cycle %d\n", 1792 __FUNCTION__, this->trdid, process->pid, vpn, new_ppn, new_attr, cycle ); 1773 1793 #endif 1774 1794 … … 1797 1817 #if DEBUG_VMM_HANDLE_PAGE_FAULT 1798 1818 uint32_t cycle = (uint32_t)hal_get_cycles(); 1799 // if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1800 if( (vpn == 0x403) && (local_cxy == 0) ) 1819 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1801 1820 printk("\n[DBG] %s : thread %x in process %x enter for vpn %x / core[%x,%d] / cycle %d\n", 1802 1821 __FUNCTION__, this, process->pid, vpn, local_cxy, this->core->lid, cycle ); … … 1836 1855 1837 1856 #if DEBUG_VMM_HANDLE_PAGE_FAULT 1838 // if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1839 if( (vpn == 0x403) && (local_cxy == 0) ) 1857 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1840 1858 printk("\n[DBG] %s : thread %x in process %x call RPC_VMM_GET_PTE\n", 1841 1859 __FUNCTION__, this, process->pid ); … … 1870 1888 #if DEBUG_VMM_HANDLE_PAGE_FAULT 1871 1889 cycle = (uint32_t)hal_get_cycles(); 1872 // if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1873 if( (vpn == 0x403) && (local_cxy == 0) ) 1890 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle ) 1874 1891 printk("\n[DBG] %s : thread %x in process %x exit for vpn %x / core[%x,%d] / cycle %d\n", 1875 1892 __FUNCTION__, this, process->pid, vpn, local_cxy, this->core->lid, cycle ); -
trunk/kernel/mm/vmm.h
r457 r469 166 166 * valid GPT entries in parent GPT are copied to the child GPT. The COW flag is not set. 167 167 * - no STACK vseg is copied from parent VMM to child VMM, because the child STACK vseg 168 * must be copied from the cluster containing the user thread requesting the fork().168 * must be copied later from the cluster containing the user thread requesting the fork(). 169 169 ********************************************************************************************* 170 170 * @ child_process : local pointer on local child process descriptor. -
trunk/kernel/syscalls/sys_read.c
r459 r469 231 231 tm_end = hal_get_cycles(); 232 232 if( DEBUG_SYS_READ < tm_end ) 233 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n" 234 "nbytes %d / file_id %d / cost %d\n", 235 __FUNCTION__ , this->trdid, process->pid, 236 (uint32_t)tm_start , nbytes , file_id , (uint32_t)(tm_end - tm_start) ); 233 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d / cost %d\n", 234 __FUNCTION__ , this->trdid, process->pid, (uint32_t)tm_start, (uint32_t)(tm_end - tm_start) ); 237 235 #endif 238 236 -
trunk/kernel/syscalls/sys_sem.c
r457 r469 74 74 75 75 #if DEBUG_SYSCALLS_ERROR 76 printk("\n[ERROR] in %s : unmapped semaphore pointer %x / thread %x in process %x \n",77 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );76 printk("\n[ERROR] in %s : unmapped semaphore pointer %x / thread %x in process %x / cycle %d\n", 77 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 78 78 vmm_display( process , false ); 79 79 #endif … … 97 97 98 98 #if DEBUG_SYSCALLS_ERROR 99 printk("\n[ERROR] in %s : cannot create semaphore / thread %x in process %x\n",100 __FUNCTION__, this->trdid, process->pid );99 printk("\n[ERROR] in %s INIT: cannot create semaphore / thread %x in process %x / cycle %d\n", 100 __FUNCTION__, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 101 101 #endif 102 102 this->errno = ENOMEM; … … 115 115 116 116 #if DEBUG_SYSCALLS_ERROR 117 printk("\n[ERROR] in %s : unmapped buffer for current value %x / thread %x in process %x\n",118 __FUNCTION__ , (intptr_t)current_value, this->trdid, process->pid );117 printk("\n[ERROR] in %s GETVALUE: unmapped target buffer %x / thread %x in process %x / cycle %d\n", 118 __FUNCTION__ , (intptr_t)current_value, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 119 119 vmm_display( process , false ); 120 120 #endif … … 131 131 132 132 #if DEBUG_SYSCALLS_ERROR 133 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",134 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );133 printk("\n[ERROR] in %s GETVALUE: semaphore %x not found / thread %x in process %x / cycle %d\n", 134 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 135 135 #endif 136 136 this->errno = EINVAL; … … 157 157 158 158 #if DEBUG_SYSCALLS_ERROR 159 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n", 160 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 159 printk("\n[ERROR] in %s WAIT: semaphore %x not found / thread %x in process %x / cycle %d\n", 160 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 161 vmm_display( process , true ); 161 162 #endif 162 163 this->errno = EINVAL; … … 180 181 181 182 #if DEBUG_SYSCALLS_ERROR 182 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",183 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );183 printk("\n[ERROR] in %s POST: semaphore %x not found / thread %x in process %x / cycle %d\n", 184 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 184 185 #endif 185 186 this->errno = EINVAL; … … 203 204 204 205 #if DEBUG_SYSCALLS_ERROR 205 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n",206 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );206 printk("\n[ERROR] in %s DESTROY: semaphore %x not found / thread %x in process %x / cycle %d\n", 207 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 207 208 #endif 208 209 this->errno = EINVAL; … … 220 221 221 222 #if DEBUG_SYSCALLS_ERROR 222 printk("\n[ERROR] in %s : undefined operation type %d / thread %x in process %x \n",223 __FUNCTION__ , operation, this->trdid, process->pid );223 printk("\n[ERROR] in %s : undefined operation type %d / thread %x in process %x / cycle %d\n", 224 __FUNCTION__ , operation, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 224 225 #endif 225 226 this->errno = EINVAL; -
trunk/kernel/syscalls/sys_write.c
r459 r469 61 61 reg_t save_sr; // required to enable IRQs during syscall 62 62 63 #if (DEBUG_SYS_WRITE & 1)64 enter_sys_write = (uint32_t)tm_start;65 #endif66 67 63 thread_t * this = CURRENT_THREAD; 68 64 process_t * process = this->process; … … 77 73 #endif 78 74 75 #if (DEBUG_SYS_WRITE & 1) 76 enter_sys_write = (uint32_t)tm_start; 77 #endif 78 79 79 // check file_id argument 80 80 if( file_id >= CONFIG_PROCESS_FILE_MAX_NR ) … … 195 195 tm_end = hal_get_cycles(); 196 196 if( DEBUG_SYS_WRITE < tm_end ) 197 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n" 198 "nbytes %d / file_id %d / cost %d\n", 199 __FUNCTION__, this->trdid, process->pid, (uint32_t)tm_start, 200 nbytes, file_id , (uint32_t)(tm_end - tm_start) ); 197 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d / cost %d\n", 198 __FUNCTION__, this->trdid, process->pid, (uint32_t)tm_start, (uint32_t)(tm_end - tm_start) ); 201 199 #endif 202 200 -
trunk/user/ksh/ksh.c
r459 r469 1 /////////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////////////////// 2 2 // File : ksh.c 3 3 // Date : October 2017 4 4 // Author : Alain Greiner 5 /////////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////////////////// 6 6 // This application implements a minimal shell for ALMOS-MKH. 7 7 // 8 8 // This user KSH process contains two POSIX threads: 9 9 // - the "main" thread contains the infinite loop implementing 10 // the children processes termination monitoring using the wait syscall. 11 // - the "interactive" thread contains the infinite loop implementing 12 // the command interpreter attached to the TXT terminal. 13 // This "interactive" thread block and deschedules when the KSH process 14 // loses the TXT terminal ownership. It is reactivated when the KSH 15 // process returns in background. 10 // the children processes termination monitoring, using the wait syscall. 11 // - the "interactive" thread contains the infinite loop implementing the command 12 // interpreter attached to the TXT terminal, and handling one KSH command 13 // per iteration. 16 14 // 17 // Note: the children processes are created by the <load> command, and are15 // The children processes are created by the <load> command, and are 18 16 // attached to the same TXT terminal as the KSH process itself. 19 // . A child process can be lauched in foreground: the KSH process loses 20 // the TXT terminal ownership, that is transfered to the new process. 21 // . A child process can be lauched in background: the KSH process keeps 22 // the TXT terminal ownership. that is transfered to the new process. 23 /////////////////////////////////////////////////////////////////////////////// 17 // A child process can be lauched in foreground or in background: 18 // . when the child process is running in foreground, the KSH process loses 19 // the TXT terminal ownership, that is transfered to the child process. 20 // . when the child process is running in background: the KSH process keeps 21 // the TXT terminal ownership. 22 // 23 // A semaphore is used to synchronize the two KSH threads. At each iteration, 24 // the interactive thread check the semaphore (with a sem_wait). It blocks 25 // and deschedules, if the KSH process loosed the TXT ownership (after a load, 26 // or for any other cause. It unblocks with the following policy: 27 // . if the command is "not a load", the semaphore is incremented by the 28 // cmd_***() function when the command is completed, to allow the KSH interactive() 29 // function to get the next command in the while loop. 30 // . if the command is a "load without &", the TXT is given to the NEW process by the 31 // execve() syscall, and is released to the KSH process when NEW process terminates. 32 // The KSH process is notified and the KSH main() function increments the semahore 33 // to allow the KSH interactive() function to handle commands. 34 // . if the command is a "load with &", the cmd_load() function returns the TXT 35 // to the KSH process and increment the semaphore, when the parent KSH process 36 // returns from the fork() syscall. 37 ///////////////////////////////////////////////////////////////////////////////////////// 24 38 25 39 #include <stdio.h> … … 37 51 #define FIFO_SIZE (1024) // FIFO depth for recursive ls 38 52 39 #define KSH_DEBUG 0 40 41 //////////////////////////////////////////////////////////////////////////////// 53 #define KSH_DEBUG 0 54 #define CMD_LOAD_DEBUG 0 55 56 ////////////////////////////////////////////////////////////////////////////////////////// 42 57 // Structures 43 //////////////////////////////////////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////////////////////////// 44 59 45 60 // one entry in the registered commands array … … 61 76 62 77 63 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////////////// 64 79 // Global Variables 65 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////////////// 66 81 67 82 ksh_cmd_t cmd[]; // array of supported commands … … 76 91 sem_t semaphore; // block interactive thread when zero 77 92 78 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////////////// 79 94 // Shell Commands 80 //////////////////////////////////////////////////////////////////////////////// 95 ////////////////////////////////////////////////////////////////////////////////////////// 81 96 82 97 ///////////////////////////////////////////// … … 454 469 if( (argc < 2) || (argc > 3) ) 455 470 { 456 printf(" usage: %s pathname [&] \n", argv[0] );471 printf(" usage: %s pathname [&] / argc = %d\n", argv[0], argc ); // @@@ 457 472 return; 458 473 } … … 466 481 ksh_pid = getpid(); 467 482 468 #if KSH_DEBUG 469 printf("\n[KSH_DEBUG] in %s : ksh PID %x / path %s / background %d\n", 470 __FUNCTION__, ksh_pid, argv[1], background ); 483 #if CMD_LOAD_DEBUG 484 long long unsigned cycle; 485 get_cycle( &cycle ); 486 printf("\n@@@ %s : KSH PID %x before fork / path %s / background %d / cycle %d\n", 487 __FUNCTION__, ksh_pid, argv[1], background, (int)cycle ); 471 488 #endif 472 489 … … 481 498 else if (ret_fork == 0) // it is the CHILD process 482 499 { 500 501 #if CMD_LOAD_DEBUG 502 get_cycle( &cycle ); 503 printf("\n@@@ %s : CHILD_PID %x after fork, before exec / cycle %d\n", 504 __FUNCTION__ , getpid(), (int)cycle ); 505 #endif 506 483 507 // CHILD process exec NEW process 484 508 ret_exec = execve( pathname , NULL , NULL ); 509 510 #if CMD_LOAD_DEBUG 511 get_cycle( &cycle ); 512 printf("\n@@@ %s : CHILD_PID %x after exec / ret_exec %d / cycle %d\n", 513 __FUNCTION__ , getpid(), ret_exec, (int)cycle ); 514 #endif 485 515 486 516 // this is only executed in case of exec failure … … 494 524 { 495 525 496 #if KSH_DEBUG 497 int sem_value; 498 sem_getvalue( &semaphore , &sem_value ); 499 printf("\n[KSH_DEBUG] in %s : child PID %x / background %d / sem_value %d\n", 500 ret_fork, background, sem_value ); 526 #if CMD_LOAD_DEBUG 527 get_cycle( &cycle ); 528 printf("\n@@@ %s : KSH_PID %x after fork / ret_fork %x / cycle %d\n", 529 __FUNCTION__, getpid(), ret_fork, (int)cycle ); 501 530 #endif 502 531 503 if( background ) // child in background => KSH keepsTXT ownership532 if( background ) // child in background => KSH must keep TXT ownership 504 533 { 505 534 // execve() tranfered TXT ownership to child => give it back to KSH … … 734 763 // This function analyses one command (with arguments), executes it, and returns. 735 764 //////////////////////////////////////////////////////////////////////////////////// 736 static void parse( char * buf )765 static void __attribute__ ((noinline)) parse( char * buf ) 737 766 { 738 767 int argc = 0; … … 758 787 } 759 788 789 // analyse command type 760 790 if (argc > 0) 761 791 { … … 765 795 766 796 // try to match typed command 767 for (i = 0 ; cmd[i].name; i++)797 for (i = 0 ; cmd[i].name ; i++) 768 798 { 769 799 if (strcmp(argv[0], cmd[i].name) == 0) … … 788 818 static void interactive() 789 819 { 790 char c; // read character 791 char buf[CMD_MAX_SIZE]; // buffer for one command 792 unsigned int end_command; // last character found in a command 793 unsigned int count; // pointer in command buffer 794 unsigned int i; // index for loops 795 unsigned int state; // escape sequence state 796 797 // @@@ 798 // parse( "load /bin/user/fft.elf" ); 799 // @@@ 820 char c; // read character 821 char buf[CMD_MAX_SIZE]; // buffer for one command 822 unsigned int end_command; // last character found in a command 823 unsigned int count; // pointer in command buffer 824 unsigned int i; // index for loops 825 unsigned int state; // escape sequence state 826 827 /* This can be used to remove interactive mode 828 829 for( i=1 ; 1 ; i += 2) 830 { 831 if( sem_wait( &semaphore ) ) 832 { 833 printf("\n[ksh error] cannot found semafore\n" ); 834 exit( 1 ); 835 } 836 else 837 { 838 printf("\n[ksh] %d for sort\n", i ); 839 } 840 strcpy( buf , "load /bin/user/sort.elf" ); 841 parse( buf ); 842 843 if( sem_wait( &semaphore ) ) 844 { 845 printf("\n[ksh error] cannot found semafore\n" ); 846 exit( 1 ); 847 } 848 else 849 { 850 printf("\n[ksh] %d for fft\n", i+1 ); 851 } 852 strcpy( buf , "load /bin/user/fft.elf" ); 853 parse( buf ); 854 } 855 856 */ 800 857 801 858 enum fsm_states … … 826 883 state = NORMAL; 827 884 828 // block if the KSH process is not the TXT owner829 // - if the command is not a "load"830 // the semaphore must be released by the cmd_***()831 // - if the command is a load, it depends on832 // the "background" argument833 sem_wait( &semaphore );885 // decrement semaphore, and block if the KSH process is not the TXT owner 886 if ( sem_wait( &semaphore ) ) 887 { 888 printf("\n[ksh error] cannot found semafore\n" ); 889 exit( 1 ); 890 } 834 891 835 892 // display prompt on a new line … … 991 1048 int status; // child process termination status 992 1049 int child_pid; // child process identifier 993 int parent_pid; // parent process identifier 994 pthread_t trdid; // kernel allocated index for interactive thread1050 int parent_pid; // parent process identifier (i.e. this process) 1051 pthread_t trdid; // interactive thread identifier (unused) 995 1052 unsigned int is_owner; // non-zero if KSH process is TXT owner 996 1053 … … 1005 1062 1006 1063 // initializes the semaphore used to unblock the interactive thread 1007 sem_init( &semaphore , 0 , 1 ); 1064 if ( sem_init( &semaphore , 0 , 1 ) ) 1065 { 1066 printf("\n[KSH ERROR] cannot initialize semaphore\n" ); 1067 exit( 1 ); 1068 } 1069 1070 printf("\n@@@ in KSH %s : &semaphore = %x\n", __FUNCTION__, &semaphore ); 1008 1071 1009 1072 // initialize interactive thread attributes -
trunk/user/sort/sort.c
r459 r469 28 28 #include <hal_macros.h> 29 29 30 #define ARRAY_LENGTH 0x 400 // 1024values30 #define ARRAY_LENGTH 0x100 // 256 values 31 31 32 32 #define MAX_THREADS 1024 // 16 * 16 * 4 … … 250 250 } 251 251 252 get_cycle( &cycle ); 253 printf("\n\n[SORT] main starts on core[%x,%d] / %d threads / %d values / cycle %d\n", 254 main_cxy, main_lid, threads, ARRAY_LENGTH, (unsigned int)cycle ); 252 printf("\n[SORT] main starts on core[%x,%d] / %d thread(s) / %d values\n", 253 main_cxy, main_lid, threads, ARRAY_LENGTH ); 255 254 256 255 // Barrier initialization
Note: See TracChangeset
for help on using the changeset viewer.