Changeset 443 for trunk/kernel/syscalls


Ignore:
Timestamp:
May 16, 2018, 4:15:22 PM (6 years ago)
Author:
alain
Message:

Fix few bugs whike debugging the sort multi-thread application.

Location:
trunk/kernel/syscalls
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_display.c

    r440 r443  
    3030#include <process.h>
    3131#include <string.h>
    32 
     32#include <shared_syscalls.h>
     33
     34/////////////////////////////////////////////////////////////////////////////////
     35// This static function returns a printable string for the type of display.
     36/////////////////////////////////////////////////////////////////////////////////
     37
     38#if DEBUG_SYS_DISPLAY
     39static char* display_type_str( uint32_t type )
     40{
     41    if     ( type == DISPLAY_STRING            ) return "STRING";
     42    else if( type == DISPLAY_VMM               ) return "VMM";
     43    else if( type == DISPLAY_SCHED             ) return "SCHED";
     44    else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES";
     45    else if( type == DISPLAY_VFS               ) return "VFS";
     46    else if( type == DISPLAY_CHDEV             ) return "CHDEV";
     47    else if( type == DISPLAY_TXT_PROCESSES     ) return "TXT_PROCESSES";
     48}
     49#endif
    3350
    3451/////////////////////////////
     
    4966tm_start = hal_get_cycles();
    5067if( DEBUG_SYS_DISPLAY < tm_start )
    51 printk("\n[DBG] %s : thread %d enter / process %x / type  %d / cycle = %d\n",
    52 __FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );
     68printk("\n[DBG] %s : thread %d enter / process %x / type  %s / cycle = %d\n",
     69__FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );
    5370#endif
    5471
     
    98115    else if( type == DISPLAY_VMM )
    99116    {
    100         pid_t pid = (pid_t)arg0;
    101 
    102         // get extended pointer on reference process
    103         xptr_t process_xp = cluster_get_reference_process_from_pid( pid );
     117        cxy_t cxy = (cxy_t)arg0;
     118        pid_t pid = (pid_t)arg1;
     119
     120        // check cxy argument
     121            if( cluster_is_undefined( cxy ) )
     122        {
     123
     124#if DEBUG_SYSCALLS_ERROR
     125printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     126__FUNCTION__ , cxy , this->trdid , process->pid );
     127#endif
     128            this->errno = EINVAL;
     129            return -1;
     130        }
     131
     132        // get extended pointer on process PID in cluster CXY
     133        xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
    104134
    105135            if( process_xp == XPTR_NULL )
     
    107137
    108138#if DEBUG_SYSCALLS_ERROR
    109 printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n",
    110 __FUNCTION__ , pid , this->trdid , process->pid );
    111 #endif
    112             this->errno = EINVAL;
    113             return -1;
    114         }
    115 
    116         // get cluster and local pointer on process
    117         cxy_t       process_cxy = GET_CXY( process_xp );
    118         process_t * process_ptr = (process_t *)GET_PTR( process_xp );
     139printk("\n[ERROR] in %s : process %x in cluster %x not found / thread %x / process %x\n",
     140__FUNCTION__ , pid , cxy , this->trdid , process->pid );
     141#endif
     142            this->errno = EINVAL;
     143            return -1;
     144        }
     145
     146        // get local pointer on process
     147        process_t * process = (process_t *)GET_PTR( process_xp );
    119148
    120149        // call kernel function
    121         if( process_cxy == local_cxy )
    122         {
    123                 vmm_display( process_ptr , true );
     150        if( cxy == local_cxy )
     151        {
     152                vmm_display( process , true );
    124153        }
    125154        else
    126155        {
    127             rpc_vmm_display_client( process_cxy , process_ptr , true );
     156            rpc_vmm_display_client( cxy , process , true );
    128157        }
    129158    }
  • trunk/kernel/syscalls/sys_exit.c

    r441 r443  
    5151#endif
    5252
    53     // get owner process descriptor pointers and cluster
    54     xptr_t      owner_xp  = cluster_get_owner_process_from_pid( pid );
     53    // get owner process descriptor pointers
     54    xptr_t      owner_xp  = process->owner_xp;
    5555    cxy_t       owner_cxy = GET_CXY( owner_xp );
    5656    process_t * owner_ptr = GET_PTR( owner_xp );
     
    6262    hal_enable_irq( &save_sr );
    6363
    64     // mark for delete all process threads in all clusters
    65     // (but the main thread and this calling thread)
     64    // mark for delete all process threads in all clusters,
     65    // but the main thread and this calling thread
    6666    process_sigaction( pid , DELETE_ALL_THREADS );
    6767
     
    8181#if( DEBUG_SYS_EXIT & 1)
    8282if( tm_start > DEBUG_SYS_EXIT )
    83 printk("\n[DBG] %s : calling thread %x deleted itself / process %x\n",
     83printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n",
    8484__FUNCTION__ , this, pid );
    8585#endif
  • trunk/kernel/syscalls/sys_fg.c

    r438 r443  
    3636int sys_fg( pid_t    pid )
    3737{
    38     xptr_t      process_xp;
     38    xptr_t      process_xp;     // extended pointer on reference process descriptor
    3939    process_t * process_ptr;
    4040    cxy_t       process_cxy;
    41     xptr_t      chdev_xp;
     41    xptr_t      file_xp;        // extended pointer on STDIN file descriptor
     42    xptr_t      chdev_xp;       // extended pointer on TXT0_RX chdev
    4243    chdev_t   * chdev_ptr;
    4344    cxy_t       chdev_cxy;
     
    7071    process_ptr = (process_t *)GET_PTR( process_xp );
    7172    process_cxy = GET_CXY( process_xp );
     73
     74    // get extended pointer on the reference process STDIN file descriptor
     75    file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    7276 
    7377    // get extended pointer on TXT_RX chdev
    74     chdev_xp = chdev_from_file( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     78    chdev_xp = chdev_from_file( file_xp );
    7579
    7680    // get chdev cluster and local pointer
  • trunk/kernel/syscalls/sys_read.c

    r441 r443  
    147147        // check file readable
    148148        uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
     149
    149150        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    150151            {
     
    231232exit_sys_read = (uint32_t)tm_end;
    232233
    233 printk("\n@@@@@@@@@@@@ timing to read character\n"
     234printk("\n***** timing to read one character *****\n"
    234235" - enter_sys_read          = %d / delta %d\n"
    235236" - enter_devfs_read        = %d / delta %d\n"
  • trunk/kernel/syscalls/sys_thread_cancel.c

    r440 r443  
    3737    cxy_t        target_cxy;    // target thread cluster identifier
    3838    ltid_t       target_ltid;   // target thread local index
     39    xptr_t       owner_xp;      // extended pointer on owner process
    3940    cxy_t        owner_cxy;     // process owner cluster identifier
    40     xptr_t       owner_xp;      // extended pointer on owner process
    4141
    4242    // get killer thread pointers
     
    4444    process_t  * process = this->process;
    4545    pid_t        pid     = process->pid;
     46
     47#if DEBUG_SYS_THREAD_CANCEL
     48uint64_t     tm_start;
     49uint64_t     tm_end;
     50tm_start = hal_get_cycles();
     51if( DEBUG_SYS_THREAD_CANCEL < tm_start )
     52printk("\n[DBG] %s : thread %x enter to kill thread %x in process %x / cycle %d\n",
     53__FUNCTION__, this , trdid , pid , (uint32_t)tm_start );
     54#endif
    4655
    4756    // get extended pointer on target thread
     
    5968    }
    6069
    61 #if DEBUG_SYS_THREAD_CANCEL
    62 uint64_t     tm_start;
    63 uint64_t     tm_end;
    64 tm_start = hal_get_cycles();
    65 if( DEBUG_SYS_THREAD_CANCEL < tm_start )
    66 printk("\n[DBG] %s : thread %x enter to kill thread %x / cycle %d\n",
    67 __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_start );
    68 #endif
    69 
    70     // get process owner cluster identifier
    71     owner_cxy = CXY_FROM_PID( pid );
     70    // get process owner cluster
     71    owner_xp  = process->owner_xp;
     72    owner_cxy = GET_CXY( owner_xp );
    7273
    7374    // get target thread ltid and cluster
     
    7980    if( (target_cxy == owner_cxy) && (target_ltid == 0) )
    8081    {
    81         // get extended pointer on owner cluster
    82         owner_xp = cluster_get_owner_process_from_pid( pid );
    83 
    8482        // mark for delete all threads but the main
    8583        hal_enable_irq( &save_sr );
     
    107105tm_end = hal_get_cycles();
    108106if( DEBUG_SYS_THREAD_CANCEL < tm_end )
    109 printk("\n[DBG] %s : thread %x exit after kill thread %x / cycle %d\n",
    110 __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_end );
     107printk("\n[DBG] %s : thread %x exit after kill thread %x in process %x / cycle %d\n",
     108__FUNCTION__, this , trdid , pid , (uint32_t)tm_end );
    111109#endif
    112110
  • trunk/kernel/syscalls/sys_trace.c

    r407 r443  
    11/*
    2  * sys_trace.c - show kernel active processes and threads
     2 * sys_trace.c - activate / desactivate the context switches trace for a given core
    33 *
    4  * Author    Alain Greiner (c) (2016,2017)
     4 * Author    Alain Greiner (c) (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727#include <thread.h>
    2828#include <errno.h>
     29#include <shared_syscalls.h>
    2930#include <syscalls.h>
    3031
    31 //////////////////////////////////
    32 int sys_trace( uint32_t operation,
    33                pid_t    pid,
    34                uint32_t trdid )
     32///////////////////////////////
     33int sys_trace( bool_t   active,
     34               cxy_t    cxy,
     35               lid_t    lid )
    3536{
    36     // get extended pointer on target thread
    37     xptr_t thread_xp = thread_get_xptr( pid , trdid );
     37    uint32_t    ncores;
    3838
    39     if( thread_xp == XPTR_NULL )
     39    thread_t  * this    = CURRENT_THREAD;
     40    process_t * process = this->process;
     41
     42#if DEBUG_SYS_TRACE
     43uint64_t    tm_start;
     44uint64_t    tm_end;
     45tm_start = hal_get_cycles();
     46if( DEBUG_SYS_TRACE < tm_start )
     47printk("\n[DBG] %s : thread %d enter / process %x / cycle = %d\n",
     48__FUNCTION__, this, this->process->pid, (uint32_t)tm_start );
     49#endif
     50
     51    // check cluster identifier
     52    if( cluster_is_undefined( cxy ) )
    4053    {
    41         printk("\n[ERROR] in %s : undefined thread for PID = %x / TRDID = %x\n",
    42                __FUNCTION__ , pid , trdid );
    43         CURRENT_THREAD->errno = EINVAL;
     54
     55#if DEBUG_SYSCALLS_ERROR
     56printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     57__FUNCTION__ , cxy , this->trdid , process->pid );
     58#endif
     59        this->errno = EINVAL;
    4460        return -1;
    4561    }
    4662
    47     if( operation == TRACE_OFF )
     63    // check core local index
     64    ncores = hal_remote_lw( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) );
     65    if( lid >= ncores )
    4866    {
    49         // desactivate thread trace TODO
    5067
    51             printk("\n[DBG] %s : trace OFF  for thread %x in process %x\n",
    52                __FUNCTION__ , trdid , pid );
    53     }
    54     else if( operation == TRACE_ON )
    55     {
    56         // activate thread trace TODO
    57                    
    58             printk("\n[DBG] %s : trace ON for thread %x in process %x\n",
    59                __FUNCTION__ , trdid , pid );
    60     }
    61     else
    62     {
    63         printk("\n[ERROR] in %s : undefined operation\n", __FUNCTION__ );
    64         CURRENT_THREAD->errno = EINVAL;
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
     70__FUNCTION__ , lid , this->trdid , process->pid );
     71#endif
     72        this->errno = EINVAL;
    6573        return -1;
    6674    }
    6775
     76    // get local pointer on target core
     77    core_t * core = &LOCAL_CLUSTER->core_tbl[lid];
     78
     79    // get extended pointer on target scheduler trace field
     80    xptr_t trace_xp = XPTR( cxy , &core->scheduler.trace );
     81
     82    if ( active ) hal_remote_sw( trace_xp , 1 );
     83    else          hal_remote_sw( trace_xp , 0 );
     84   
    6885    hal_fence();
     86
     87#if DEBUG_SYS_TRACE
     88tm_end = hal_get_cycles();
     89if( DEBUG_SYS_TRACE < tm_end )
     90printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
     91__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
     92#endif
    6993
    7094    return 0;
  • trunk/kernel/syscalls/sys_wait.c

    r440 r443  
    7373        }
    7474
    75     // get process owner cluster and calling thread trdid
     75    // get calling process owner cluster
    7676    cxy_t   owner_cxy = CXY_FROM_PID( pid );
    77     trdid_t trdid     = this->trdid;
    7877
    79     // wait must be executed by the main thread
     78    // get calling thread trdid
     79    trdid_t trdid = this->trdid;
     80
     81    // this function must be executed by the process main thread
    8082    if( (owner_cxy != local_cxy) || (LTID_FROM_TRDID(trdid) != 0) )
    8183    {
     
    113115            child_state = (int)hal_remote_lw ( XPTR(child_cxy,&child_ptr->term_state));
    114116
    115             // test if child process is terminated,
     117            // test if this child process is terminated,
    116118            // but termination not yet reported to parent process
    117119            if( ((child_state & PROCESS_TERM_EXIT)  ||
     
    120122                 ((child_state & PROCESS_TERM_WAIT) == 0) )
    121123            {
    122                 // get pointer on main thread and PID from child owner process
     124                // get pointer on child main thread and PID from child owner process
    123125                child_pid    = (pid_t)     hal_remote_lw (XPTR( child_cxy , &child_ptr->pid ));
    124126                child_thread = (thread_t *)hal_remote_lpt(XPTR( child_cxy ,
    125127                                                                &child_ptr->th_tbl[0] ));
    126128
    127                 // set the PROCESS_FLAG_WAIT in owner child descriptor
     129                // set the PROCESS_FLAG_WAIT in owner child process descriptor
    128130                hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ),
    129131                                      PROCESS_TERM_WAIT );
  • trunk/kernel/syscalls/sys_write.c

    r441 r443  
    103103    }
    104104
    105     // enable IRQs
    106     hal_enable_irq( &save_sr );
    107 
    108105    // get extended pointer on remote file descriptor
    109106    file_xp = process_fd_get_xptr( process , file_id );
     
    128125    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    129126
    130     // action depend on file type
     127    // enable IRQs
     128    hal_enable_irq( &save_sr );
     129
     130   // action depend on file type
    131131    if( type == INODE_TYPE_FILE )  // check file writable & write to mapper
    132132    {
     
    152152    else if( type == INODE_TYPE_DEV )  // check ownership & write to device
    153153    {
     154        // check user buffer size for TXT_TX
     155        if( (type == INODE_TYPE_DEV) && (count >= CONFIG_TXT_KBUF_SIZE) )
     156        {
     157
     158#if DEBUG_SYSCALLS_ERROR
     159printk("\n[ERROR] in %s : user buffer size %x too large / thread %x / process %x\n",
     160__FUNCTION__ , count, this->trdid, process->pid );
     161#endif
     162                    this->errno = EINVAL;
     163                    return -1;
     164        }
     165
    154166        // move count bytes to device
    155167        nbytes = devfs_user_move( false,             // from buffer to device
     
    158170                                 count );
    159171    }
    160     else
     172    else  // not FILE and not DEV
    161173    {
    162174        nbytes = 0;
     
    192204exit_sys_write = (uint32_t)tm_end;
    193205
    194 printk("\n@@@@@@@@@@@@ timing to write\n"
     206printk("\n***** timing to write a string *****\n"
    195207" - enter_sys_write          = %d / delta %d\n"
    196208" - enter_devfs_write        = %d / delta %d\n"
  • trunk/kernel/syscalls/syscalls.h

    r440 r443  
    170170 * [10] This function implement the exit system call terminating a POSIX process.
    171171 * It can be called by any thread running in any cluster.
    172  * It uses both remote accesses to access the owner process descriptor, ans the
    173  * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors
     172 * It uses both remote accesses to access the owner process descriptor, and the
     173 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors.
    174174 * In the present implementation, this function implements actually the _exit():
    175175 * - it does not flush open output streams.
     
    600600
    601601/******************************************************************************************
    602  * [47] This non-standard function is used to activate / desactivate the trace for a thread
    603  * identified by the <trdid> and <pid> arguments.
     602 * [47] This debug function is used to activate / desactivate the context switches trace
     603 * for a core identified by the <cxy> and <lid> arguments.
    604604 * It can be called by any other thread in the same process.
    605605 ******************************************************************************************
    606  * @ operation  : operation type as defined below.
    607  * @ pid        : process identifier.
    608  * @ trdid      : thread identifier.
     606 * @ active     : activate trace if true / desactivate trace if false.
     607 * @ cxy        : cluster identifier.
     608 * @ lid        : core local index.
    609609 * @ returns O if success / returns -1 if failure.
    610610 *****************************************************************************************/
    611 int sys_trace( uint32_t operation,
    612                pid_t    pid,
    613                uint32_t trdid );
     611int sys_trace( bool_t   active,
     612               cxy_t    cxy,
     613               lid_t    lid );
    614614
    615615/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.