Changeset 435 for trunk/kernel/syscalls


Ignore:
Timestamp:
Feb 20, 2018, 5:32:17 PM (7 years ago)
Author:
alain
Message:

Fix a bad bug in scheduler...

Location:
trunk/kernel/syscalls
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_syscalls.h

    r421 r435  
    321321typedef enum
    322322{
    323     DISPLAY_STRING  = 0,
    324     DISPLAY_VMM     = 1,
    325     DISPLAY_SCHED   = 2,
    326     DISPLAY_PROCESS = 3,
    327     DISPLAY_VFS     = 4,
    328     DISPLAY_CHDEV   = 5,
     323    DISPLAY_STRING            = 0,
     324    DISPLAY_VMM               = 1,
     325    DISPLAY_SCHED             = 2,
     326    DISPLAY_CLUSTER_PROCESSES = 3,
     327    DISPLAY_VFS               = 4,
     328    DISPLAY_CHDEV             = 5,
     329    DISPLAY_TXT_PROCESSES     = 6,
    329330}
    330331display_type_t;
     
    391392
    392393
     394/*********************************************************************************************
     395 * These macros can be used by the parent process to analyze a child process
     396 * termination status, as returned by the wait() syscall.
     397 * The termination state is a 32 bits word:
     398 * - the 8 LSB bits contain the user defined exit status
     399 * - the 24 other bits contain the flags defined below
     400 ********************************************************************************************/
     401
     402#define PROCESS_TERM_STOP  0x100            /*! process received a SIGSTOP signal           */
     403#define PROCESS_TERM_KILL  0x200            /*! process killed by a SIGKILL signal          */
     404#define PROCESS_TERM_EXIT  0x400            /*! process terminated by a sys_exit()          */
     405#define PROCESS_TERM_WAIT  0x800            /*! parent process executed a sys_wait()        */
     406
     407#define WIFEXITED( status )       (status & PROCESS_TERM_EXIT)
     408#define WIFSIGNALED( status )     (status & PROCESS_TERM_KILL)
     409#define WIFSTOPPED( status )      (status & PROCESS_TERM_STOP)
     410#define WEXITSTATUS( status )     (status & 0xFF)
     411
    393412
    394413#endif  // _SHARED_SYSCALLS_H_
  • trunk/kernel/syscalls/sys_display.c

    r433 r435  
    142142        }
    143143    }
    144     else if( type == DISPLAY_PROCESS )
     144    else if( type == DISPLAY_CLUSTER_PROCESSES )
    145145    {
    146146        cxy_t cxy = (cxy_t)arg0;
     
    155155
    156156        cluster_processes_display( cxy );
     157    }
     158    else if( type == DISPLAY_TXT_PROCESSES )
     159    {
     160        uint32_t txt_id = (uint32_t)arg0;
     161
     162        // check argument
     163            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
     164        {
     165            printk("\n[ERROR] in %s : undefined TXT channel %x\n",
     166            __FUNCTION__ , txt_id );
     167            return -1;
     168        }
     169
     170        process_txt_display( txt_id );
    157171    }
    158172    else if( type == DISPLAY_VFS )
  • trunk/kernel/syscalls/sys_exec.c

    r433 r435  
    221221printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
    222222#endif
    223             this->errno = error;
     223            this->errno = EINVAL;
    224224            return -1;
    225225        }
     
    235235printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
    236236#endif
    237             this->errno = error;
     237            this->errno = EINVAL;
    238238            return -1;
    239239        }
     
    248248#if CONFIG_DEBUG_SYSCALLS_ERROR
    249249printk("\n[ERROR] in %s : cannot create process %x in cluster %x\n",
    250 __FUNCTION__, pid, CXY_FROM_PID( pid );
     250__FUNCTION__, pid, CXY_FROM_PID(pid) );
    251251#endif
    252252        this->errno = error;
  • trunk/kernel/syscalls/sys_exit.c

    r433 r435  
    2929#include <printk.h>
    3030#include <process.h>
    31 #include <signal.h>
     31#include <shared_syscalls.h>
    3232#include <cluster.h>
    3333#include <rpc.h>
     
    5151#endif
    5252
    53     // get cluster and pointers on process in owner cluster
    54     xptr_t      owner_xp  = cluster_get_owner_process_from_pid( pid );
    55     cxy_t       owner_cxy = GET_CXY( owner_xp );
    56     process_t * owner_ptr = GET_PTR( owner_xp );
     53    // get owner cluster
     54    cxy_t  owner_cxy = CXY_FROM_PID( pid );
    5755
    58     assert( (owner_xp != XPTR_NULL) , __FUNCTION__ , "owner_xp cannot be NULL\n" );
     56    // exit must be called by the main thread
     57    if( (owner_cxy != local_cxy) || (LTID_FROM_TRDID( this->trdid ) != 0) )
     58    {
     59
     60#if CONFIG_DEBUG_SYSCALLS_ERROR
     61printk("\n[ERROR] %s must be called by thread 0 in process owner cluster\n"
     62       "         trdid = %x / pid = %x / local_cxy = %x\n",
     63__FUNCTION__, this->trdid, pid, local_cxy );
     64#endif
     65         this->errno = EINVAL;
     66         return -1;
     67    }
    5968
    6069    // enable IRQs
    6170    hal_enable_irq( &save_sr );
    6271
    63     // the process_make_kill() function must be executed
    64     // by an RPC thread in reference cluster
    65     rpc_process_make_kill_client( owner_cxy, owner_ptr, true , status );
     72    // register exit_status in owner process descriptor
     73    process->term_state = status;
     74
     75    // remove TXT ownership from owner process descriptor
     76    process_txt_reset_ownership( XPTR( local_cxy , process ) );
     77
     78    // block all process threads in all clusters
     79    process_sigaction( pid , BLOCK_ALL_THREADS );
     80
     81    // mark all process threads in all clusters for delete
     82    process_sigaction( pid , DELETE_ALL_THREADS );
    6683
    6784    // restore IRQs
    6885    hal_restore_irq( save_sr );
    6986
     87    // atomically update owner process descriptor term_state
     88    hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) ,
     89                          PROCESS_TERM_EXIT );
    7090    hal_fence();
    7191
  • trunk/kernel/syscalls/sys_fork.c

    r433 r435  
    8181    if( hal_remote_atomic_add( children_xp , 1 ) >= CONFIG_PROCESS_MAX_CHILDREN )
    8282        {
    83             printk("\n[ERROR] in %s : too much children processes\n", __FUNCTION__);
     83
     84#if CONFIG_DEBUG_SYSCALLS_ERROR
     85printk("\n[ERROR] in %s : too much children processes\n", __FUNCTION__);
     86#endif
    8487            hal_remote_atomic_add ( children_xp , -1 );
    8588        parent_thread_ptr->errno = EAGAIN;
     
    119122    if( error )
    120123    {
    121         printk("\n[ERROR] in %s : cannot fork process %x in cluster %x\n",
    122         __FUNCTION__, parent_pid, local_cxy );
     124
     125#if CONFIG_DEBUG_SYSCALLS_ERROR
     126printk("\n[ERROR] in %s : cannot fork process %x in cluster %x\n",
     127__FUNCTION__, parent_pid, local_cxy );
     128#endif
    123129        parent_thread_ptr->errno = EAGAIN;
    124130        return -1;
  • trunk/kernel/syscalls/sys_get_config.c

    r421 r435  
    3535int sys_get_config( uint32_t * x_size,
    3636                    uint32_t * y_size,
    37                     uint32_t * y_width,
    3837                    uint32_t * ncores )
    3938{
     
    4140    uint32_t  k_x_size;
    4241    uint32_t  k_y_size;
    43     uint32_t  k_y_width;
    4442    uint32_t  k_ncores;
    4543
     
    4947    process_t * process = this->process;
    5048
     49#if CONFIG_DEBUG_SYS_GET_CONFIG
     50uint64_t     tm_start;
     51uint64_t     tm_end;
     52tm_start = hal_get_cycles();
     53if( CONFIG_DEBUG_SYS_GET_CONFIG < tm_start )
     54printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
     55__FUNCTION__, this, process->pid, (uint32_t)tm_start );
     56#endif
     57
    5158    // check buffer in user space
    5259    error |= vmm_v2p_translate( false , x_size  , &paddr );
    5360    error |= vmm_v2p_translate( false , y_size  , &paddr );
    54     error |= vmm_v2p_translate( false , y_width , &paddr );
    5561    error |= vmm_v2p_translate( false , ncores  , &paddr );
    5662
    5763        if( error )
    5864        {
    59         printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n",
    60                __FUNCTION__ , this->trdid , process->pid );
     65
     66#if CONFIG_DEBUG_SYSCALLS_ERROR
     67printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n",
     68__FUNCTION__ , this->trdid , process->pid );
     69#endif
    6170        this->errno = EFAULT;
    6271                return -1;
     
    6675        k_x_size  = LOCAL_CLUSTER->x_size;
    6776        k_y_size  = LOCAL_CLUSTER->y_size;
    68         k_y_width = LOCAL_CLUSTER->y_width;
    6977        k_ncores  = LOCAL_CLUSTER->cores_nr;
    7078
     
    7280        hal_copy_to_uspace( x_size  , &k_x_size  , sizeof(uint32_t) );
    7381        hal_copy_to_uspace( y_size  , &k_y_size  , sizeof(uint32_t) );
    74         hal_copy_to_uspace( y_width , &k_y_width , sizeof(uint32_t) );
    7582        hal_copy_to_uspace( ncores  , &k_ncores  , sizeof(uint32_t) );
     83
     84    hal_fence();
     85
     86#if CONFIG_DEBUG_SYS_GET_CONFIG
     87tm_end = hal_get_cycles();
     88if( CONFIG_DEBUG_SYS_GET_CONFIG < tm_end )
     89printk("\n[DBG] %s : thread %x exit / process %x / cost %d / tycle %d\n",
     90__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
     91#endif
    7692
    7793        return 0;
  • trunk/kernel/syscalls/sys_kill.c

    r433 r435  
    4848
    4949    thread_t  * this    = CURRENT_THREAD;
     50    process_t * process = this->process;
    5051
    5152#if CONFIG_DEBUG_SYS_KILL
     
    5859#endif
    5960
    60     // get cluster and pointers on owner process
     61    // process cannot kill itself
     62    if( pid == process->pid )
     63    {
     64
     65#if CONFIG_DEBUG_SYSCALLS_ERROR
     66printk("\n[ERROR] in %s : process %d cannot kill itself\n", __FUNCTION__ , pid );
     67#endif
     68        this->errno = EINVAL;
     69        return -1;
     70    }
     71
     72    // get cluster and pointers on owner target process descriptor
    6173    owner_xp  = cluster_get_owner_process_from_pid( pid );
    6274    owner_cxy = GET_CXY( owner_xp );
     
    6779    {
    6880
    69 syscall_dmsg("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
    70 
     81#if CONFIG_DEBUG_SYSCALLS_ERROR
     82printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
     83#endif
    7184        this->errno = EINVAL;
    7285        return -1;
     
    7992    ppid       = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    8093
    81     // processes INIT and processes KSH cannot be stoped or killed
    82     if( ppid < 2 )
     94    // processes INIT
     95    if( pid == 1 )
    8396    {
    8497
    85 syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", __FUNCTION__ , pid );
    86 
     98#if CONFIG_DEBUG_SYSCALLS_ERROR
     99printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
     100#endif
    87101                this->errno = EINVAL;
    88102        return -1;
     
    92106    hal_enable_irq( &save_sr );
    93107
    94     // analyse signal type
    95     // supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
     108    // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
    96109    switch( sig_id )
    97110    {
     
    108121
    109122            // block all threads in all clusters
    110             process_sigaction( owner_ptr , BLOCK_ALL_THREADS );
     123            process_sigaction( pid , BLOCK_ALL_THREADS );
    111124
    112             // atomically update reference process termination state
     125            // atomically update owner process termination state
    113126            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    114                                   PROCESS_FLAG_BLOCK );
     127                                  PROCESS_TERM_STOP );
    115128 
    116129            retval = 0;
     
    120133        {
    121134            // unblock all threads in all clusters
    122             process_sigaction( owner_ptr , UNBLOCK_ALL_THREADS );
     135            process_sigaction( pid , UNBLOCK_ALL_THREADS );
    123136
    124137            // atomically update reference process termination state
    125138            hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    126                                    ~PROCESS_FLAG_BLOCK );
     139                                   ~PROCESS_TERM_STOP );
    127140            retval = 0;
    128141            break;
     
    131144        case SIGKILL:
    132145        {
    133             // the process_make_kill() function must be executed
    134             // by an RPC thread in process owner cluster
    135             // It deletes all target process threads in all clusters,
    136             // and updates the process termination state
    137             rpc_process_make_kill_client( owner_cxy , owner_ptr , false , 0 );
     146            // remove TXT ownership from owner process descriptor
     147            process_txt_reset_ownership( owner_xp );
     148
     149            // block all process threads in all clusters
     150            process_sigaction( pid , BLOCK_ALL_THREADS );
     151
     152            // mark all process threads in all clusters for delete
     153            process_sigaction( pid , DELETE_ALL_THREADS );
     154
     155            // atomically update owner process descriptor flags
     156            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
     157                                  PROCESS_TERM_KILL );
    138158
    139159            retval = 0;
     
    143163        {
    144164
    145 syscall_dmsg("\n[ERROR] in %s : illegal signal type %d for process %x\n",
    146 __FUNCTION__ , sig_id , pid );
    147 
     165#if CONFIG_DEBUG_SYSCALLS_ERROR
     166printk("\n[ERROR] in %s : illegal signal %d / process %x\n", __FUNCTION__, sig_id, pid );
     167#endif
    148168            this->errno = EINVAL;
    149169            retval = -1;
  • trunk/kernel/syscalls/sys_mmap.c

    r407 r435  
    2525#include <hal_types.h>
    2626#include <hal_uspace.h>
     27#include <hal_irqmask.h>
    2728#include <shared_syscalls.h>
    2829#include <errno.h>
     
    4445    error_t       error;
    4546    paddr_t       paddr;        // unused, but required for user space checking
    46 
    47         uint64_t      tm_start;
    48         uint64_t      tm_end;
    49 
    50         tm_start = hal_get_cycles();
     47    reg_t         save_sr;      // required to enable IRQs
    5148
    5249        thread_t    * this    = CURRENT_THREAD;
    5350        process_t   * process = this->process;
    5451
     52#if CONFIG_DEBUG_SYS_MMAP
     53uint64_t      tm_start;
     54uint64_t      tm_end;
     55tm_start = hal_get_cycles();
     56if ( CONFIG_DEBUG_SYS_MMAP < tm_start )
     57printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
     58__FUNCTION__, this, process->pid, (uint32_t)tm_start );
     59#endif
     60
    5561    // check arguments in user space
    5662    error = vmm_v2p_translate( false , attr , &paddr );
     
    5864    if ( error )
    5965    {
    60         printk("\n[ERROR] in %s : arguments not in used space = %x\n",
    61         __FUNCTION__ , (intptr_t)attr );
     66
     67#if CONFIG_DEBUG_SYSCALLS_ERROR
     68printk("\n[ERROR] in %s : arguments not in used space = %x\n", __FUNCTION__ , (intptr_t)attr );
     69#endif
    6270                this->errno = EINVAL;
    6371                return -1;
     
    8290    if( map_fixed )
    8391    {
    84         printk("\n[ERROR] in %s : MAP_FIXED not supported\n", __FUNCTION__ );
     92
     93#if CONFIG_DEBUG_SYSCALLS_ERROR
     94printk("\n[ERROR] in %s : MAP_FIXED not supported\n", __FUNCTION__ );
     95#endif
    8596        this->errno = EINVAL;
    8697        return -1;
     
    89100    if( map_shared == map_private )
    90101    {
    91         printk("\n[ERROR] in %s : MAP_SHARED xor MAP_PRIVATE\n", __FUNCTION__ );
     102
     103#if CONFIG_DEBUG_SYSCALLS_ERROR
     104printk("\n[ERROR] in %s : MAP_SHARED xor MAP_PRIVATE\n", __FUNCTION__ );
     105#endif
    92106        this->errno = EINVAL;
    93107        return -1;
     
    108122                if( fdid >= CONFIG_PROCESS_FILE_MAX_NR )
    109123                {
    110                         printk("\n[ERROR] in %s: bad file descriptor = %d\n", __FUNCTION__ , fdid );
     124
     125#if CONFIG_DEBUG_SYSCALLS_ERROR
     126printk("\n[ERROR] in %s: bad file descriptor = %d\n", __FUNCTION__ , fdid );
     127#endif
    111128            this->errno = EBADFD;
    112129            return -1;
     
    118135        if( file_xp == XPTR_NULL )
    119136        {
    120                         printk("\n[ERROR] in %s: file %d not found\n", __FUNCTION__ , fdid );
     137
     138#if CONFIG_DEBUG_SYSCALLS_ERROR
     139printk("\n[ERROR] in %s: file %d not found\n", __FUNCTION__ , fdid );
     140#endif
    121141            this->errno = EBADFD;
    122142            return -1;
     
    138158                if( (offset + length) > size)
    139159                {
    140                         printk("\n[ERROR] in %s: offset (%d) + len (%d) >= file's size (%d)\n",
    141                         __FUNCTION__, k_attr.offset, k_attr.length, size );
     160
     161#if CONFIG_DEBUG_SYSCALLS_ERROR
     162printk("\n[ERROR] in %s: offset (%d) + len (%d) >= file's size (%d)\n",
     163__FUNCTION__, k_attr.offset, k_attr.length, size );
     164#endif
    142165            this->errno = ERANGE;
    143166            return -1;
     
    148171                    (prot_write && !(file_attr & FD_ATTR_WRITE_ENABLE)) )
    149172                {
    150                         printk("\n[ERROR] in %s: prot = %x / file_attr = %x)\n",
    151                         __FUNCTION__ , k_attr.prot , file_attr );
     173
     174#if CONFIG_DEBUG_SYSCALLS_ERROR
     175printk("\n[ERROR] in %s: prot = %x / file_attr = %x)\n",
     176__FUNCTION__ , k_attr.prot , file_attr );
     177#endif
    152178                        this->errno = EACCES;
    153179                        return -1;
     
    178204            if( cluster_is_undefined( vseg_cxy ) )
    179205            {
    180                 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE\n", __FUNCTION__ );
     206
     207#if CONFIG_DEBUG_SYSCALLS_ERROR
     208printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE\n", __FUNCTION__ );
     209#endif
    181210                this->errno = EINVAL;
    182211                return -1;
     
    184213        }
    185214    }
     215
     216    // enable IRQs
     217    hal_enable_irq( &save_sr );
    186218
    187219    // get reference process cluster and local pointer
     
    216248    }
    217249   
     250    // restore IRQs
     251    hal_restore_irq( save_sr );
     252
    218253    if( vseg == NULL )
    219254    {
    220         printk("\n[ERROR] in %s : cannot create vseg\n", __FUNCTION__ );
     255
     256#if CONFIG_DEBUG_SYSCALLS_ERROR
     257printk("\n[ERROR] in %s : cannot create vseg\n", __FUNCTION__ );
     258#endif
    221259        this->errno = ENOMEM;
    222260        return -1;
     
    226264    hal_copy_to_uspace( &attr->addr , &vseg->min , sizeof(intptr_t) );
    227265
    228     tm_end = hal_get_cycles();
    229 
    230 syscall_dmsg("\n[DBG] %s : core[%x,%d] created vseg %s in cluster %x / cycle %d\n"
    231 "      base = %x / length = %x / cost = %d\n",
    232 __FUNCTION__, local_cxy , this->core->lid , vseg_type_str(vseg->type) ,
    233 vseg->cxy , (uint32_t)tm_start , vseg->min , length , (uint32_t)(tm_end - tm_start) );
     266    hal_fence();
     267
     268#if CONFIG_DEBUG_SYS_MMAP
     269tm_end = hal_get_cycles();
     270if ( CONFIG_DEBUG_SYS_MMAP < tm_start )
     271printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n"
     272"vseg %s / cluster %x / base %x / size %x / cost %d\n",
     273__FUNCTION__, this, process->pid, (uint32_t)tm_end,
     274vseg_type_str(vseg->type), vseg->cxy, vseg->min, length, (uint32_t)(tm_end - tm_start) );
     275#endif
    234276
    235277        return 0;
  • trunk/kernel/syscalls/sys_read.c

    r433 r435  
    3636// TODO: concurrent user page(s) munmap need to be handled [AG]
    3737
    38 // TODO : remove these debug variables
    3938extern uint32_t enter_sys_read;
    4039extern uint32_t enter_devfs_move;
     
    6463    reg_t        save_sr;     // required to enable IRQs during syscall
    6564
    66 #if CONFIG_READ_DEBUG
     65#if (CONFIG_DEBUG_SYS_READ & 1)
    6766enter_sys_read = (uint32_t)tm_start;
    6867#endif
     
    7675tm_start = hal_get_cycles();
    7776if( CONFIG_DEBUG_SYS_READ < tm_start )
    78 printk("\n[DBG] %s : thread %d enter / process %x / vaddr = %x / count %d / cycle %d\n",
     77printk("\n[DBG] %s : thread %x enter / process %x / vaddr = %x / count %d / cycle %d\n",
    7978__FUNCTION__, this, process->pid, vaddr, count, (uint32_t)tm_start );
    8079#endif
     
    8382        if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
    8483        {
    85         printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
    86         __FUNCTION__ , file_id );
     84
     85#if CONFIG_DEBUG_SYSCALLS_ERROR
     86printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", __FUNCTION__ , file_id );
     87#endif
    8788                this->errno = EBADFD;
    8889                return -1;
     
    9495    if ( error )
    9596    {
    96         printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
    97         __FUNCTION__ , (intptr_t)vaddr );
     97
     98#if CONFIG_DEBUG_SYSCALLS_ERROR
     99printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
     100__FUNCTION__ , (intptr_t)vaddr );
     101#endif
    98102                this->errno = EINVAL;
    99103                return -1;
     
    108112    if( file_xp == XPTR_NULL )
    109113    {
    110         printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
    111         __FUNCTION__ , file_id , process->pid );
     114
     115#if CONFIG_DEBUG_SYSCALLS_ERROR
     116printk("\n[ERROR] in %s : undefined fd_id %d in process %x\n",
     117__FUNCTION__ , file_id , process->pid );
     118#endif
    112119        this->errno = EBADFD;
    113120        return -1;
     
    122129    if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    123130        {
    124         printk("\n[ERROR] in %s : file %d not readable in process %x\n",
    125         __FUNCTION__ , file_id , process->pid );
     131
     132#if CONFIG_DEBUG_SYSCALLS_ERROR
     133printk("\n[ERROR] in %s : file %d not readable in process %x\n",
     134__FUNCTION__ , file_id , process->pid );
     135#endif
    126136                this->errno = EBADFD;
    127137                return -1;
     
    138148        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    139149            {
    140             printk("\n[ERROR] in %s : file %d not readable in process %x\n",
    141             __FUNCTION__ , file_id , process->pid );
     150
     151#if CONFIG_DEBUG_SYSCALLS_ERROR
     152printk("\n[ERROR] in %s : file %d not readable in process %x\n",
     153__FUNCTION__ , file_id , process->pid );
     154#endif
    142155                    this->errno = EBADFD;
    143156                    return -1;
     
    166179        if( XPTR( local_cxy , process ) != owner_xp )
    167180        {
    168             printk("\n[ERROR] in %s : process %x not in foreground for TXT%d\n",
    169             __FUNCTION__, process->pid, hal_remote_lw( XPTR(chdev_cxy,&chdev_ptr->channel) ) );
     181
     182#if CONFIG_DEBUG_SYSCALLS_ERROR
     183printk("\n[ERROR] in %s : process %x not in foreground for TXT%d\n",
     184__FUNCTION__, process->pid, hal_remote_lw( XPTR(chdev_cxy,&chdev_ptr->channel) ) );
     185#endif
    170186                    this->errno = EBADFD;
    171187                    return -1;
     
    180196    if( nbytes != count )
    181197    {
    182         printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",
    183         __FUNCTION__ , file_id , process->pid );
     198
     199#if CONFIG_DEBUG_SYSCALLS_ERROR
     200printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",
     201__FUNCTION__ , file_id , process->pid );
     202#endif
    184203        this->errno = error;
    185204        return -1;
     
    194213tm_end = hal_get_cycles();
    195214if( CONFIG_DEBUG_SYS_READ < tm_end )
    196 printk("\n[DBG] %s : thread %x / process %x / cycle %d\n"
     215printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n"
    197216"nbytes = %d / first byte = %c / file_id = %d / cost = %d\n",
    198217__FUNCTION__ , local_cxy , this->core->lid , this->trdid , this->process->pid ,
     
    201220#endif
    202221
    203 #if (CONFIG_READ_DEBUG & 0x1)
     222#if (CONFIG_DEBUG_SYS_READ & 1)
    204223exit_sys_read = (uint32_t)tm_end;
    205224
    206225printk("\n@@@@@@@@@@@@ timing to read character %c\n"
    207 " - enter_sys_read     = %d / delta %d\n"
    208 " - enter_devfs_move   = %d / delta %d\n"
    209 " - enter_txt_read     = %d / delta %d\n"
    210 " - enter_chdev_cmd    = %d / delta %d\n"
    211 " - enter_chdev_server = %d / delta %d\n"
    212 " - enter_tty_cmd      = %d / delta %d\n"
    213 " - enter_tty_isr      = %d / delta %d\n"
    214 " - exit_tty_isr       = %d / delta %d\n"
    215 " - exit_tty_cmd       = %d / delta %d\n"
    216 " - exit_chdev_server  = %d / delta %d\n"
    217 " - exit_chdev_cmd     = %d / delta %d\n"
    218 " - exit_txt_read      = %d / delta %d\n"
    219 " - exit_devfs_move    = %d / delta %d\n"
    220 " - exit_sys_read      = %d / delta %d\n",
     226" - enter_sys_read          = %d / delta %d\n"
     227" - enter_devfs_read        = %d / delta %d\n"
     228" - enter_txt_read          = %d / delta %d\n"
     229" - enter_chdev_cmd_read    = %d / delta %d\n"
     230" - enter_chdev_server_read = %d / delta %d\n"
     231" - enter_tty_cmd_read      = %d / delta %d\n"
     232" - enter_tty_isr_read      = %d / delta %d\n"
     233" - exit_tty_isr_read       = %d / delta %d\n"
     234" - exit_tty_cmd_read       = %d / delta %d\n"
     235" - exit_chdev_server_read  = %d / delta %d\n"
     236" - exit_chdev_cmd_read     = %d / delta %d\n"
     237" - exit_txt_read           = %d / delta %d\n"
     238" - exit_devfs_read         = %d / delta %d\n"
     239" - exit_sys_read           = %d / delta %d\n",
    221240*((char *)(intptr_t)paddr) ,
    222 enter_sys_read     , 0 ,
    223 enter_devfs_move   , enter_devfs_move   - enter_sys_read     ,
    224 enter_txt_read     , enter_txt_read     - enter_devfs_move   ,
    225 enter_chdev_cmd    , enter_chdev_cmd    - enter_txt_read     ,
    226 enter_chdev_server , enter_chdev_server - enter_chdev_cmd    ,
    227 enter_tty_cmd      , enter_tty_cmd      - enter_chdev_server ,
    228 enter_tty_isr      , enter_tty_isr      - enter_tty_cmd      ,
    229 exit_tty_isr       , exit_tty_isr       - enter_tty_isr      ,
    230 exit_tty_cmd       , exit_tty_cmd       - exit_tty_isr       ,
    231 exit_chdev_server  , exit_chdev_server  - exit_tty_cmd       ,
    232 exit_chdev_cmd     , exit_chdev_cmd     - exit_chdev_server  ,
    233 exit_txt_read      , exit_txt_read      - exit_chdev_cmd     ,
    234 exit_devfs_move    , exit_devfs_move    - exit_txt_read      ,
    235 exit_sys_read      , exit_sys_read      - exit_devfs_move    );
     241enter_sys_read          , 0 ,
     242enter_devfs_read        , enter_devfs_read        - enter_sys_read          ,
     243enter_txt_read          , enter_txt_read          - enter_devfs_read        ,
     244enter_chdev_cmd_read    , enter_chdev_cmd_read    - enter_txt_read          ,
     245enter_chdev_server_read , enter_chdev_server_read - enter_chdev_cmd_read    ,
     246enter_tty_cmd_read      , enter_tty_cmd_read      - enter_chdev_server_read ,
     247enter_tty_isr_read      , enter_tty_isr_read      - enter_tty_cmd_read      ,
     248exit_tty_isr_read       , exit_tty_isr_read       - enter_tty_isr_read      ,
     249exit_tty_cmd_read       , exit_tty_cmd_read       - exit_tty_isr_read       ,
     250exit_chdev_server_read  , exit_chdev_server_read  - exit_tty_cmd_read       ,
     251exit_chdev_cmd_read     , exit_chdev_cmd_read     - exit_chdev_server_read  ,
     252exit_txt_read           , exit_txt_read           - exit_chdev_cmd_read     ,
     253exit_devfs_read         , exit_devfs_read         - exit_txt_read           ,
     254exit_sys_read           , exit_sys_read           - exit_devfs_read         );
    236255#endif
    237256 
  • trunk/kernel/syscalls/sys_signal.c

    r409 r435  
    2727#include <thread.h>
    2828#include <printk.h>
    29 #include <signal.h>
    3029
    3130//////////////////////////////////
  • trunk/kernel/syscalls/sys_wait.c

    r433 r435  
    2424#include <hal_types.h>
    2525#include <hal_uspace.h>
     26#include <hal_irqmask.h>
    2627#include <core.h>
    2728#include <thread.h>
     
    4243    int         child_state;
    4344    thread_t  * child_thread;
     45    reg_t       save_sr;
    4446
    4547    thread_t  * this    = CURRENT_THREAD;
     
    6163        if( error )
    6264        {
    63         printk("\n[ERROR] in %s : status buffer unmapped for thread %x in process %x\n",
    64         __FUNCTION__ , this->trdid , process->pid );
     65
     66#if CONFIG_DEBUG_SYSCALLS_ERROR
     67printk("\n[ERROR] in %s : status buffer unmapped for thread %x in process %x\n",
     68__FUNCTION__ , this->trdid , process->pid );
     69#endif
    6570        this->errno = EFAULT;
    6671                return -1;
     
    8590    while( 1 )
    8691    {
     92        // enable IRQS
     93        hal_enable_irq( &save_sr );
     94 
    8795        // get lock protecting children list
    8896        remote_spinlock_lock( children_lock_xp );
     
    101109            // test if child process is terminated,
    102110            // but termination not yet reported to parent process
    103             if( ((child_state & PROCESS_FLAG_EXIT)   ||
    104                  (child_state & PROCESS_FLAG_KILL)   ||
    105                  (child_state & PROCESS_FLAG_BLOCK)) &&
    106                  ((child_state & PROCESS_FLAG_WAIT) == 0) )
     111            if( ((child_state & PROCESS_TERM_EXIT)  ||
     112                 (child_state & PROCESS_TERM_KILL)  ||
     113                 (child_state & PROCESS_TERM_STOP)) &&
     114                 ((child_state & PROCESS_TERM_WAIT) == 0) )
    107115            {
    108116                // get pointer on main thread and PID from child owner process
     
    112120                // set the PROCESS_FLAG_WAIT in owner child descriptor
    113121                hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ),
    114                                       PROCESS_FLAG_WAIT );
     122                                      PROCESS_TERM_WAIT );
    115123
    116124                // set the THREAD_FLAG_REQ_DELETE in child main thread
     
    118126                                            THREAD_FLAG_REQ_DELETE );
    119127
     128                // release lock protecting children list
     129                remote_spinlock_unlock( children_lock_xp );
     130
    120131#if CONFIG_DEBUG_SYS_WAIT
    121132tm_end = hal_get_cycles();
    122133if( CONFIG_DEBUG_SYS_WAIT < tm_end )
    123 printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n",
    124 __FUNCTION__, this, process->pid, (uint32_t)tm_end );
     134printk("\n[DBG] %s : thread %x exit / parent %x / child %x / cycle %d\n",
     135__FUNCTION__, this, process->pid, child_pid, (uint32_t)tm_end );
    125136#endif
    126 
    127137                 // return relevant info to calling parent process
    128138                 hal_copy_to_uspace( status , &child_state , sizeof(int) );
     
    131141        }
    132142       
    133         // release lock
     143        // release lock protecting children list
    134144        remote_spinlock_unlock( children_lock_xp );
    135145
    136146        // deschedule without blocking
    137147        sched_yield( "parent wait children termination" );
    138     }
     148
     149    }  // end while
    139150
    140151    // never executed
  • trunk/kernel/syscalls/sys_write.c

    r433 r435  
    4141{
    4242    error_t      error;
    43     paddr_t      paddr;           // unused, but required for user space checking
     43    paddr_t      paddr;           // required for user space checking
    4444        xptr_t       file_xp;         // remote file extended pointer
    4545    uint32_t     nbytes;          // number of bytes actually written
    4646    reg_t        save_sr;         // required to enable IRQs during syscall
     47
     48#if (CONFIG_DEBUG_SYS_WRITE_DEBUG & 1)
     49enter_sys_read = (uint32_t)tm_start;
     50#endif
    4751
    4852        thread_t   * this = CURRENT_THREAD;
     
    5458tm_start = hal_get_cycles();
    5559if( CONFIG_DEBUG_SYS_WRITE < tm_start )
    56 printk("\n[DBG] %s : thread %x / process %x / vaddr %x / count %d / cycle %d\n",
     60printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / count %d / cycle %d\n",
    5761__FUNCTION__, this, process->pid, vaddr, count, (uint32_t)tm_start );
    5862#endif
     
    162166tm_end = hal_get_cycles();
    163167if( CONFIG_DEBUG_SYS_WRITE < tm_end )
    164 printk("\n[DBG] %s : thread %x in process %x / cycle %d\n"
     168printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n"
    165169"nbytes = %d / first byte = %c / file_id = %d / cost = %d\n",
    166170__FUNCTION__, this, process->pid, (uint32_t)tm_start,
     
    168172#endif
    169173 
     174#if (CONFIG_DEBUG_SYS_WRITE & 1)
     175exit_sys_write = (uint32_t)tm_end;
     176
     177printk("\n@@@@@@@@@@@@ timing to write string %c\n"
     178" - enter_sys_write          = %d / delta %d\n"
     179" - enter_devfs_write        = %d / delta %d\n"
     180" - enter_txt_write          = %d / delta %d\n"
     181" - enter_chdev_cmd_write    = %d / delta %d\n"
     182" - enter_chdev_server_write = %d / delta %d\n"
     183" - enter_tty_cmd_write      = %d / delta %d\n"
     184" - enter_tty_isr_write      = %d / delta %d\n"
     185" - exit_tty_isr_write       = %d / delta %d\n"
     186" - exit_tty_cmd_write       = %d / delta %d\n"
     187" - exit_chdev_server_write  = %d / delta %d\n"
     188" - exit_chdev_cmd_write     = %d / delta %d\n"
     189" - exit_txt_write           = %d / delta %d\n"
     190" - exit_devfs_write         = %d / delta %d\n"
     191" - exit_sys_write           = %d / delta %d\n",
     192*((char *)(intptr_t)paddr) ,
     193enter_sys_write          , 0 ,
     194enter_devfs_write        , enter_devfs_write        - enter_sys_write          ,
     195enter_txt_write          , enter_txt_write          - enter_devfs_write        ,
     196enter_chdev_cmd_write    , enter_chdev_cmd_write    - enter_txt_write          ,
     197enter_chdev_server_write , enter_chdev_server_write - enter_chdev_cmd_write    ,
     198enter_tty_cmd_write      , enter_tty_cmd_write      - enter_chdev_server_write ,
     199enter_tty_isr_write      , enter_tty_isr_write      - enter_tty_cmd_write      ,
     200exit_tty_isr_write       , exit_tty_isr_write       - enter_tty_isr_write      ,
     201exit_tty_cmd_write       , exit_tty_cmd_write       - exit_tty_isr_write       ,
     202exit_chdev_server_write  , exit_chdev_server_write  - exit_tty_cmd_write       ,
     203exit_chdev_cmd_write     , exit_chdev_cmd_write     - exit_chdev_server_write  ,
     204exit_txt_write           , exit_txt_write           - exit_chdev_cmd_write     ,
     205exit_devfs_write         , exit_devfs_write         - exit_txt_write           ,
     206exit_sys_write           , exit_sys_write           - exit_devfs_write         );
     207#endif
     208 
    170209        return nbytes;
    171210
  • trunk/kernel/syscalls/syscalls.h

    r433 r435  
    508508 * The following macros can be used to extract information from status:
    509509 * - WIFEXITED(status)   : is true if the child process terminated with an exit().
    510  * - WIFSIGNALED(status) : is true if the child process terminated by a signal.
     510 * - WIFSIGNALED(status) : is true if the child process killed by a signal.
    511511 * - WIFSTOPPED(status)  : is true if the child process is stopped by a signal.
    512512 * - WEXITSTATUS(status) : returns the low-order 8 bits of the exit() argument.
     
    558558 * [43] This debug function displays on the kernel terminal TXT0 an user defined string,
    559559 * or the current state of a kernel structure, identified by the <type> argument.
    560  * The <arg0> and <arg1> arguments depends on the structure type. It can be:
    561  * - VMM     : VSL and GPT for a process identified by <pid>.
    562  * - SCHED   : all threads allocated to a scheduler identified by <cxy> & <lid>.
    563  * - PROCESS : all processes registered in a cluster identified by <cxy>. 
    564  * - VFS     : all files registered in the VFS cache.
    565  * - CHDEV   : all registered channel devices.
    566  ******************************************************************************************
    567  * type     : [in] STRING / VMM / SCHED / PROCESS / VSEG / VFS
     560 * The <arg0> and <arg1> arguments depends on the structure type:
     561 * - DISPLAY_STRING          : an user defined string
     562 * - DISPLAY_VMM             : VSL and GPT for a process identified by <pid>.
     563 * - DISPLAY_SCHED           : all threads allocated to a scheduler <cxy> & <lid>.
     564 * - DISPLAY_CLUSTER_PROCESS : all processes registered in a cluster identified by <cxy>. 
     565 * - DISPLAY_TXT_PROCESS     : all processes registered in a cluster identified by <cxy>. 
     566 * - DISPLAY_VFS             : all files registered in the VFS cache.
     567 * - DISPLAY_CHDEV           : all registered channel devices.
     568 ******************************************************************************************
     569 * type      : [in] type of display
    568570 * arg0      : [in] type dependant argument.
    569571 * arg1      : [in] type dependant argument.
Note: See TracChangeset for help on using the changeset viewer.