Changeset 583 for trunk/kernel/kern/process.c
- Timestamp:
- Nov 1, 2018, 12:10:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.c
r581 r583 68 68 ////////////////////////////////////////////////////////////////////////////////////////// 69 69 70 /////////////////////////// 70 ///////////////////////////////// 71 71 process_t * process_alloc( void ) 72 72 { … … 463 463 } // end process_destroy() 464 464 465 ///////////////////////////////////////////////// 465 /////////////////////////////////////////////////////////////////// 466 466 const char * process_action_str( process_sigactions_t action_type ) 467 467 { 468 switch ( action_type ) { 469 case BLOCK_ALL_THREADS: return "BLOCK"; 470 case UNBLOCK_ALL_THREADS: return "UNBLOCK"; 471 case DELETE_ALL_THREADS: return "DELETE"; 472 default: return "undefined"; 473 } 468 switch ( action_type ) 469 { 470 case BLOCK_ALL_THREADS: return "BLOCK"; 471 case UNBLOCK_ALL_THREADS: return "UNBLOCK"; 472 case DELETE_ALL_THREADS: return "DELETE"; 473 default: return "undefined"; 474 } 474 475 } 475 476 … … 499 500 remote_nr = 0; 500 501 501 // check calling thread can yield 502 assert( (client->busylocks == 0), 503 "cannot yield : busylocks = %d\n", client->busylocks ); 502 // check calling thread can yield 503 thread_assert_can_yield( client , __FUNCTION__ ); 504 504 505 505 #if DEBUG_PROCESS_SIGACTION 506 506 uint32_t cycle = (uint32_t)hal_get_cycles(); 507 507 if( DEBUG_PROCESS_SIGACTION < cycle ) 508 printk("\n[DBG] %s : thread %x in process %xenter to %s process %x / cycle %d\n",509 __FUNCTION__ , client-> trdid, client->process->pid,508 printk("\n[DBG] %s : thread[%x,%x] enter to %s process %x / cycle %d\n", 509 __FUNCTION__ , client->process->pid, client->trdid, 510 510 process_action_str( type ) , pid , cycle ); 511 511 #endif … … 522 522 lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] ); 523 523 524 525 526 527 524 // check action type 525 assert( ((type == DELETE_ALL_THREADS ) || 526 (type == BLOCK_ALL_THREADS ) || 527 (type == UNBLOCK_ALL_THREADS )), "illegal action type" ); 528 528 529 530 529 // The client thread send parallel RPCs to all remote clusters containing 531 530 // target process copies, wait all responses, and then handles directly … … 576 575 #if DEBUG_PROCESS_SIGACTION 577 576 if( DEBUG_PROCESS_SIGACTION < cycle ) 578 printk("\n[DBG] %s : thread %x in process %x handles remote process %x in cluster%x\n",579 __FUNCTION__, client-> trdid, client->process->pid, pid , process_cxy);577 printk("\n[DBG] %s : thread[%x,%x] send RPC to cluster %x for process %x\n", 578 __FUNCTION__, client->process->pid, client->trdid, process_cxy, pid ); 580 579 #endif 581 580 // call RPC in target cluster … … 608 607 #if DEBUG_PROCESS_SIGACTION 609 608 if( DEBUG_PROCESS_SIGACTION < cycle ) 610 printk("\n[DBG] %s : thread %x in process %xhandles local process %x in cluster %x\n",611 __FUNCTION__, client-> trdid, client->process->pid, pid , local_cxy );609 printk("\n[DBG] %s : thread[%x,%x] handles local process %x in cluster %x\n", 610 __FUNCTION__, client->process->pid, client->trdid, pid , local_cxy ); 612 611 #endif 613 612 if (type == DELETE_ALL_THREADS ) process_delete_threads ( local , client_xp ); 614 else if(type == BLOCK_ALL_THREADS ) process_block_threads ( local , client_xp);613 else if(type == BLOCK_ALL_THREADS ) process_block_threads ( local ); 615 614 else if(type == UNBLOCK_ALL_THREADS ) process_unblock_threads( local ); 616 615 } … … 619 618 cycle = (uint32_t)hal_get_cycles(); 620 619 if( DEBUG_PROCESS_SIGACTION < cycle ) 621 printk("\n[DBG] %s : thread %x in process %xexit after %s process %x / cycle %d\n",622 __FUNCTION__, client-> trdid, client->process->pid,620 printk("\n[DBG] %s : thread[%x,%x] exit after %s process %x / cycle %d\n", 621 __FUNCTION__, client->process->pid, client->trdid, 623 622 process_action_str( type ), pid, cycle ); 624 623 #endif … … 627 626 628 627 ///////////////////////////////////////////////// 629 void process_block_threads( process_t * process, 630 xptr_t client_xp ) 628 void process_block_threads( process_t * process ) 631 629 { 632 630 thread_t * target; // pointer on target thread … … 644 642 uint32_t cycle = (uint32_t)hal_get_cycles(); 645 643 if( DEBUG_PROCESS_SIGACTION < cycle ) 646 printk("\n[DBG] %s : thread %x in process %xenter for process %x in cluster %x / cycle %d\n",647 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy , cycle );644 printk("\n[DBG] %s : thread[%x,%x] enter for process %x in cluster %x / cycle %d\n", 645 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy , cycle ); 648 646 #endif 649 647 650 648 // check target process is an user process 651 assert( ( process->pid != 0 ), 652 "target process must be an user process" ); 653 654 // get target process owner cluster 649 assert( (LPID_FROM_PID( process->pid ) != 0 ), "target process must be an user process" ); 650 651 // get target process cluster 655 652 owner_cxy = CXY_FROM_PID( process->pid ); 656 653 … … 668 665 count++; 669 666 670 // main thread and client thread should not be blocked 671 if( ((ltid != 0) || (owner_cxy != local_cxy)) && // not main thread 672 (client_xp) != XPTR( local_cxy , target ) ) // not client thread 667 // set the global blocked bit in target thread descriptor. 668 thread_block( XPTR( local_cxy , target ) , THREAD_BLOCKED_GLOBAL ); 669 670 // - if the calling thread and the target thread are running on the same core, 671 // we don't need confirmation from scheduler, 672 // - if the calling thread and the target thread are not running on the same 673 // core, we ask the target scheduler to acknowlege the blocking 674 // to be sure that the target thread is not running. 675 676 if( this->core->lid != target->core->lid ) 673 677 { 674 // set the global blocked bit in target thread descriptor. 675 thread_block( XPTR( local_cxy , target ) , THREAD_BLOCKED_GLOBAL ); 676 677 // - if the calling thread and the target thread are on the same core, 678 // we don't need confirmation from scheduler, 679 // - if the calling thread and the target thread are not running on the same 680 // core, we ask the target scheduler to acknowlege the blocking 681 // to be sure that the target thread is not running. 682 683 if( this->core->lid != target->core->lid ) 684 { 685 // increment responses counter 686 hal_atomic_add( (void*)&ack_count , 1 ); 687 688 // set FLAG_REQ_ACK and &ack_rsp_count in target descriptor 689 thread_set_req_ack( target , (uint32_t *)&ack_count ); 690 691 // force scheduling on target thread 692 dev_pic_send_ipi( local_cxy , target->core->lid ); 693 } 678 // increment responses counter 679 hal_atomic_add( (void*)&ack_count , 1 ); 680 681 // set FLAG_REQ_ACK and &ack_rsp_count in target descriptor 682 thread_set_req_ack( target , (uint32_t *)&ack_count ); 683 684 // force scheduling on target thread 685 dev_pic_send_ipi( local_cxy , target->core->lid ); 694 686 } 695 687 } … … 713 705 cycle = (uint32_t)hal_get_cycles(); 714 706 if( DEBUG_PROCESS_SIGACTION < cycle ) 715 printk("\n[DBG] %s : thread %x in process %xexit for process %x in cluster %x / cycle %d\n",707 printk("\n[DBG] %s : thread[%x,%x] exit for process %x in cluster %x / cycle %d\n", 716 708 __FUNCTION__, this, this->process->pid, pid, local_cxy , cycle ); 717 709 #endif … … 740 732 uint32_t cycle = (uint32_t)hal_get_cycles(); 741 733 if( DEBUG_PROCESS_SIGACTION < cycle ) 742 printk("\n[DBG] %s : thread %x n process %x enter for process %x in cluster%x / cycle %d\n",743 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy, cycle );734 printk("\n[DBG] %s : thread[%x,%x] enter in cluster %x for process %x / cycle %d\n", 735 __FUNCTION__, this->process->pid, this->trdid, local_cxy, process->pid, cycle ); 744 736 #endif 745 737 746 738 // check target process is an user process 747 assert( ( process->pid!= 0 ),739 assert( ( LPID_FROM_PID( process->pid ) != 0 ), 748 740 "target process must be an user process" ); 749 741 750 742 // get lock protecting process th_tbl[] 751 rwlock_ rd_acquire( &process->th_lock );743 rwlock_wr_acquire( &process->th_lock ); 752 744 753 745 // loop on target process local threads … … 773 765 774 766 // release lock protecting process th_tbl[] 775 rwlock_ rd_release( &process->th_lock );767 rwlock_wr_release( &process->th_lock ); 776 768 777 769 #if DEBUG_PROCESS_SIGACTION 778 770 cycle = (uint32_t)hal_get_cycles(); 779 771 if( DEBUG_PROCESS_SIGACTION < cycle ) 780 printk("\n[DBG] %s : thread %x in process %xexit for process %x in cluster %x / cycle %d\n",781 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy , cycle );772 printk("\n[DBG] %s : thread[%x,%x] exit for process %x in cluster %x / cycle %d\n", 773 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy , cycle ); 782 774 #endif 783 775 … … 799 791 uint32_t cycle = (uint32_t)hal_get_cycles(); 800 792 if( DEBUG_PROCESS_SIGACTION < cycle ) 801 printk("\n[DBG] %s : thread %x in process %xenter for process %x in cluster %x / cycle %d\n",802 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy , cycle );793 printk("\n[DBG] %s : thread[%x,%x] enter for process %x in cluster %x / cycle %d\n", 794 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy , cycle ); 803 795 #endif 804 796 … … 831 823 cycle = (uint32_t)hal_get_cycles(); 832 824 if( DEBUG_PROCESS_SIGACTION < cycle ) 833 printk("\n[DBG] %s : thread %x in process %xexit for process %x in cluster %x / cycle %d\n",834 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy, cycle );825 printk("\n[DBG] %s : thread[%x,%x] exit for process %x in cluster %x / cycle %d\n", 826 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy, cycle ); 835 827 #endif 836 828 … … 850 842 uint32_t cycle = (uint32_t)hal_get_cycles(); 851 843 if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle ) 852 printk("\n[DBG] %s : thread %x in cluster %xenter for process %x in cluster %x / cycle %d\n",853 __FUNCTION__, this-> trdid, this->process->pid, pid, local_cxy, cycle );844 printk("\n[DBG] %s : thread[%x,%x] enter for process %x in cluster %x / cycle %d\n", 845 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy, cycle ); 854 846 #endif 855 847 … … 897 889 cycle = (uint32_t)hal_get_cycles(); 898 890 if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle ) 899 printk("\n[DBG] %s : thread %x in cluster %xexit in cluster %x / process %x / cycle %d\n",900 __FUNCTION__, this-> trdid, this->process->pid, local_cxy, process_ptr, cycle );891 printk("\n[DBG] %s : thread[%x,%x] exit in cluster %x / process %x / cycle %d\n", 892 __FUNCTION__, this->process->pid, this->trdid, local_cxy, process_ptr, cycle ); 901 893 #endif 902 894 … … 1109 1101 if( thread->type != THREAD_IDLE ) rwlock_wr_acquire( &process->th_lock ); 1110 1102 1111 // scan kth_tbl1103 // scan th_tbl 1112 1104 for( ltid = 0 ; ltid < CONFIG_THREADS_MAX_PER_CLUSTER ; ltid++ ) 1113 1105 { … … 1127 1119 // returns trdid 1128 1120 *trdid = TRDID( local_cxy , ltid ); 1129 } 1130 1131 // get the lock protecting th_tbl for all threads 1132 // but the idle thread executing kernel_init (cannot yield) 1121 1122 // if( LPID_FROM_PID( process->pid ) == 0 ) 1123 // printk("\n@@@ %s : allocate ltid %d for a thread %s in cluster %x\n", 1124 // __FUNCTION__, ltid, thread_type_str( thread->type), local_cxy ); 1125 1126 } 1127 1128 // release the lock protecting th_tbl 1133 1129 if( thread->type != THREAD_IDLE ) rwlock_wr_release( &process->th_lock ); 1134 1130 … … 1141 1137 { 1142 1138 uint32_t count; // number of threads in local process descriptor 1143 1144 // check argument1145 assert( (thread != NULL) , "thread argument is NULL" );1146 1139 1147 1140 process_t * process = thread->process; … … 1150 1143 ltid_t ltid = LTID_FROM_TRDID( thread->trdid ); 1151 1144 1152 // the lock depends on thread user/kernel type, because we cannot1153 // use a descheduling policy for the lock protecting the kth_tbl1154 1155 1145 // get the lock protecting th_tbl[] 1156 1146 rwlock_wr_acquire( &process->th_lock ); 1157 1147 1158 // get number of kernelthreads1148 // get number of threads 1159 1149 count = process->th_nr; 1160 1150 1151 // check thread 1152 assert( (thread != NULL) , "thread argument is NULL" ); 1153 1161 1154 // check th_nr value 1162 assert( (count > 0) , "process kth_nr cannot be 0\n" );1155 assert( (count > 0) , "process th_nr cannot be 0\n" ); 1163 1156 1164 1157 // remove thread from th_tbl[] … … 1166 1159 process->th_nr = count-1; 1167 1160 1168 // release lock protecting kth_tbl 1161 // if( LPID_FROM_PID( process->pid ) == 0 ) 1162 // printk("\n@@@ %s : release ltid %d for a thread %s in cluster %x\n", 1163 // __FUNCTION__, ltid, thread_type_str( thread->type), local_cxy ); 1164 1165 // release lock protecting th_tbl 1169 1166 rwlock_wr_release( &process->th_lock ); 1170 1167 … … 1203 1200 1204 1201 #if DEBUG_PROCESS_MAKE_FORK 1205 uint32_t cycle = (uint32_t)hal_get_cycles(); 1202 uint32_t cycle = (uint32_t)hal_get_cycles(); 1203 thread_t * this = CURRENT_THREAD; 1204 trdid_t trdid = this->trdid; 1205 pid_t pid = this->process->pid; 1206 1206 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1207 printk("\n[DBG] %s : thread %x in process %xenter / cluster %x / cycle %d\n",1208 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy, cycle );1207 printk("\n[DBG] %s : thread[%x,%x] enter / cluster %x / cycle %d\n", 1208 __FUNCTION__, pid, trdid, local_cxy, cycle ); 1209 1209 #endif 1210 1210 … … 1231 1231 cycle = (uint32_t)hal_get_cycles(); 1232 1232 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1233 printk("\n[DBG] %s : thread %x in process %xallocated process %x / cycle %d\n",1234 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );1233 printk("\n[DBG] %s : thread[%x,%x] allocated process %x / cycle %d\n", 1234 __FUNCTION__, pid, trdid, new_pid, cycle ); 1235 1235 #endif 1236 1236 … … 1243 1243 cycle = (uint32_t)hal_get_cycles(); 1244 1244 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1245 printk("\n[DBG] %s : thread %x in process %xinitialized child_process %x / cycle %d\n",1246 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );1245 printk("\n[DBG] %s : thread[%x,%x] initialized child_process %x / cycle %d\n", 1246 __FUNCTION__, pid, trdid, new_pid, cycle ); 1247 1247 #endif 1248 1248 … … 1263 1263 cycle = (uint32_t)hal_get_cycles(); 1264 1264 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1265 printk("\n[DBG] %s : thread %x in process %x copied VMM from parent %x to child %x / cycle %d\n", 1266 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, 1267 parent_pid, new_pid, cycle ); 1265 printk("\n[DBG] %s : thread[%x,%x] copied VMM from parent to child / cycle %d\n", 1266 __FUNCTION__, pid, trdid, cycle ); 1268 1267 #endif 1269 1268 … … 1277 1276 cycle = (uint32_t)hal_get_cycles(); 1278 1277 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1279 printk("\n[DBG] %s : thread %x in process %x/ child takes TXT ownership / cycle %d\n",1280 __FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );1278 printk("\n[DBG] %s : thread[%x,%x] / child takes TXT ownership / cycle %d\n", 1279 __FUNCTION__ , pid, trdid, cycle ); 1281 1280 #endif 1282 1281 … … 1306 1305 cycle = (uint32_t)hal_get_cycles(); 1307 1306 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1308 printk("\n[DBG] %s : thread %x in process %xcreated main thread %x / cycle %d\n",1309 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, thread, cycle );1307 printk("\n[DBG] %s : thread[%x,%x] created main thread %x / cycle %d\n", 1308 __FUNCTION__, pid, trdid, thread, cycle ); 1310 1309 #endif 1311 1310 … … 1328 1327 cycle = (uint32_t)hal_get_cycles(); 1329 1328 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1330 printk("\n[DBG] %s : thread %x in process %xset COW in parent and child / cycle %d\n",1331 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );1329 printk("\n[DBG] %s : thread[%x,%x] set COW in parent and child / cycle %d\n", 1330 __FUNCTION__, pid, trdid, cycle ); 1332 1331 #endif 1333 1332 … … 1350 1349 cycle = (uint32_t)hal_get_cycles(); 1351 1350 if( DEBUG_PROCESS_MAKE_FORK < cycle ) 1352 printk("\n[DBG] %s : thread %x in process %xexit / created process %x / cycle %d\n",1353 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );1351 printk("\n[DBG] %s : thread[%x,%x] exit / created process %x / cycle %d\n", 1352 __FUNCTION__, pid, trdid, new_pid, cycle ); 1354 1353 #endif 1355 1354 … … 1384 1383 uint32_t cycle = (uint32_t)hal_get_cycles(); 1385 1384 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1386 printk("\n[DBG] %s : thread %x in process %x enters / path%s / cycle %d\n",1387 __FUNCTION__, thread->trdid, pid, path, cycle );1385 printk("\n[DBG] %s : thread[%x,%x] enters for %s / cycle %d\n", 1386 __FUNCTION__, pid, thread->trdid, path, cycle ); 1388 1387 #endif 1389 1388 … … 1406 1405 cycle = (uint32_t)hal_get_cycles(); 1407 1406 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1408 printk("\n[DBG] %s : thread %x in process %xopened file <%s> / cycle %d\n",1409 __FUNCTION__, thread->trdid, pid, path, cycle );1407 printk("\n[DBG] %s : thread[%x,%x] opened file <%s> / cycle %d\n", 1408 __FUNCTION__, pid, thread->trdid, path, cycle ); 1410 1409 #endif 1411 1410 … … 1416 1415 cycle = (uint32_t)hal_get_cycles(); 1417 1416 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1418 printk("\n[DBG] %s : thread %x in process %xdeleted all threads / cycle %d\n",1419 __FUNCTION__, thread->trdid, pid, cycle );1417 printk("\n[DBG] %s : thread[%x,%x] deleted all threads / cycle %d\n", 1418 __FUNCTION__, pid, thread->trdid, cycle ); 1420 1419 #endif 1421 1420 … … 1426 1425 cycle = (uint32_t)hal_get_cycles(); 1427 1426 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1428 printk("\n[DBG] %s : thread %x in process %xreset VMM / cycle %d\n",1429 __FUNCTION__, thread->trdid, pid, cycle );1427 printk("\n[DBG] %s : thread[%x,%x] reset VMM / cycle %d\n", 1428 __FUNCTION__, pid, thread->trdid, cycle ); 1430 1429 #endif 1431 1430 … … 1443 1442 cycle = (uint32_t)hal_get_cycles(); 1444 1443 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1445 printk("\n[DBG] %s : thread %x in process %x/ kentry/args/envs vsegs registered / cycle %d\n",1446 __FUNCTION__, thread->trdid, pid, cycle );1444 printk("\n[DBG] %s : thread[%x,%x] / kentry/args/envs vsegs registered / cycle %d\n", 1445 __FUNCTION__, pid, thread->trdid, cycle ); 1447 1446 #endif 1448 1447 … … 1461 1460 cycle = (uint32_t)hal_get_cycles(); 1462 1461 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1463 printk("\n[DBG] %s : thread %x in process %x/ code/data vsegs registered / cycle %d\n",1464 __FUNCTION__, thread->trdid, pid, cycle );1462 printk("\n[DBG] %s : thread[%x,%x] / code/data vsegs registered / cycle %d\n", 1463 __FUNCTION__, pid, thread->trdid, cycle ); 1465 1464 #endif 1466 1465
Note: See TracChangeset
for help on using the changeset viewer.