Ignore:
Timestamp:
Nov 1, 2018, 12:10:42 PM (3 years ago)
Author:
alain
Message:

Improve signals.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.c

    r581 r583  
    6868//////////////////////////////////////////////////////////////////////////////////////////
    6969
    70 ///////////////////////////
     70/////////////////////////////////
    7171process_t * process_alloc( void )
    7272{
     
    463463}  // end process_destroy()
    464464
    465 /////////////////////////////////////////////////
     465///////////////////////////////////////////////////////////////////
    466466const char * process_action_str( process_sigactions_t action_type )
    467467{
    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    }
    474475}
    475476
     
    499500    remote_nr = 0;
    500501
    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__ );
    504504
    505505#if DEBUG_PROCESS_SIGACTION
    506506uint32_t cycle = (uint32_t)hal_get_cycles();
    507507if( DEBUG_PROCESS_SIGACTION < cycle )
    508 printk("\n[DBG] %s : thread %x in process %x enter to %s process %x / cycle %d\n",
    509 __FUNCTION__ , client->trdid, client->process->pid,
     508printk("\n[DBG] %s : thread[%x,%x] enter to %s process %x / cycle %d\n",
     509__FUNCTION__ , client->process->pid, client->trdid,
    510510process_action_str( type ) , pid , cycle );
    511511#endif
     
    522522    lock_xp   = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
    523523
    524     // check action type
    525     assert( ((type == DELETE_ALL_THREADS ) ||
    526              (type == BLOCK_ALL_THREADS )  ||
    527              (type == UNBLOCK_ALL_THREADS )), "illegal action type" );
     524// check action type
     525assert( ((type == DELETE_ALL_THREADS ) ||
     526         (type == BLOCK_ALL_THREADS )  ||
     527         (type == UNBLOCK_ALL_THREADS )), "illegal action type" );
    528528             
    529 
    530529    // The client thread send parallel RPCs to all remote clusters containing
    531530    // target process copies, wait all responses, and then handles directly
     
    576575#if DEBUG_PROCESS_SIGACTION
    577576if( 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 );
     577printk("\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 );
    580579#endif
    581580            // call RPC in target cluster
     
    608607#if DEBUG_PROCESS_SIGACTION
    609608if( DEBUG_PROCESS_SIGACTION < cycle )
    610 printk("\n[DBG] %s : thread %x in process %x handles local process %x in cluster %x\n",
    611 __FUNCTION__, client->trdid, client->process->pid, pid , local_cxy );
     609printk("\n[DBG] %s : thread[%x,%x] handles local process %x in cluster %x\n",
     610__FUNCTION__, client->process->pid, client->trdid, pid , local_cxy );
    612611#endif
    613612        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 );
    615614        else if(type == UNBLOCK_ALL_THREADS ) process_unblock_threads( local );
    616615    }
     
    619618cycle = (uint32_t)hal_get_cycles();
    620619if( DEBUG_PROCESS_SIGACTION < cycle )
    621 printk("\n[DBG] %s : thread %x in process %x exit after %s process %x / cycle %d\n",
    622 __FUNCTION__, client->trdid, client->process->pid,
     620printk("\n[DBG] %s : thread[%x,%x] exit after %s process %x / cycle %d\n",
     621__FUNCTION__, client->process->pid, client->trdid,
    623622process_action_str( type ), pid, cycle );
    624623#endif
     
    627626
    628627/////////////////////////////////////////////////
    629 void process_block_threads( process_t * process,
    630                             xptr_t      client_xp )
     628void process_block_threads( process_t * process )
    631629{
    632630    thread_t          * target;         // pointer on target thread
     
    644642uint32_t cycle = (uint32_t)hal_get_cycles();
    645643if( DEBUG_PROCESS_SIGACTION < cycle )
    646 printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
    647 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     644printk("\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 );
    648646#endif
    649647
    650648// 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
     649assert( (LPID_FROM_PID( process->pid ) != 0 ), "target process must be an user process" );
     650
     651    // get target process cluster
    655652    owner_cxy = CXY_FROM_PID( process->pid );
    656653
     
    668665            count++;
    669666
    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 )
    673677            {
    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 );
    694686            }
    695687        }
     
    713705cycle = (uint32_t)hal_get_cycles();
    714706if( DEBUG_PROCESS_SIGACTION < cycle )
    715 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
     707printk("\n[DBG] %s : thread[%x,%x] exit for process %x in cluster %x / cycle %d\n",
    716708__FUNCTION__, this, this->process->pid, pid, local_cxy , cycle );
    717709#endif
     
    740732uint32_t cycle = (uint32_t)hal_get_cycles();
    741733if( 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 );
     734printk("\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 );
    744736#endif
    745737
    746738// check target process is an user process
    747 assert( ( process->pid != 0 ),
     739assert( ( LPID_FROM_PID( process->pid ) != 0 ),
    748740"target process must be an user process" );
    749741
    750742    // get lock protecting process th_tbl[]
    751     rwlock_rd_acquire( &process->th_lock );
     743    rwlock_wr_acquire( &process->th_lock );
    752744
    753745    // loop on target process local threads                       
     
    773765
    774766    // release lock protecting process th_tbl[]
    775     rwlock_rd_release( &process->th_lock );
     767    rwlock_wr_release( &process->th_lock );
    776768
    777769#if DEBUG_PROCESS_SIGACTION
    778770cycle = (uint32_t)hal_get_cycles();
    779771if( DEBUG_PROCESS_SIGACTION < cycle )
    780 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
    781 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     772printk("\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 );
    782774#endif
    783775
     
    799791uint32_t cycle = (uint32_t)hal_get_cycles();
    800792if( DEBUG_PROCESS_SIGACTION < cycle )
    801 printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
    802 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     793printk("\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 );
    803795#endif
    804796
     
    831823cycle = (uint32_t)hal_get_cycles();
    832824if( DEBUG_PROCESS_SIGACTION < cycle )
    833 printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
    834 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
     825printk("\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 );
    835827#endif
    836828
     
    850842uint32_t cycle = (uint32_t)hal_get_cycles();
    851843if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
    852 printk("\n[DBG] %s : thread %x in cluster %x enter for process %x in cluster %x / cycle %d\n",
    853 __FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
     844printk("\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 );
    854846#endif
    855847
     
    897889cycle = (uint32_t)hal_get_cycles();
    898890if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
    899 printk("\n[DBG] %s : thread %x in cluster %x exit in cluster %x / process %x / cycle %d\n",
    900 __FUNCTION__, this->trdid, this->process->pid, local_cxy, process_ptr, cycle );
     891printk("\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 );
    901893#endif
    902894
     
    11091101    if( thread->type != THREAD_IDLE ) rwlock_wr_acquire( &process->th_lock );
    11101102
    1111     // scan kth_tbl
     1103    // scan th_tbl
    11121104    for( ltid = 0 ; ltid < CONFIG_THREADS_MAX_PER_CLUSTER ; ltid++ )
    11131105    {
     
    11271119        // returns trdid
    11281120        *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
    11331129    if( thread->type != THREAD_IDLE ) rwlock_wr_release( &process->th_lock );
    11341130
     
    11411137{
    11421138    uint32_t count;  // number of threads in local process descriptor
    1143 
    1144 // check argument
    1145 assert( (thread != NULL) , "thread argument is NULL" );
    11461139
    11471140    process_t * process = thread->process;
     
    11501143    ltid_t  ltid = LTID_FROM_TRDID( thread->trdid );
    11511144   
    1152     // the lock depends on thread user/kernel type, because we cannot
    1153     // use a descheduling policy for the lock protecting the kth_tbl
    1154 
    11551145    // get the lock protecting th_tbl[]
    11561146    rwlock_wr_acquire( &process->th_lock );
    11571147
    1158     // get number of kernel threads
     1148    // get number of threads
    11591149    count = process->th_nr;
    11601150
     1151// check thread
     1152assert( (thread != NULL) , "thread argument is NULL" );
     1153
    11611154// check th_nr value
    1162 assert( (count > 0) , "process kth_nr cannot be 0\n" );
     1155assert( (count > 0) , "process th_nr cannot be 0\n" );
    11631156
    11641157    // remove thread from th_tbl[]
     
    11661159    process->th_nr = count-1;
    11671160
    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
    11691166    rwlock_wr_release( &process->th_lock );
    11701167
     
    12031200
    12041201#if DEBUG_PROCESS_MAKE_FORK
    1205 uint32_t cycle = (uint32_t)hal_get_cycles();
     1202uint32_t cycle   = (uint32_t)hal_get_cycles();
     1203thread_t * this  = CURRENT_THREAD;
     1204trdid_t    trdid = this->trdid;
     1205pid_t      pid   = this->process->pid;
    12061206if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1207 printk("\n[DBG] %s : thread %x in process %x enter / cluster %x / cycle %d\n",
    1208 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy, cycle );
     1207printk("\n[DBG] %s : thread[%x,%x] enter / cluster %x / cycle %d\n",
     1208__FUNCTION__, pid, trdid, local_cxy, cycle );
    12091209#endif
    12101210
     
    12311231cycle = (uint32_t)hal_get_cycles();
    12321232if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1233 printk("\n[DBG] %s : thread %x in process %x allocated process %x / cycle %d\n",
    1234 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
     1233printk("\n[DBG] %s : thread[%x,%x] allocated process %x / cycle %d\n",
     1234__FUNCTION__, pid, trdid, new_pid, cycle );
    12351235#endif
    12361236
     
    12431243cycle = (uint32_t)hal_get_cycles();
    12441244if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1245 printk("\n[DBG] %s : thread %x in process %x initialized child_process %x / cycle %d\n",
    1246 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
     1245printk("\n[DBG] %s : thread[%x,%x] initialized child_process %x / cycle %d\n",
     1246__FUNCTION__, pid, trdid, new_pid, cycle );
    12471247#endif
    12481248
     
    12631263cycle = (uint32_t)hal_get_cycles();
    12641264if( 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 );
     1265printk("\n[DBG] %s : thread[%x,%x] copied VMM from parent to child / cycle %d\n",
     1266__FUNCTION__, pid, trdid, cycle );
    12681267#endif
    12691268
     
    12771276cycle = (uint32_t)hal_get_cycles();
    12781277if( 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 );
     1278printk("\n[DBG] %s : thread[%x,%x] / child takes TXT ownership / cycle %d\n",
     1279__FUNCTION__ , pid, trdid, cycle );
    12811280#endif
    12821281
     
    13061305cycle = (uint32_t)hal_get_cycles();
    13071306if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1308 printk("\n[DBG] %s : thread %x in process %x created main thread %x / cycle %d\n",
    1309 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, thread, cycle );
     1307printk("\n[DBG] %s : thread[%x,%x] created main thread %x / cycle %d\n",
     1308__FUNCTION__, pid, trdid, thread, cycle );
    13101309#endif
    13111310
     
    13281327cycle = (uint32_t)hal_get_cycles();
    13291328if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1330 printk("\n[DBG] %s : thread %x in process %x set COW in parent and child / cycle %d\n",
    1331 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
     1329printk("\n[DBG] %s : thread[%x,%x] set COW in parent and child / cycle %d\n",
     1330__FUNCTION__, pid, trdid, cycle );
    13321331#endif
    13331332
     
    13501349cycle = (uint32_t)hal_get_cycles();
    13511350if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1352 printk("\n[DBG] %s : thread %x in process %x exit / created process %x / cycle %d\n",
    1353 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, new_pid, cycle );
     1351printk("\n[DBG] %s : thread[%x,%x] exit / created process %x / cycle %d\n",
     1352__FUNCTION__, pid, trdid, new_pid, cycle );
    13541353#endif
    13551354
     
    13841383uint32_t cycle = (uint32_t)hal_get_cycles();
    13851384if( 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 );
     1385printk("\n[DBG] %s : thread[%x,%x] enters for %s / cycle %d\n",
     1386__FUNCTION__, pid, thread->trdid, path, cycle );
    13881387#endif
    13891388
     
    14061405cycle = (uint32_t)hal_get_cycles();
    14071406if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1408 printk("\n[DBG] %s : thread %x in process %x opened file <%s> / cycle %d\n",
    1409 __FUNCTION__, thread->trdid, pid, path, cycle );
     1407printk("\n[DBG] %s : thread[%x,%x] opened file <%s> / cycle %d\n",
     1408__FUNCTION__, pid, thread->trdid, path, cycle );
    14101409#endif
    14111410
     
    14161415cycle = (uint32_t)hal_get_cycles();
    14171416if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1418 printk("\n[DBG] %s : thread %x in process %x deleted all threads / cycle %d\n",
    1419 __FUNCTION__, thread->trdid, pid, cycle );
     1417printk("\n[DBG] %s : thread[%x,%x] deleted all threads / cycle %d\n",
     1418__FUNCTION__, pid, thread->trdid, cycle );
    14201419#endif
    14211420
     
    14261425cycle = (uint32_t)hal_get_cycles();
    14271426if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1428 printk("\n[DBG] %s : thread %x in process %x reset VMM / cycle %d\n",
    1429 __FUNCTION__, thread->trdid, pid, cycle );
     1427printk("\n[DBG] %s : thread[%x,%x] reset VMM / cycle %d\n",
     1428__FUNCTION__, pid, thread->trdid, cycle );
    14301429#endif
    14311430
     
    14431442cycle = (uint32_t)hal_get_cycles();
    14441443if( 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 );
     1444printk("\n[DBG] %s : thread[%x,%x] / kentry/args/envs vsegs registered / cycle %d\n",
     1445__FUNCTION__, pid, thread->trdid, cycle );
    14471446#endif
    14481447
     
    14611460cycle = (uint32_t)hal_get_cycles();
    14621461if( 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 );
     1462printk("\n[DBG] %s : thread[%x,%x] / code/data vsegs registered / cycle %d\n",
     1463__FUNCTION__, pid, thread->trdid, cycle );
    14651464#endif
    14661465
Note: See TracChangeset for help on using the changeset viewer.