Changeset 584 for trunk


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

Introduce sys_place_fork() function.

Location:
trunk/kernel/syscalls
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_signal.h

    r445 r584  
    2727/*******************************************************************************************
    2828 * This defines the signal type mnemonics for the kill() syscall.
    29  * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported (december 2017)
     29 * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported by the
     30 *           sys_kill() function  ( [AG] december 2017 )
    3031 ******************************************************************************************/
    3132
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r566 r584  
    7878    SYS_GET_CYCLE      = 42,
    7979    SYS_DISPLAY        = 43,
    80     SYS_UNDEFINED      = 44,   ///
     80    SYS_PLACE_FORK     = 44, 
    8181    SYS_THREAD_SLEEP   = 45,
    8282    SYS_THREAD_WAKEUP  = 46,
  • trunk/kernel/syscalls/sys_display.c

    r580 r584  
    203203    else if( type == DISPLAY_CLUSTER_PROCESSES )
    204204    {
    205         cxy_t cxy = (cxy_t)arg0;
     205        cxy_t  cxy   = (cxy_t)arg0;
     206        bool_t owned = (bool_t)arg1;
    206207
    207208        // check cxy argument
     
    217218        }
    218219
    219         cluster_processes_display( cxy );
     220        cluster_processes_display( cxy , owned );
    220221    }
    221222    //////////////////////////////
  • trunk/kernel/syscalls/sys_exec.c

    r566 r584  
    196196
    197197#if DEBUG_SYSCALLS_ERROR
    198 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     198printk("\n[ERROR] in %s : thread[%x,%x] pathname too long\n",
     199__FUNCTION__, pid, this->trdid );
    199200#endif
    200201        this->errno = ENFILE;
     
    207208#if DEBUG_SYS_EXEC
    208209if( DEBUG_SYS_EXEC < tm_start )
    209 printk("\n[DBG] %s : thread %x in process %x enter for path <%s> / cycle = %d\n",
    210 __FUNCTION__, this->trdid, pid, exec_info.path, (uint32_t)tm_start );
     210printk("\n[DBG] %s : thread[%x,%x] enter for path <%s> / cycle = %d\n",
     211__FUNCTION__, pid, this->trdid, exec_info.path, (uint32_t)tm_start );
    211212#endif
    212213
     
    218219
    219220#if DEBUG_SYSCALLS_ERROR
    220 printk("\n[ERROR] in %s : thread %x in process %x cannot access args\n",
    221 __FUNCTION__ , this->trdid, pid );
     221printk("\n[ERROR] in %s : thread[%x,%x] cannot access args for <%s>\n",
     222__FUNCTION__, pid, this->trdid, exec_info.path );
    222223#endif
    223224            this->errno = EINVAL;
     
    233234
    234235#if DEBUG_SYSCALLS_ERROR
    235 printk("\n[ERROR] in %s : thread %x in process %x cannot access envs\n",
    236 __FUNCTION__ , this->trdid, pid );
     236printk("\n[ERROR] in %s : thread[%x,%x] cannot access envs for <%s>\n",
     237__FUNCTION__ , pid, this->trdid, exec_info.path );
    237238#endif
    238239            this->errno = EINVAL;
     
    248249
    249250#if DEBUG_SYSCALLS_ERROR
    250 printk("\n[ERROR] in %s : thread %x in process %x cannot create process for <%s>\n",
    251 __FUNCTION__, this->trdid, pid, exec_info.path );
     251printk("\n[ERROR] in %s : thread[%x,%x] cannot create process for <%s>\n",
     252__FUNCTION__, pid, this->trdid, exec_info.path );
    252253#endif
    253254        this->errno = error;
  • trunk/kernel/syscalls/sys_exit.c

    r566 r584  
    3838int sys_exit( uint32_t status )
    3939{
    40     reg_t       save_sr;           // required to enable IRQs
    41 
    4240    xptr_t      owner_xp;          // extended pointer on owner process
    4341    cxy_t       owner_cxy;         // owner process cluster
     
    6058tm_start = hal_get_cycles();
    6159if( DEBUG_SYS_EXIT < tm_start )
    62 printk("\n[DBG] %s : thread %x in process %x enter / status %x / cycle %d\n",
    63 __FUNCTION__, this->trdid, process->pid , status , (uint32_t)tm_start );
     60printk("\n[DBG] %s : thread[%x,%x] enter / status %x / cycle %d\n",
     61__FUNCTION__, process->pid, this->trdid , status , (uint32_t)tm_start );
    6462#endif
    6563
     
    7169#if (DEBUG_SYS_EXIT & 1)
    7270if( DEBUG_SYS_EXIT < tm_start )
    73 printk("\n[DBG] %s : thread %x in process %x get owner process in cluster %x\n",
    74 __FUNCTION__, this->trdid, process->pid, owner_cxy );
     71printk("\n[DBG] %s : thread[%x,%x] get owner process in cluster %x\n",
     72__FUNCTION__, process->pid, this->trdid, owner_cxy );
    7573#endif
    7674
     
    8583#if (DEBUG_SYS_EXIT & 1)
    8684if( DEBUG_SYS_EXIT < tm_start )
    87 printk("\n[DBG] %s : thread %x in process %x get parent process in cluster %x\n",
    88 __FUNCTION__, this->trdid, process->pid, parent_cxy );
     85printk("\n[DBG] %s : thread[%x,%x] get parent process in cluster %x\n",
     86__FUNCTION__, process->pid, this->trdid, parent_cxy );
    8987#endif
    9088
     
    9896#if( DEBUG_SYS_EXIT & 1)
    9997if( DEBUG_SYS_EXIT < tm_start )
    100 printk("\n[DBG] %s : thread %x in process %x detached process from TXT\n",
    101 __FUNCTION__, this->trdid, process->pid );
     98printk("\n[DBG] %s : thread[%x,%x] detached process from TXT\n",
     99__FUNCTION__, process->pid, this->trdid );
    102100#endif
    103101
    104102    // mark for delete all process threads in all clusters,
    105103    // but the main thread and this calling thread
    106     hal_enable_irq( &save_sr );
    107104    process_sigaction( process->pid , DELETE_ALL_THREADS );
    108     hal_restore_irq( save_sr );
    109105
    110106#if( DEBUG_SYS_EXIT & 1)
    111107if( DEBUG_SYS_EXIT < tm_start )
    112 printk("\n[DBG] %s : thread %x in process %x deleted all threads but itself\n",
    113 __FUNCTION__, this->trdid, process->pid );
     108printk("\n[DBG] %s : thread[%x,%x] deleted all threads but itself\n",
     109__FUNCTION__, process->pid, this->trdid );
    114110#endif
    115111
     
    120116#if( DEBUG_SYS_EXIT & 1)
    121117if( tm_start > DEBUG_SYS_EXIT )
    122 printk("\n[DBG] %s : thread %x in process %x marked iself for delete\n",
    123 __FUNCTION__, this->trdid, process->pid );
     118printk("\n[DBG] %s : thread[%x,%x] marked iself for delete\n",
     119__FUNCTION__, process->pid, this->trdid );
    124120#endif
    125121        thread_delete( XPTR( local_cxy , this ) , pid , true );
     
    131127#if( DEBUG_SYS_EXIT & 1)
    132128if( tm_start > DEBUG_SYS_EXIT )
    133 printk("\n[DBG] %s : thread %x in process %x blocked main thread\n",
    134 __FUNCTION__, this->trdid, process->pid );
     129printk("\n[DBG] %s : thread[%x,%x] blocked main thread\n",
     130__FUNCTION__, process->pid, this->trdid );
    135131#endif
    136132
     
    142138#if( DEBUG_SYS_EXIT & 1)
    143139if( tm_start > DEBUG_SYS_EXIT )
    144 printk("\n[DBG] %s : thread %x in process %x set exit status %x in owner process\n",
    145 __FUNCTION__, this->trdid, process->pid, term_state );
     140printk("\n[DBG] %s : thread[%x,%x] set exit status %x in owner process\n",
     141__FUNCTION__, process->pid, this->trdid, term_state );
    146142#endif
    147143
     
    151147#if( DEBUG_SYS_EXIT & 1)
    152148if( tm_start > DEBUG_SYS_EXIT )
    153 printk("\n[DBG] %s : thread %x in process %x unblocked parent main thread in process %x\n",
    154 __FUNCTION__ , this->trdid, process->pid,
     149printk("\n[DBG] %s : thread[%x,%x] unblocked parent main thread in process %x\n",
     150__FUNCTION__ , process->pid, this->trdid,
    155151hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid) ) );
    156152#endif
     
    161157tm_end = hal_get_cycles();
    162158if( DEBUG_SYS_EXIT < tm_end )
    163 printk("\n[DBG] %s : thread %x in process %x exit / status %x / cost = %d / cycle %d\n",
    164 __FUNCTION__, this->trdid, process->pid, status,
     159printk("\n[DBG] %s : thread[%x,%x] exit / status %x / cost = %d / cycle %d\n",
     160__FUNCTION__, process->pid, this->trdid, status,
    165161(uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    166162#endif
  • trunk/kernel/syscalls/sys_fork.c

    r566 r584  
    7373#if DEBUG_SYS_FORK
    7474if( DEBUG_SYS_FORK < tm_start )
    75 printk("\n[DBG] %s : thread %x in process %x enter / cycle =  %d\n",
    76 __FUNCTION__, parent_thread_ptr->trdid, parent_pid, (uint32_t)tm_start );
     75printk("\n[DBG] %s : thread[%x,%x] enter / cycle =  %d\n",
     76__FUNCTION__, parent_pid, parent_thread_ptr->trdid, (uint32_t)tm_start );
    7777#endif
    7878
     
    8888
    8989#if DEBUG_SYSCALLS_ERROR
    90 printk("\n[ERROR] in %s : thread %x in process %x cannot fork : too much children\n",
    91 __FUNCTION__, parent_thread_ptr->trdid, parent_pid );
     90printk("\n[ERROR] in %s : thread[%x,%x] cannot fork : too much children\n",
     91__FUNCTION__, parent_pid, parent_thread_ptr->trdid );
    9292#endif
    9393            hal_remote_atomic_add ( children_xp , -1 );
     
    110110#if (DEBUG_SYS_FORK & 1 )
    111111if( DEBUG_SYS_FORK < tm_start )
    112 printk("\n[DBG] %s : thread %x in process %x selected cluster %x\n",
    113 __FUNCTION__, parent_thread_ptr->trdid, parent_pid, child_cxy );
     112printk("\n[DBG] %s : thread[%x,%x] selected cluster %x\n",
     113__FUNCTION__, parent_pid, parent_thread_ptr->trdid, child_cxy );
    114114#endif
    115115
     
    136136
    137137#if DEBUG_SYSCALLS_ERROR
    138 printk("\n[ERROR] in %s : thread %x in process %x cannot fork to cluster %x\n",
    139 __FUNCTION__, parent_thread_ptr->trdid, parent_pid, local_cxy );
     138printk("\n[ERROR] in %s : thread[%x,%x] cannot fork\n",
     139__FUNCTION__, parent_pid, parent_thread_ptr->trdid );
    140140#endif
    141141        parent_thread_ptr->errno = EAGAIN;
     
    167167#if DEBUG_SYS_FORK
    168168if( DEBUG_SYS_FORK < tm_end )
    169 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n",
    170 __FUNCTION__, current->trdid, current->process->pid, (uint32_t)tm_end );
     169printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     170__FUNCTION__, current->process->pid, current->trdid, (uint32_t)tm_end );
    171171#endif
    172172
  • trunk/kernel/syscalls/sys_kill.c

    r566 r584  
    3535#include <syscalls.h>
    3636
     37
     38#if DEBUG_SYS_KILL
     39////////////////////////////////////////////
     40static char* sig_type_str( uint32_t sig_id )
     41{
     42    switch( sig_id )
     43    {
     44        case SIGKILL: return "SIGKILL";
     45        case SIGSTOP: return "SIGSTOP";
     46        case SIGCONT: return "SIGCONT";
     47        default:      return "undefined";
     48    }
     49}
     50#endif
     51
     52
    3753///////////////////////////
    3854int sys_kill( pid_t    pid,
    3955              uint32_t sig_id )
    4056{
    41     reg_t       save_sr;           // required to enable IRQs
    4257    xptr_t      owner_xp;          // extended pointer on process in owner cluster
    4358    cxy_t       owner_cxy;         // process owner cluster
    4459    process_t * owner_ptr;         // local pointer on process in owner cluster
    45     uint32_t    retval;            // return value for the switch
    4660    xptr_t      parent_xp;         // extended pointer on parent process
    4761    cxy_t       parent_cxy;        // parent process cluster
     
    5367    process_t * process = this->process;
    5468
     69#if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)
     70uint64_t     tm_start = hal_get_cycles();
     71#endif
     72
    5573#if DEBUG_SYS_KILL
    56 uint64_t    tm_start;
    57 uint64_t    tm_end;
    5874tm_start = hal_get_cycles();
    5975if( DEBUG_SYS_KILL < tm_start )
    60 printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n",
    61 __FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start );
     76printk("\n[DBG] %s : thread[%x,%x] enter / process %x / %s / cycle %d\n",
     77__FUNCTION__, this->process->pid, this->trdid, pid,
     78sig_type_str(sig_id), (uint32_t)tm_start );
    6279#endif
    6380
     
    6986#if (DEBUG_SYS_KILL & 1)
    7087if( DEBUG_SYS_KILL < tm_start )
    71 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
    72 __FUNCTION__ , this, owner_ptr, owner_cxy );
     88printk("\n[DBG] %s : thread[%x,%x] get owner process %x in cluster %x\n",
     89__FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy );
    7390#endif
    7491
     
    8198#endif
    8299        this->errno = EINVAL;
    83         return -1;
    84     }
    85 
    86     // process cannot kill itself
    87     if( (pid == process->pid) )
    88     {
    89 
    90 #if DEBUG_SYSCALLS_ERROR
    91 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );
    92 #endif
    93         this->errno = EINVAL;
    94         return -1;
    95     }
    96 
    97     // processe INIT cannot be killed
    98     if( pid == 1 )
    99     {
    100 
    101 #if DEBUG_SYSCALLS_ERROR
    102 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
    103 #endif
    104                 this->errno = EINVAL;
    105100        return -1;
    106101    }
     
    113108#if (DEBUG_SYS_KILL & 1)
    114109if( DEBUG_SYS_KILL < tm_start )
    115 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
    116 __FUNCTION__ , this, parent_ptr, parent_cxy );
     110printk("\n[DBG] %s : thread[%x,%x] get parent process %x in cluster %x\n",
     111__FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy );
    117112#endif
    118113
     
    126121        case 0 :          // does nothing
    127122        {
    128             retval = 0;
    129123            break;
    130124        }
    131125        case SIGSTOP:     // block all target process threads
    132126        {
    133             // transfer TXT ownership
    134             process_txt_transfer_ownership( owner_xp );
    135 
    136             // block all threads in all clusters, but the main thread
     127            // block all threads in all clusters
    137128            process_sigaction( pid , BLOCK_ALL_THREADS );
    138 
    139             // block the main thread
    140             xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );
    141             thread_block( main_xp , THREAD_BLOCKED_GLOBAL );
    142129
    143130            // atomically update owner process termination state
     
    145132                                  PROCESS_TERM_STOP );
    146133
    147             // unblock the parent process main thread 
     134            // unblock the parent process main thread
    148135            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
    149136
    150             retval = 0;
    151137            break;
    152138        }
     
    159145            hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    160146                                   ~PROCESS_TERM_STOP );
    161             retval = 0;
    162             break;
    163         }
    164         break;
     147
     148            // unblock the parent process main thread
     149            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     150
     151            break;
     152        }
    165153        case SIGKILL:
    166154        {
     155            // a process cannot kill itself
     156            if( (pid == process->pid) )
     157            {
     158
     159#if DEBUG_SYSCALLS_ERROR
     160printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );
     161#endif
     162                this->errno = EINVAL;
     163                return -1;
     164            }
     165
     166            // processe INIT cannot be killed
     167            if( pid == 1 )
     168            {
     169
     170#if DEBUG_SYSCALLS_ERROR
     171printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
     172#endif
     173                        this->errno = EINVAL;
     174                return -1;
     175            }
     176
    167177            // remove process from TXT list
    168178            process_txt_detach( owner_xp );
    169179
    170180            // mark for delete all threads in all clusters, but the main
    171             hal_enable_irq( &save_sr );
    172181            process_sigaction( pid , DELETE_ALL_THREADS );
    173             hal_restore_irq( save_sr );
    174182
    175183            // block main thread
     
    185193            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
    186194
    187             retval = 0;
    188195            break;
    189196        }
     
    195202#endif
    196203            this->errno = EINVAL;
    197             retval = -1;
    198             break;
     204            return -1;
    199205        }
    200206    }
     
    202208    hal_fence();
    203209
     210#if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)
     211uint64_t     tm_end = hal_get_cycles();
     212#endif
     213
    204214#if DEBUG_SYS_KILL
    205 tm_end = hal_get_cycles();
    206215if( DEBUG_SYS_KILL < tm_end )
    207 printk("\n[DBG] %s : thread %x exit / process %x / sig %d / cost = %d / cycle %d\n",
    208 __FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    209 #endif
    210 
    211         return retval;
     216printk("\n[DBG] %s : thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",
     217__FUNCTION__ , this->process->pid, this->trdid, pid,
     218sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     219#endif
     220
     221#if CONFIG_INSTRUMENTATION_SYSCALLS
     222hal_atomic_add( &syscalls_cumul_cost[SYS_KILL] , tm_end - tm_start );
     223hal_atomic_add( &syscalls_occurences[SYS_KILL] , 1 );
     224#endif
     225
     226        return 0;
    212227
    213228}  // end sys_kill()
  • trunk/kernel/syscalls/sys_read.c

    r566 r584  
    7272#if DEBUG_SYS_READ
    7373if( DEBUG_SYS_READ < tm_start )
    74 printk("\n[DBG] %s : thread %x in process %x enter / vaddr %x / count %d / cycle %d\n",
    75 __FUNCTION__, this->trdid, process->pid, vaddr, count, (uint32_t)tm_start );
     74printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
     75__FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start );
    7676#endif
    7777
     
    8585
    8686#if DEBUG_SYSCALLS_ERROR
    87 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", __FUNCTION__ , file_id );
     87printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index = %d\n",
     88__FUNCTION__ , process->pid, this->trdid, file_id );
    8889#endif
    8990                this->errno = EBADFD;
     
    9899
    99100#if DEBUG_SYSCALLS_ERROR
    100 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",
    101 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     101printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n",
     102__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
    102103vmm_display( process , false );
    103104#endif
     
    116117
    117118#if DEBUG_SYSCALLS_ERROR
    118 printk("\n[ERROR] in %s : undefined fd_id %d in process %x\n",
    119 __FUNCTION__ , file_id , process->pid );
     119printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
     120__FUNCTION__, process->pid, this->trdid, file_id );
    120121#endif
    121122        this->errno = EBADFD;
     
    127128    cxy_t        file_cxy = GET_CXY( file_xp );
    128129
    129     // check file readable
    130     uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
    131     if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    132         {
    133 
    134 #if DEBUG_SYSCALLS_ERROR
    135 printk("\n[ERROR] in %s : file %d not readable in process %x\n",
    136 __FUNCTION__ , file_id , process->pid );
    137 #endif
    138                 this->errno = EBADFD;
    139                 return -1;
    140         }
    141    
    142130    // get file type
    143131    vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
     
    153141
    154142#if DEBUG_SYSCALLS_ERROR
    155 printk("\n[ERROR] in %s : file %d not readable in process %x\n",
    156 __FUNCTION__ , file_id , process->pid );
     143printk("\n[ERROR] in %s : thread[%x,%x] file %d not readable\n",
     144__FUNCTION__, process->pid, this->trdid, file_id );
    157145#endif
    158146                    this->errno = EBADFD;
     
    185173            {
    186174                if( (iter & 0xFFF) == 0 )
    187                 printk("\n[WARNING] in %s : thread %x in process %x wait TXT_RX / cycle %d\n",
    188                 __FUNCTION__, this->trdid, process->pid, (uint32_t)hal_get_cycles() );
     175                printk("\n[WARNING] in %s : thread[%x,%x] wait TXT_RX / cycle %d\n",
     176                __FUNCTION__, process->pid, this->trdid, (uint32_t)hal_get_cycles() );
    189177
    190178                // deschedule without blocking
     
    216204
    217205#if DEBUG_SYSCALLS_ERROR
    218 printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",
    219 __FUNCTION__ , file_id , process->pid );
     206printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",
     207__FUNCTION__, process->pid, this->trdid, file_id );
    220208#endif
    221209        this->errno = error;
     
    234222#if DEBUG_SYS_READ
    235223if( DEBUG_SYS_READ < tm_end )
    236 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n",
    237 __FUNCTION__ , this->trdid, process->pid, (uint32_t)tm_end );
     224printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     225__FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end );
    238226#endif
    239227
  • trunk/kernel/syscalls/sys_thread_exit.c

    r566 r584  
    3636int sys_thread_exit( void * exit_value )
    3737{
    38     reg_t       save_sr;    // required to enable IRQs
    39     xptr_t      owner_xp;   // extended pointer on owner process
    40  
    4138        thread_t  * this      = CURRENT_THREAD;
    4239    trdid_t     trdid     = this->trdid;
    4340    process_t * process   = this->process;
    4441    pid_t       pid       = process->pid;
    45     cxy_t       owner_cxy = CXY_FROM_PID( pid );
    4642
    4743    // check exit_value argument
     
    5753    }
    5854
    59 #if DEBUG_SYS_THREAD_EXIT
    60 uint64_t     tm_start;
    61 uint64_t     tm_end;
    62 tm_start = hal_get_cycles();
    63 if( DEBUG_SYS_THREAD_EXIT < tm_start )
    64 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
    65 __FUNCTION__ , this->trdid, pid , (uint32_t)tm_start );
    66 #endif
    6755
    6856    // If calling thread is the main thread, the process must be deleted.
    69     // This require to delete all process threads and synchronise with parent process
    70     if( (local_cxy == owner_cxy) && (LTID_FROM_TRDID(trdid) == 0) )
     57    // => delete all process threads and synchronise with parent process.
     58    // If calling thread is not the main thread, it must be deleted.
     59    // => block the thread and mark it for delete.
     60    if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) )
    7161    {
    72         // get extended pointer on owner cluster
    73         owner_xp = cluster_get_owner_process_from_pid( pid );
    7462
    75         // mark for delete all threads but the main
    76         hal_enable_irq( &save_sr );
    77         process_sigaction( pid , DELETE_ALL_THREADS );
    78         hal_restore_irq( save_sr );
    79 
    80         // remove process from TXT list
    81         process_txt_detach( owner_xp );
    82 
    83         // block the main thread
    84         thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL );
    85 
    86         // atomically update owner process descriptor term_state to ask
    87         // the parent process sys_wait() function to delete the main thread
    88         hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) ,
    89                               PROCESS_TERM_EXIT );
     63#if DEBUG_SYS_THREAD_EXIT
     64uint64_t     tm_start = hal_get_cycles();
     65if( DEBUG_SYS_THREAD_EXIT < tm_start )
     66printk("\n[DBG] %s : thread[%x,%x] / main => delete process / cycle %d\n",
     67__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
     68#endif
     69        // delete process
     70        sys_exit( 0 );
    9071    }
    9172    else
    9273    {
     74
     75#if DEBUG_SYS_THREAD_EXIT
     76uint64_t     tm_start = hal_get_cycles();
     77if( DEBUG_SYS_THREAD_EXIT < tm_start )
     78printk("\n[DBG] %s : thread[%x,%x] / not main => delete thread / cycle %d\n",
     79__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
     80#endif
    9381        // block calling thread and mark it for delete,
    9482        thread_delete( XPTR( local_cxy , this ) , pid , false );
     83
     84        // deschedule
     85        sched_yield( "suicide after thread_exit" );
    9586    }
    9687
    97 #if DEBUG_SYS_THREAD_EXIT
    98 tm_end = hal_get_cycles();
    99 if( DEBUG_SYS_THREAD_EXIT < tm_end )
    100 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",
    101 __FUNCTION__, this->trdid, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    102 #endif
    103 
    104     // deschedule <=> suicide, because blocked by thread_delete()
    105     sched_yield( "suicide after thread_exit" );
    106    
    10788    return 0;   // never executed but required by compiler
    10889
  • trunk/kernel/syscalls/sys_thread_join.c

    r566 r584  
    6767tm_start = hal_get_cycles();
    6868if( DEBUG_SYS_THREAD_JOIN < tm_start )
    69 printk("\n[DBG] %s : thread %x in process %x enter / target thread %x / cycle %d\n",
    70 __FUNCTION__ , joining_ptr->trdid, process->pid, trdid , (uint32_t)tm_start );
     69printk("\n[DBG] %s : joining thread[%x,%x] enter / target thread[%x,%x] / cycle %d\n",
     70__FUNCTION__ , process->pid, joining_ptr->trdid,
     71process->pid, trdid, (uint32_t)tm_start );
    7172#endif
    7273
    7374    // check trdid argument
    74         if( (target_ltid >= CONFIG_THREADS_MAX_PER_CLUSTER) || cluster_is_undefined( target_cxy ) ) 
     75        if( (target_ltid >= CONFIG_THREADS_MAX_PER_CLUSTER) || cluster_is_undefined(target_cxy) )
    7576        {
    7677
    7778#if DEBUG_SYSCALLS_ERROR
    78 printk("\n[ERROR] in %s : illegal trdid argument %x\n", __FUNCTION__, trdid );
     79printk("\n[ERROR] in %s : illegal trdid argument %x\n",
     80__FUNCTION__, trdid );
    7981#endif
    8082                joining_ptr->errno = EINVAL;
     
    8789
    8890#if DEBUG_SYSCALLS_ERROR
    89 printk("\n[ERROR] in %s : exit_value argument must be NULL\n", __FUNCTION__ );
     91printk("\n[ERROR] in %s : exit_value argument must be NULL\n",
     92__FUNCTION__ );
    9093#endif
    9194                joining_ptr->errno = EINVAL;
     
    113116
    114117#if DEBUG_SYSCALLS_ERROR
    115 printk("\n[ERROR] in %s : target thread %x not found\n", __FUNCTION__, trdid );
     118printk("\n[ERROR] in %s : target thread %x not found\n",
     119__FUNCTION__, trdid );
    116120#endif
    117121        joining_ptr->errno = ESRCH;
     
    145149    if( hal_remote_l32( target_flags_xp ) & THREAD_FLAG_KILL_DONE )  // killer thread is first
    146150    {
    147 
    148 #if (DEBUG_SYS_THREAD_JOIN & 1)
    149 if( DEBUG_SYS_THREAD_JOIN < tm_start )
    150 printk("\n[DBG] %s : thread %x in process %x / killer thread arrived first\n",
    151 __FUNCTION__ , joining_ptr->trdid, process->pid );
    152 #endif
    153151        // get pointers on killer thread
    154152        killer_xp  = (xptr_t)hal_remote_l64( target_join_xp_xp );
     
    163161        remote_busylock_release( target_join_lock_xp );
    164162
    165         // restore IRQs
    166         hal_restore_irq( save_sr );
     163#if DEBUG_SYS_THREAD_JOIN
     164tm_end = hal_get_cycles();
     165if( DEBUG_SYS_THREAD_JOIN < tm_end )
     166printk("\n[DBG] %s : joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n",
     167__FUNCTION__, process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end );
     168#endif
     169
    167170    }
    168171    else                                                          // joining thread is first
    169172    {
    170 
    171 #if (DEBUG_SYS_THREAD_JOIN & 1)
    172 if( DEBUG_SYS_THREAD_JOIN < tm_start )
    173 printk("\n[DBG] %s : thread %x in process %x / joining thread arrived first\n",
    174 __FUNCTION__ , joining_ptr->trdid, process->pid );
    175 #endif
    176173        // set the join_done flag in target thread
    177174        hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_JOIN_DONE );
     
    186183        remote_busylock_release( target_join_lock_xp );
    187184
    188 #if (DEBUG_SYS_THREAD_JOIN & 1)
     185#if DEBUG_SYS_THREAD_JOIN
    189186if( DEBUG_SYS_THREAD_JOIN < tm_start )
    190 printk("\n[DBG] %s : thread %x in process %x / joining thread deschedule\n",
    191 __FUNCTION__ , joining_ptr->trdid, process->pid );
     187printk("\n[DBG] %s : joining thread[%x,%x] deschedules / target thread[%x,%x] not completed\n",
     188__FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid );
    192189#endif
    193190        // deschedule
    194191        sched_yield( "joining thread waiting killer thread" );
    195192   
    196 #if (DEBUG_SYS_THREAD_JOIN & 1)
    197 if( DEBUG_SYS_THREAD_JOIN < tm_start )
    198 printk("\n[DBG] %s : thread %x in process %x / joining thread resume\n",
    199 __FUNCTION__ , joining_ptr->trdid, process->pid );
    200 #endif
    201         // restore IRQs
    202         hal_restore_irq( save_sr );
    203     }
    204 
    205 #if DEBUG_SYS_THREAD_JOIN
     193#if DEBUG_SYS_THREAD_JOIN
    206194tm_end = hal_get_cycles();
    207195if( DEBUG_SYS_THREAD_JOIN < tm_end )
    208 printk("\n[DBG] %s : thread %x in process %x exit / target thread %x / cycle %d\n",
    209 __FUNCTION__, joining_ptr->trdid, process->pid, (uint32_t)tm_end );
    210 #endif
     196printk("\n[DBG] %s : joining thread[%x,%x] exit / target thread[%x,%x] completed / cycle %d\n",
     197__FUNCTION__ , process->pid, joining_ptr->trdid, process->pid, trdid, (uint32_t)tm_end );
     198#endif
     199
     200    }
     201
     202    // restore IRQs
     203    hal_restore_irq( save_sr );
    211204
    212205    return 0;
  • trunk/kernel/syscalls/sys_write.c

    r566 r584  
    7171tm_start = hal_get_cycles();
    7272if( DEBUG_SYS_WRITE < tm_start )
    73 printk("\n[DBG] %s : thread %x in process %x enter / vaddr %x / count %d / cycle %d\n",
    74 __FUNCTION__, this->trdid, process->pid, vaddr, count, (uint32_t)tm_start );
     73printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
     74__FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start );
    7575#endif
    7676 
     
    8484
    8585#if DEBUG_SYSCALLS_ERROR
    86 printk("\n[ERROR] in %s : illegal file descriptor index\n", __FUNCTION__ );
     86printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
     87__FUNCTION__, process->pid, this->trdid, file_id );
    8788#endif
    8889        this->errno = EBADFD;
     
    9798
    9899#if DEBUG_SYSCALLS_ERROR
    99 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",
    100 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid );
     100printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n",
     101__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
    101102vmm_display( process , false );
    102103#endif
     
    112113
    113114#if DEBUG_SYSCALLS_ERROR
    114 printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
    115 __FUNCTION__ , file_id , process->pid );
     115printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor index = %d\n",
     116__FUNCTION__, process->pid, this->trdid, file_id );
    116117#endif
    117118                this->errno = EBADFD;
     
    139140
    140141#if DEBUG_SYSCALLS_ERROR
    141 printk("\n[ERROR] in %s : file %d not writable in process %x\n",
    142 __FUNCTION__ , file_id , process->pid );
     142printk("\n[ERROR] in %s : thread[%x,%x] file %d not writable\n",
     143__FUNCTION__ , process->pid, this->trdid, file_id );
    143144#endif
    144145                    this->errno = EBADFD;
     
    159160
    160161#if DEBUG_SYSCALLS_ERROR
    161 printk("\n[ERROR] in %s : user buffer size %x too large / thread %x / process %x\n",
    162 __FUNCTION__ , count, this->trdid, process->pid );
     162printk("\n[ERROR] in %s : thread[%x,%x] user buffer size %x too large\n",
     163__FUNCTION__ , process->pid, this->trdid, count );
    163164#endif
    164165                    this->errno = EINVAL;
     
    182183
    183184#if DEBUG_SYSCALLS_ERROR
    184 printk("\n[ERROR] in %s cannot write data to file %d in process %x\n",
    185 __FUNCTION__ , file_id , process->pid );
     185printk("\n[ERROR] in %s : thread[%x,‰x] cannot write data to file %d\n",
     186__FUNCTION__ , process->pid, this->trdid, file_id );
    186187#endif
    187188        this->errno = error;
     
    200201#if DEBUG_SYS_WRITE
    201202if( DEBUG_SYS_WRITE < tm_end )
    202 printk("\n[DBG] %s : thread %x in process %x exit / cycle %d\n",
    203 __FUNCTION__, this->trdid, process->pid, (uint32_t)tm_end );
     203printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     204__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
    204205#endif
    205206 
  • trunk/kernel/syscalls/syscalls.h

    r566 r584  
    409409/******************************************************************************************
    410410 * [32] This function associate a specific signal handler to a given signal type.
    411  * Tee handlers for the SIGKILL and SIGSTOP signals cannot be redefined.
     411 * The handlers for the SIGKILL and SIGSTOP signals cannot be redefined.
    412412 ******************************************************************************************
    413413 * @ sig_id    : index defining signal type (from 1 to 31).
     
    530530
    531531/******************************************************************************************
    532  * [40] This function returns the hardware platform parameters.
     532 * [40] This function implement the non-standard get_config() syscall.
     533 * It returns in <x_size>, <y_size>, <ncores> the hardware platform parameters.
    533534 ******************************************************************************************
    534535 * @ x_size   : [out] number of clusters in a row.
     
    542543
    543544/******************************************************************************************
    544  * [41] This function returns the calling core cluster and local index.
     545 * [41] This function implements the non-standard get_core() syscall.
     546 * It returns in <cxy> and <lid> the calling core cluster and local index.
    545547 ******************************************************************************************
    546548 * @ cxy      : [out] cluster identifier (fixed format)
     
    552554
    553555/******************************************************************************************
    554  * [42] This function returns in a 64 bits user buffer the calling core cycles count.
     556 * [42] This function implements the non-standard get_cycle() syscall.
     557 * It returns in a 64 bits user buffer the calling core cycles count.
    555558 * It uses both the hardware register and the core descriptor cycles count to take
    556559 * into account a possible harware register overflow  in 32 bits architectures.
     
    584587
    585588/******************************************************************************************
    586  * [44] TBD
     589 * [44] This function implements the non-standard place_fork() syscall.
     590 * It can be used to specify the target cluster <cxy> for a new process created
     591 * by a subsequent fork() syscall.
     592 * WARNING: it must be called before each fork() syscall, as the placement specification
     593 *          is reset by the fork syscall.
    587594 ******************************************************************************************
    588595 * @ cxy    : cluster identifier.
    589  * @ lid    : core local index.
    590  * @ return 0 if success / return -1 if failure.
    591  *****************************************************************************************/
    592 int sys_place( uint32_t cxy,
    593                uint32_t lid );
     596 * @ return 0 if success / return -1 if failure.
     597 *****************************************************************************************/
     598int sys_place_fork( uint32_t cxy );
    594599
    595600/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.