Changeset 421 for trunk


Ignore:
Timestamp:
Jan 29, 2018, 5:40:34 PM (7 years ago)
Author:
alain
Message:

Introduce sys_fg() , sys_display() , sys_wait() syscalls.

Location:
trunk/kernel/syscalls
Files:
3 added
2 deleted
9 edited

Legend:

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

    r416 r421  
    7474        SYS_EXEC           = 37,
    7575        SYS_STAT           = 38,     
    76         SYS_TRACE          = 39,
     76        SYS_WAIT           = 39,
    7777
    7878    SYS_GET_CONFIG     = 40,
    7979    SYS_GET_CORE       = 41,
    8080    SYS_GET_CYCLE      = 42,
    81     SYS_GET_SCHED      = 43,
    82     SYS_PANIC          = 44,
    83         SYS_SLEEP          = 45,
    84         SYS_WAKEUP         = 46,
    85 
    86         SYSCALLS_NR        = 47,
     81    SYS_DISPLAY        = 43,
     82    SYS_UNDEFINED_44   = 44,   ///
     83        SYS_THREAD_SLEEP   = 45,
     84        SYS_THREAD_WAKEUP  = 46,
     85    SYS_TRACE          = 47,
     86    SYS_FG             = 48,
     87    SYS_UNDEFINED_49   = 49,   ///
     88
     89        SYSCALLS_NR        = 50,
    8790};
    8891
     
    312315trace_operation_t;
    313316
     317/*******************************************************************************************
     318 * This enum defines the type of structure for the "display" syscall.
     319 ******************************************************************************************/
     320
     321typedef enum
     322{
     323    DISPLAY_STRING  = 0,
     324    DISPLAY_VMM     = 1,
     325    DISPLAY_SCHED   = 2,
     326    DISPLAY_PROCESS = 3,
     327    DISPLAY_VFS     = 4,
     328    DISPLAY_CHDEV   = 5,
     329}
     330display_type_t;
     331
    314332/******************************************************************************************
    315333 * This structure define the informations associated to a file descriptor,
     
    368386struct timezone
    369387{
    370     int          tz_minuteswest;            /*8 of Greenwich                              */
     388    int          tz_minuteswest;            /*! of Greenwich                              */
    371389    int          tz_dsttime;                /*! type of dst correction to apply           */
    372390};
  • trunk/kernel/syscalls/sys_exec.c

    r416 r421  
    170170
    171171    // get parent process pid
    172     thread_t   * this    = CURRENT_THREAD;
    173     process_t  * process = this->process;
    174     pid_t        pid     = process->pid;
     172    thread_t    * this    = CURRENT_THREAD;
     173    process_t   * process = this->process;
     174    pid_t         pid     = process->pid;
    175175
    176176#if CONFIG_SYSCALL_DEBUG
     
    178178uint64_t      tm_end;
    179179tm_start = hal_get_cycles();
    180 printk("\n[DBG] %s : core[%x,%d] enter / process %x / path = %s / cycle = %d\n",
    181 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path, (uint32_t)tm_start );
     180printk("\n[DBG] %s : core[%x,%d] enter / process %x / cycle = %d\n",
     181__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start );
    182182#endif
    183183
     
    251251#if CONFIG_SYSCALL_DEBUG
    252252tm_end = hal_get_cycles();
    253 printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d\n",
    254 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path, (uint32_t)(tm_end - tm_start) );
     253printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d / cycle %d\n",
     254__FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path,
     255(uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
    255256#endif
    256257
  • trunk/kernel/syscalls/sys_get_config.c

    r410 r421  
    3535int sys_get_config( uint32_t * x_size,
    3636                    uint32_t * y_size,
     37                    uint32_t * y_width,
    3738                    uint32_t * ncores )
    3839{
     
    4041    uint32_t  k_x_size;
    4142    uint32_t  k_y_size;
     43    uint32_t  k_y_width;
    4244    uint32_t  k_ncores;
    4345
     
    4850
    4951    // check buffer in user space
    50     error |= vmm_v2p_translate( false , x_size , &paddr );
    51     error |= vmm_v2p_translate( false , y_size , &paddr );
    52     error |= vmm_v2p_translate( false , ncores , &paddr );
     52    error |= vmm_v2p_translate( false , x_size  , &paddr );
     53    error |= vmm_v2p_translate( false , y_size  , &paddr );
     54    error |= vmm_v2p_translate( false , y_width , &paddr );
     55    error |= vmm_v2p_translate( false , ncores  , &paddr );
    5356
    5457        if( error )
     
    6164
    6265    // get parameters
    63         k_x_size = LOCAL_CLUSTER->x_size;
    64         k_y_size = LOCAL_CLUSTER->y_size;
    65         k_ncores = LOCAL_CLUSTER->cores_nr;
     66        k_x_size  = LOCAL_CLUSTER->x_size;
     67        k_y_size  = LOCAL_CLUSTER->y_size;
     68        k_y_width = LOCAL_CLUSTER->y_width;
     69        k_ncores  = LOCAL_CLUSTER->cores_nr;
    6670
    6771    // copy to user space
    68         hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) );
    69         hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) );
    70         hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) );
     72        hal_copy_to_uspace( x_size  , &k_x_size  , sizeof(uint32_t) );
     73        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) );
     75        hal_copy_to_uspace( ncores  , &k_ncores  , sizeof(uint32_t) );
    7176
    7277        return 0;
  • trunk/kernel/syscalls/sys_kill.c

    r416 r421  
    3838{
    3939    uint32_t    save_sr;       // required to enable IRQs
     40    xptr_t      process_xp;    // extended pointer on target reference process
     41    cxy_t       process_cxy;   // target process cluster
     42    process_t * process_ptr;   // local pointer on target process
     43    xptr_t      parent_xp;     // extended pointer on parent process
     44    cxy_t       parent_cxy;    // parent process cluster
     45    process_t * parent_ptr;    // local pointer on parent process
     46    pid_t       ppid;          // parent process PID
    4047
    4148    thread_t  * this    = CURRENT_THREAD;
     
    4956#endif
    5057
    51     // get owner process cluster and lpid
    52     cxy_t   owner_cxy  = CXY_FROM_PID( pid );
    53     lpid_t  lpid       = LPID_FROM_PID( pid );
     58    // get cluster and pointers on reference process
     59    process_xp  = cluster_get_reference_process_from_pid( pid );
     60    process_cxy = GET_CXY( process_xp );
     61    process_ptr = (process_t *)GET_PTR( process_xp );
    5462
    55     // check pid
    56     if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ) )
     63    // check process existence
     64    if( process_xp == XPTR_NULL )
    5765    {
    58         printk("\n[ERROR] in %s : illegal target PID = %d for thread %x in process %x\n",
    59         __FUNCTION__ , pid , this->trdid , pid );
     66        syscall_dmsg("\n[ERROR] in %s : process %x not found\n",
     67        __FUNCTION__ , pid );
     68        this->errno = EINVAL;
     69        return -1;
     70    }
     71   
     72    // get parent process PID
     73    parent_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
     74    parent_cxy = GET_CXY( parent_xp );
     75    parent_ptr = GET_PTR( parent_xp );
     76    ppid       = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
     77
     78    // processes INIT and processes KSH cannot be stoped or killed
     79    if( ppid < 2 )
     80    {
     81        syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n",
     82        __FUNCTION__ , pid );
    6083                this->errno = EINVAL;
    6184        return -1;
    6285    }
    6386
     87    // does nothing if sig_id == 0
     88    if( sig_id == 0 )  return 0;
     89   
    6490    // check sig_id
    6591    if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) )
    6692    {
    67         printk("\n[ERROR] in %s : illegal signal type for thread %x in process %x\n",
    68         __FUNCTION__ , sig_id , this->trdid , pid );
     93        syscall_dmsg("\n[ERROR] in %s : illegal signal type for process %x\n",
     94        __FUNCTION__ , sig_id , pid );
    6995                this->errno = EINVAL;
    7096        return -1;
     
    75101
    76102    // execute process_make_kill() function in owner cluster
    77     if( local_cxy == owner_cxy )                                // owner is local
     103    if( local_cxy == process_cxy )                            // owner cluster is local
    78104    {
    79105        process_make_kill( pid , sig_id );
    80106    }
    81     else                                                        // owner is remote
     107    else                                                      // owner cluster is remote
    82108    {
    83         rpc_process_make_kill_client( owner_cxy , pid , sig_id );
     109        rpc_process_make_kill_client( process_cxy , pid , sig_id );
    84110    }
    85111
  • trunk/kernel/syscalls/sys_read.c

    r418 r421  
    9898
    9999    // enable IRQs
    100     // hal_enable_irq( &save_sr );
     100    hal_enable_irq( &save_sr );
    101101
    102102    // get extended pointer on remote file descriptor
     
    129129
    130130    // action depend on file type
    131     if( type == INODE_TYPE_FILE )      // transfer count bytes from file mapper
    132     {
     131    if( type == INODE_TYPE_FILE )      // check file readable & read from mapper
     132    {
     133        // check file readable
     134        uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
     135        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
     136            {
     137            printk("\n[ERROR] in %s : file %d not readable in process %x\n",
     138            __FUNCTION__ , file_id , process->pid );
     139                    this->errno = EBADFD;
     140                    return -1;
     141            }
     142
     143        // move count bytes from mapper
    133144        nbytes = vfs_user_move( true,               // from mapper to buffer
    134145                                file_xp,
     
    136147                                count );
    137148    }
    138     else if( type == INODE_TYPE_DEV )  // transfer count bytes from device
    139     {
     149    else if( type == INODE_TYPE_DEV )  // check ownership & read from from device
     150    {
     151        // move count bytes from device
    140152        nbytes = devfs_user_move( true,             // from device to buffer
    141153                                  file_xp,
    142154                                  vaddr,
    143155                                  count );
     156
     157        // check ownership
     158        xptr_t    chdev_xp  = chdev_from_file( file_xp );
     159        cxy_t     chdev_cxy = GET_CXY( chdev_xp );
     160        chdev_t * chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     161        xptr_t    owner_xp  = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
     162
     163        if( XPTR( local_cxy , process ) != owner_xp )
     164        {
     165            printk("\n[ERROR] in %s : process %x not in foreground for TXT%d\n",
     166            __FUNCTION__, process->pid, hal_remote_lw( XPTR(chdev_cxy,&chdev_ptr->channel) ) );
     167                    this->errno = EBADFD;
     168                    return -1;
     169        }
    144170    }
    145171    else
    146172    {
    147173        nbytes = 0;
    148         panic("file type %d non supported yet", type );
     174        assert( false , __FUNCTION__ , "file type %d non supported yet\n", type );
    149175    }
    150176
     
    158184
    159185    // restore IRQs
    160     // hal_restore_irq( save_sr );
     186    hal_restore_irq( save_sr );
    161187
    162188    hal_fence();
     
    171197#endif
    172198
    173 #if CONFIG_READ_DEBUG
     199#if (CONFIG_READ_DEBUG & 0x1)
    174200exit_sys_read = (uint32_t)tm_end;
    175201
  • trunk/kernel/syscalls/sys_thread_join.c

    r409 r421  
    100100    if( target_ptr->signature != THREAD_SIGNATURE )
    101101    {
    102         panic("\n[PANIC] in %s : kernel stack overflow\n", __FUNCTION__ );
     102        assert( false , __FUNCTION__ , "kernel stack overflow\n" );
    103103    }
    104104
  • trunk/kernel/syscalls/sys_thread_yield.c

    r408 r421  
    22 * sys_thread_yield.c - calls the scheduler to yield
    33 *
    4  * Authors       Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *               Alain Greiner (2016,2017)
     4 * Authors       Alain Greiner (2016,2017)
    65 *
    76 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
  • trunk/kernel/syscalls/sys_write.c

    r418 r421  
    9292    cxy_t        file_cxy = GET_CXY( file_xp );
    9393
    94     // check file writable
    95     uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
    96     if( (attr & FD_ATTR_WRITE_ENABLE) == 0 )
    97         {
    98         printk("\n[ERROR] in %s : file %d not writable in process %x\n",
    99         __FUNCTION__ , file_id , process->pid );
    100                 this->errno = EBADFD;
    101                 return -1;
    102         }
    103    
     94 
    10495    // get file type
    10596    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    10697
    10798    // action depend on file type
    108     if( type == INODE_TYPE_FILE )      // transfer count bytes to file mapper
     99    if( type == INODE_TYPE_FILE )  // check file writable & write to mapper
    109100    {
     101        // check file writable
     102        uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
     103        if( (attr & FD_ATTR_WRITE_ENABLE) == 0 )
     104            {
     105            printk("\n[ERROR] in %s : file %d not writable in process %x\n",
     106            __FUNCTION__ , file_id , process->pid );
     107                    this->errno = EBADFD;
     108                    return -1;
     109            }
     110
     111        // move count bytes to mapper
    110112        nbytes = vfs_user_move( false,               // from buffer to mapper
    111113                                file_xp,
     
    113115                                count );
    114116    }
    115     else if( type == INODE_TYPE_DEV )  // transfer count bytes to device
     117    else if( type == INODE_TYPE_DEV )  // check ownership & write to device
    116118    {
     119        // move count bytes to device
    117120        nbytes = devfs_user_move( false,             // from buffer to device
    118121                                 file_xp,
     
    123126    {
    124127        nbytes = 0;
    125         panic("file type %d non supported", type );
     128        assert( false , __FUNCTION__ , "file type %d non supported\n", type );
    126129    }
    127130
     
    148151#endif
    149152 
    150 #if CONFIG_WRITE_DEBUG
     153#if (CONFIG_WRITE_DEBUG & 0x1)
    151154printk("\n@@@@@@@@@@@@ timing to write character %c\n"
    152155" - enter_sys_write    = %d\n"
  • trunk/kernel/syscalls/syscalls.h

    r409 r421  
    7878 * [3] This blocking function suspend execution of the calling thread until completion
    7979 * of another target thread identified by the <trdid> argument.
     80 * The target thread must be joinable (running in ATTACHED mode), and must be different
     81 * from the calling thread.
    8082 * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the
    8183 * target thread is stored in the location referenced by exit_value.
     
    426428 * remote access to traverse the list of process copies stored in the owner cluster,
    427429 * and the RPC_SIGNAL_RISE to signal the remote threads.
     430 * This function does nothing for (sig_id == 0). This can be used to check process pid.
     431 * TODO : This first implementation supports only SIGKILL / SIGSTOP / SIGCONT values.
    428432 ******************************************************************************************
    429433 * @ pid      : target process identifier.
     
    491495
    492496/******************************************************************************************
    493  * [39] This non-standard function is used to activate / desactivate the trace for a thread
     497 * [39] This blocking function wait a change of a child process state. A change can be:
     498 * - a termination of child following a child exit.
     499 * - a termination of child following a SIGKILL signal.
     500 * - a blocking of child following a SIGSTOP signal.
     501 * It returns the PID of the involved child process, after storing in the memory slot
     502 * pointed by the <status> argument relevant information on the child state change.
     503 * The following macros can be used to extract information from status:
     504 * - WIFEXITED(status)   : is true if the child process terminated with an exit().
     505 * - WIFSIGNALED(status) : is true if the child process terminated by a signal.
     506 * - WIFSTOPPED(status)  : is true if the child process is stopped by a signal.
     507 * - WEXITSTATUS(status) : returns the low-order 8 bits of the exit() argument.
     508 * A status of 0 indicates a normal termination.
     509 * If a parent process terminates without waiting for all child processes to terminate,
     510 * the remaining child processes are attached to the init process.
     511 ******************************************************************************************
     512 * @ status : pointer on the child PID status.
     513 * @ return child PID if success / return -1 if failure.
     514 *****************************************************************************************/
     515int sys_wait( uint32_t * status );
     516
     517/******************************************************************************************
     518 * [40] This function returns the hardware platform parameters.
     519 ******************************************************************************************
     520 * @ x_size   : [out] number of clusters in a row.
     521 * @ y_size   : [out] number of clusters in a column.
     522 * @ y_width  : [out] number of bits in Y field for CXY.
     523 * @ ncores   : [out] number of cores per cluster.
     524 * @ return 0 if success / return -1 if illegal arguments
     525 *****************************************************************************************/
     526int sys_get_config( uint32_t * x_size,
     527                    uint32_t * y_size,
     528                    uint32_t * y_width,
     529                    uint32_t * ncores );
     530
     531/******************************************************************************************
     532 * [41] This function returns the calling core cluster and local index.
     533 ******************************************************************************************
     534 * @ cxy      : [out] cluster identifier (fixed format)
     535 * @ lid      : [out] core local index in cluster.
     536 * @ return 0 if success / return -1 if illegal arguments
     537 *****************************************************************************************/
     538int sys_get_core( uint32_t * cxy,
     539                  uint32_t * lid );
     540
     541/******************************************************************************************
     542 * [42] This function returns in a 64 bits user buffer the calling core cycles count.
     543 * It uses both the hardware register and the core descriptor cycles count to take
     544 * into account a possible harware register overflow  in 32 bits architectures.
     545 ******************************************************************************************
     546 * cycle    : [out] address of buffer in user space.
     547 * @ return 0 if success / return -1 if illegal arguments
     548 *****************************************************************************************/
     549int sys_get_cycle( uint64_t * cycle );
     550
     551/******************************************************************************************
     552 * [43] This debug function displays on the kernel terminal TXT0 an user defined string,
     553 * or the current state of a kernel structure, identified by the <type> argument.
     554 * The <arg0> and <arg1> arguments depends on the structure type. It can be:
     555 * - VMM     : VSL and GPT for a process identified by <pid>.
     556 * - SCHED   : all threads allocated to a scheduler identified by <cxy> & <lid>.
     557 * - PROCESS : all processes registered in a cluster identified by <cxy>. 
     558 * - VFS     : all files registered in the VFS cache.
     559 * - CHDEV   : all registered channel devices.
     560 ******************************************************************************************
     561 * type     : [in] STRING / VMM / SCHED / PROCESS / VSEG / VFS
     562 * arg0      : [in] type dependant argument.
     563 * arg1      : [in] type dependant argument.
     564 * @ return 0 if success / return -1 if illegal arguments
     565 *****************************************************************************************/
     566int sys_display( reg_t  type,
     567                 reg_t  arg0,
     568                 reg_t  arg1 );
     569
     570/******************************************************************************************
     571 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
     572 * and deschedule.
     573 ******************************************************************************************
     574 * @ return 0 if success / returns -1 if failure.
     575 *****************************************************************************************/
     576int sys_thread_sleep();
     577
     578/******************************************************************************************
     579 * [46] This function unblock the thread identified by its <trdid> from the
     580 * THREAD_BLOCKED_GLOBAL condition.
     581 ******************************************************************************************
     582 * @ trdid  : target thread identifier.
     583 * @ return 0 if success / return -1 if failure.
     584 *****************************************************************************************/
     585int sys_thread_wakeup();
     586
     587/******************************************************************************************
     588 * [47] This non-standard function is used to activate / desactivate the trace for a thread
    494589 * identified by the <trdid> and <pid> arguments.
    495590 * It can be called by any other thread in the same process.
     
    505600
    506601/******************************************************************************************
    507  * [40] This function returns the hardware platform parameters.
    508  ******************************************************************************************
    509  * @ x_size   : [out] number of clusters in a row.
    510  * @ y_size   : [out] number of clusters in a column.
    511  * @ ncores   : [out] number of cores per cluster.
    512  * @ return 0 if success / return -1 if illegal arguments
    513  *****************************************************************************************/
    514 int sys_get_config( uint32_t * x_size,
    515                     uint32_t * y_size,
    516                     uint32_t * ncores );
    517 
    518 /******************************************************************************************
    519  * [41] This function returns the calling core cluster and local index.
    520  ******************************************************************************************
    521  * @ cxy      : [out] cluster identifier (fixed format)
    522  * @ lid      : [out] core local index in cluster.
    523  * @ return 0 if success / return -1 if illegal arguments
    524  *****************************************************************************************/
    525 int sys_get_core( uint32_t * cxy,
    526                   uint32_t * lid );
    527 
    528 /******************************************************************************************
    529  * [42] This function returns in a 64 bits user buffer the calling core cycles count.
    530  * It uses both the hardware register and the core descriptor cycles count to take
    531  * into account a possible harware register overflow  in 32 bits architectures.
    532  ******************************************************************************************
    533  * cycle    : [out] address of buffer in user space.
    534  * @ return 0 if success / return -1 if illegal arguments
    535  *****************************************************************************************/
    536 int sys_get_cycle( uint64_t * cycle );
    537 
    538 /******************************************************************************************
    539  * [43] This debug function displays on the kernel terminal the current state of a
    540  * scheduler identified by the <cxy> and <lid> arguments.
    541  ******************************************************************************************
    542  * cxy      : [in] target cluster identifier.
    543  * lid      : [in] target core local index.
    544  * @ return 0 if success / return -1 if illegal arguments
    545  *****************************************************************************************/
    546 int sys_get_sched( uint32_t  cxy,
    547                    uint32_t  lid );
    548 
    549 /******************************************************************************************
    550  * [44] This debug function requires the kernel to display on the kernel terminal a message
    551  * containing the thread / process / core identifiers, and the cause of panic,
    552  * as defined by the <string> argument.
    553  ******************************************************************************************
    554  * string   : [in] message to be displayed.
    555  * @ return always 0.
    556  *****************************************************************************************/
    557 int sys_panic( char * string );
    558 
    559 /******************************************************************************************
    560  * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition,
    561  * and deschedule.
    562  ******************************************************************************************
    563  * @ return 0 if success / returns -1 if failure.
    564  *****************************************************************************************/
    565 int sys_thread_sleep();
    566 
    567 /******************************************************************************************
    568  * [46] This function unblock the thread identified by its <trdid> from the
    569  * THREAD_BLOCKED_GLOBAL condition.
    570  ******************************************************************************************
    571  * @ trdid  : target thread identifier.
    572  * @ return 0 if success / return -1 if failure.
    573  *****************************************************************************************/
    574 int sys_thread_wakeup();
     602 * [48] This function gives the process identified by the <pid> argument
     603 * the exclusive ownership of its TXT_TX terminal (put it in foreground).
     604 ******************************************************************************************
     605 * @ pid    : process identifier.
     606 * @ return 0 if success / return -1 if failure.
     607 *****************************************************************************************/
     608int sys_fg( pid_t   pid );
    575609
    576610
Note: See TracChangeset for help on using the changeset viewer.