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

Introduce sys_place_fork() function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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()
Note: See TracChangeset for help on using the changeset viewer.