Ignore:
Timestamp:
Jun 19, 2018, 5:12:57 PM (6 years ago)
Author:
alain
Message:

miscelaneous...

File:
1 edited

Legend:

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

    r445 r446  
    392392    cxy_t       parent_cxy;
    393393    xptr_t      children_lock_xp;
     394    xptr_t      children_nr_xp;
    394395
    395396    pid_t       pid = process->pid;
     
    421422        // get extended pointer on children_lock in parent process
    422423        children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     424        children_nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr );
    423425
    424426        // remove process from children_list
    425427        remote_spinlock_lock( children_lock_xp );
    426428        xlist_unlink( XPTR( local_cxy , &process->children_list ) );
     429            hal_remote_atomic_add( children_nr_xp , -1 );
    427430        remote_spinlock_unlock( children_lock_xp );
    428431    }
     
    12371240    thread_t       * new_thread;              // local pointer on new thread
    12381241    xptr_t           parent_xp;               // extended pointer on parent process
     1242    process_t      * parent_ptr;              // local pointer on parent process
     1243    cxy_t            parent_cxy;              // parent process cluster identifier
     1244    xptr_t           children_lock_xp;        // extended pointer on children lock in parent
     1245    xptr_t           children_root_xp;        // extended pointer on children root in parent
     1246    xptr_t           children_nr_xp;          // extended pointer on children number in parent
     1247    thread_t       * parent_main_ptr;         // local pointer on parent main thread
     1248    xptr_t           parent_main_xp;          // extended pointer on parent main thread
    12391249    pthread_attr_t   attr;                    // new thread attributes
    12401250    lid_t            lid;                     // selected core local index
    12411251        error_t          error;                   // value returned by called functions
    12421252   
    1243     // get old_thread / old_process / PID / parent_xp
     1253    // get old_thread, old_process & PID
    12441254    old_thread  = CURRENT_THREAD;
    12451255    old_process = old_thread->process;
    12461256    pid         = old_process->pid;
    1247     parent_xp   = old_process->parent_xp;
    1248    
     1257
    12491258        // get .elf pathname from exec_info
    1250         path        = exec_info->path;
     1259        path = exec_info->path;
    12511260
    12521261    // this function must be executed by a thread running in owner cluster
     
    12601269uint32_t cycle = (uint32_t)hal_get_cycles();
    12611270if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1262 printk("\n[DBG] %s : thread %x enters for process %x / %s / cycle %d\n",
    1263 __FUNCTION__, old_thread, pid, path, cycle );
    1264 #endif
     1271printk("\n[DBG] %s : thread %x in process %x enters / path %s / cycle %d\n",
     1272__FUNCTION__, old_thread->trdid, pid, path, cycle );
     1273#endif
     1274
     1275    // get parent process pointers
     1276    parent_xp   = old_process->parent_xp;
     1277    parent_cxy  = GET_CXY( parent_xp );
     1278    parent_ptr  = GET_PTR( parent_xp );
     1279   
     1280#if (DEBUG_PROCESS_MAKE_EXEC & 1)
     1281if( DEBUG_PROCESS_MAKE_EXEC < cycle )
     1282printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n",
     1283__FUNCTION__, old_thread->trdid, pid, parent_ptr, parent_cxy );
     1284#endif
     1285
     1286    // get extended pointers on parent children_root, children_lock and children_nr
     1287    children_root_xp = XPTR( parent_cxy , &parent_ptr->children_root );
     1288    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     1289    children_nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr   );
     1290
     1291    // get pointers on the parent process main thread
     1292    parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
     1293    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
    12651294
    12661295     // allocate memory for new_process descriptor
     
    12981327cycle = (uint32_t)hal_get_cycles();
    12991328if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1300 printk("\n[DBG] %s : thread %x created new process %x / cycle %d \n",
    1301 __FUNCTION__ , old_thread , new_process , cycle );
     1329printk("\n[DBG] %s : thread %x in process %x created new process %x\n",
     1330__FUNCTION__ , old_thread->trdid, pid, new_process );
    13021331#endif
    13031332
     
    13581387#endif
    13591388
    1360     // get cluster and local pointer on parent process
    1361     process_t * parent_ptr = GET_PTR( parent_xp );
    1362     cxy_t       parent_cxy = GET_CXY( parent_xp );
    1363 
    1364     // get extended pointers on parent children_root, children_lock and children_nr
    1365     xptr_t root_xp = XPTR( parent_cxy , &parent_ptr->children_root );
    1366     xptr_t lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
    1367     xptr_t nr_xp   = XPTR( parent_cxy , &parent_ptr->children_nr   );
    1368 
    13691389    // register new_process in parent children list
    1370     remote_spinlock_lock( lock_xp );
    1371         xlist_add_last( root_xp , XPTR( local_cxy , &new_process->children_list ) );
    1372         hal_remote_atomic_add( nr_xp , 1 );
    1373     remote_spinlock_unlock( lock_xp );
     1390    remote_spinlock_lock( children_lock_xp );
     1391        xlist_add_last( children_root_xp , XPTR( local_cxy , &new_process->children_list ) );
     1392        hal_remote_atomic_add( children_nr_xp , 1 );
     1393    remote_spinlock_unlock( children_lock_xp );
    13741394
    13751395    // activate new thread
     
    13791399    process_txt_detach( XPTR( local_cxy , old_process ) );
    13801400
    1381     // block this old_thread
     1401    // block old_thread
    13821402    thread_block( XPTR( local_cxy , old_thread ) , THREAD_BLOCKED_GLOBAL );
    13831403
    1384     // atomically update old_process descriptor term_state to ask
    1385     // the parent process (wait() function) to delete this old_thread
     1404    // atomically update old_process termination state
    13861405    hal_atomic_or( &old_process->term_state , PROCESS_TERM_EXIT );
     1406
     1407    // take the children lock and unblock the parent process main thread
     1408    remote_spinlock_lock( children_lock_xp );
     1409    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     1410    remote_spinlock_unlock( children_lock_xp );
    13871411
    13881412    hal_fence();
     
    16211645    if( txt_owner_xp == process_xp )
    16221646    {
    1623         nolock_printk("PID %X | PPID %X | STS %X | %s (FG) | %X | %d | %s\n",
     1647        nolock_printk("PID %X | PPID %X | TS %X | %s (FG) | %X | %d | %s\n",
    16241648        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16251649    }
    16261650    else
    16271651    {
    1628         nolock_printk("PID %X | PPID %X | STS %X | %s (BG) | %X | %d | %s\n",
     1652        nolock_printk("PID %X | PPID %X | TS %X | %s (BG) | %X | %d | %s\n",
    16291653        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16301654    }
     
    16761700    xptr_t      lock_xp;      // extended pointer on list lock in chdev
    16771701
    1678 #if DEBUG_PROCESS_TXT_ATTACH
     1702#if DEBUG_PROCESS_TXT
    16791703uint32_t cycle = (uint32_t)hal_get_cycles();
    1680 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1704if( DEBUG_PROCESS_TXT < cycle )
    16811705printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d  / cycle %d\n",
    16821706__FUNCTION__, CURRENT_THREAD, process->pid, txt_id, cycle );
     
    17051729    remote_spinlock_unlock( lock_xp );
    17061730
    1707 #if DEBUG_PROCESS_TXT_ATTACH
    1708 cycle = (uint32_t)hal_get_cycles();
    1709 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1731#if DEBUG_PROCESS_TXT
     1732cycle = (uint32_t)hal_get_cycles();
     1733if( DEBUG_PROCESS_TXT < cycle )
    17101734printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n",
    17111735__FUNCTION__, CURRENT_THREAD, process->pid, txt_id , cycle );
     
    17351759    "process descriptor not in owner cluster" );
    17361760
    1737 #if DEBUG_PROCESS_TXT_ATTACH
     1761#if DEBUG_PROCESS_TXT
    17381762uint32_t cycle = (uint32_t)hal_get_cycles();
    1739 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1763if( DEBUG_PROCESS_TXT < cycle )
    17401764printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    17411765__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    17611785    remote_spinlock_unlock( lock_xp );
    17621786
    1763 #if DEBUG_PROCESS_TXT_ATTACH
     1787#if DEBUG_PROCESS_TXT
    17641788cycle  = (uint32_t)hal_get_cycles();
    17651789uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    1766 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1790if( DEBUG_PROCESS_TXT < cycle )
    17671791printk("\n[DBG] %s : thread %x exit / process %x detached from TXT %d / cycle %d\n",
    17681792__FUNCTION__, CURRENT_THREAD, process_pid, txt_id, cycle );
     
    17931817    "process descriptor not in owner cluster\n" );
    17941818
    1795 #if DEBUG_PROCESS_TXT_ATTACH
     1819#if DEBUG_PROCESS_TXT
    17961820uint32_t cycle = (uint32_t)hal_get_cycles();
    1797 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1821if( DEBUG_PROCESS_TXT < cycle )
    17981822printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    17991823__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18111835    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
    18121836
    1813 #if DEBUG_PROCESS_TXT_ATTACH
    1814 cycle = (uint32_t)hal_get_cycles();
    1815 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1837#if DEBUG_PROCESS_TXT
     1838cycle = (uint32_t)hal_get_cycles();
     1839if( DEBUG_PROCESS_TXT < cycle )
    18161840printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
    18171841__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18501874    "process descriptor not in owner cluster\n" );
    18511875
    1852 #if DEBUG_PROCESS_TXT_ATTACH
     1876#if DEBUG_PROCESS_TXT
    18531877uint32_t cycle = (uint32_t)hal_get_cycles();
    1854 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1878if( DEBUG_PROCESS_TXT < cycle )
    18551879printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    18561880__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    18691893    txt_id   = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) );
    18701894
    1871 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1872 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1895#if( DEBUG_PROCESS_TXT & 1 )
     1896if( DEBUG_PROCESS_TXT < cycle )
    18731897printk("\n[DBG] %s : file_ptr %x / txt_ptr %x / txt_id %d / owner_ptr = %x\n",
    18741898__FUNCTION__, GET_PTR(file_xp), txt_ptr, txt_id, GET_PTR(owner_xp) );
     
    18881912        {
    18891913
    1890 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1891 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1914#if( DEBUG_PROCESS_TXT & 1 )
     1915if( DEBUG_PROCESS_TXT < cycle )
    18921916printk("\n[DBG] %s : process is not the KSH process => search the KSH\n", __FUNCTION__ );
    18931917#endif
     
    19071931                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19081932
    1909 #if DEBUG_PROCESS_TXT_ATTACH
    1910 cycle = (uint32_t)hal_get_cycles();
    1911 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1933#if DEBUG_PROCESS_TXT
     1934cycle = (uint32_t)hal_get_cycles();
     1935if( DEBUG_PROCESS_TXT < cycle )
    19121936printk("\n[DBG] %s : thread %x exit / process %x to KSH process %x / cycle %d\n",
    19131937__FUNCTION__, CURRENT_THREAD, process_pid,
     
    19291953        {
    19301954
    1931 #if( DEBUG_PROCESS_TXT_ATTACH & 1 )
    1932 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1955#if( DEBUG_PROCESS_TXT & 1 )
     1956if( DEBUG_PROCESS_TXT < cycle )
    19331957printk("\n[DBG] %s : process is the KSH process => search another\n", __FUNCTION__ );
    19341958#endif
     
    19491973                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19501974
    1951 #if DEBUG_PROCESS_TXT_ATTACH
    1952 cycle = (uint32_t)hal_get_cycles();
    1953 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1975#if DEBUG_PROCESS_TXT
     1976cycle = (uint32_t)hal_get_cycles();
     1977if( DEBUG_PROCESS_TXT < cycle )
    19541978printk("\n[DBG] %s : thread %x exit / KSH process %x to process %x / cycle %d\n",
    19551979__FUNCTION__, CURRENT_THREAD, process_pid,
     
    19661990            hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
    19671991
    1968 #if DEBUG_PROCESS_TXT_ATTACH
    1969 cycle = (uint32_t)hal_get_cycles();
    1970 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     1992#if DEBUG_PROCESS_TXT
     1993cycle = (uint32_t)hal_get_cycles();
     1994if( DEBUG_PROCESS_TXT < cycle )
    19711995printk("\n[DBG] %s : thread %x exit / KSH process %x to nobody / cycle %d\n",
    19721996__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
     
    19782002    {
    19792003
    1980 #if DEBUG_PROCESS_TXT_ATTACH
    1981 cycle = (uint32_t)hal_get_cycles();
    1982 if( DEBUG_PROCESS_TXT_ATTACH < cycle )
     2004#if DEBUG_PROCESS_TXT
     2005cycle = (uint32_t)hal_get_cycles();
     2006if( DEBUG_PROCESS_TXT < cycle )
    19832007printk("\n[DBG] %s : thread %x exit / process %x is not TXT owner / cycle %d\n",
    19842008__FUNCTION__, CURRENT_THREAD, process_pid, cycle );
Note: See TracChangeset for help on using the changeset viewer.