Ignore:
Timestamp:
Jan 29, 2018, 6:08:07 PM (6 years ago)
Author:
alain
Message:

blip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.h

    r416 r428  
    5454
    5555/*********************************************************************************************
    56  * This enum defines the actions that can be executed by the process_signal() function.
     56 * This enum defines the actions that can be executed by the process_sigaction() function.
    5757 ********************************************************************************************/
    5858
     
    6262    UNBLOCK_ALL_THREADS  = 22,
    6363    DELETE_ALL_THREADS   = 33,
     64};
     65
     66/*********************************************************************************************
     67 * This enum defines the process states for ALMOS_MKH.
     68 ********************************************************************************************/
     69
     70enum process_states
     71{
     72    PROCESS_STATE_RUNNING = 0,           /*! process is executing                           */
     73    PROCESS_STATE_STOPPED = 1,           /*! process has been stopped by a signal           */
     74    PROCESS_STATE_KILLED  = 2,           /*! process has been killed by a signal            */
     75    PROCESS_STATE_EXITED  = 3,           /*! process terminated with an exit                */
    6476};
    6577
     
    102114 * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated
    103115 *    <sync_lock>, that are dynamically allocated, are only defined in the reference cluster.
    104  * 5) The <children_root>, and <children_nr> fields are only defined in the reference
    105  *    cluster, and are undefined in other clusters.
    106  * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
     116 * 5) The <children_root>, <children_nr>, <brothers_list>, and <txt_list> fields are only
     117 *    defined in the reference cluster, and are undefined in other clusters.
     118 * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
    107119 *    are defined in all process descriptors copies.
    108120 ********************************************************************************************/
     
    115127
    116128        xptr_t            vfs_root_xp;      /*! extended pointer on current VFS root inode      */
    117         xptr_t            vfs_bin_xp;       /*! extended pointer on .elf file inode             */
     129        xptr_t            vfs_bin_xp;       /*! extended pointer on .elf file descriptor        */
    118130        pid_t             pid;              /*! process identifier                              */
    119         pid_t             ppid;             /*! parent process identifier                       */
    120131    xptr_t            ref_xp;           /*! extended pointer on reference process           */
     132    xptr_t            parent_xp;        /*! extended pointer on parent process              */
    121133
    122134        xptr_t            vfs_cwd_xp;       /*! extended pointer on current working dir inode   */
     
    124136
    125137        xlist_entry_t     children_root;    /*! root of the children process xlist              */
     138    remote_spinlock_t children_lock;    /*! lock protecting children process xlist          */
    126139    uint32_t          children_nr;      /*! number of children processes                    */
    127140
    128         xlist_entry_t     brothers_list;    /*! member of list of children of same parent       */
     141        xlist_entry_t     children_list;    /*! member of list of children of same parent       */
    129142    xlist_entry_t     local_list;       /*! member of list of process in same cluster       */
    130143    xlist_entry_t     copies_list;      /*! member of list of copies of same process        */
     144    xlist_entry_t     txt_list;         /*! member of list of processes sharing same TXT    */
    131145
    132146        spinlock_t        th_lock;          /*! lock protecting th_tbl[] concurrent access      */
    133147        uint32_t          th_nr;            /*! number of threads in this cluster               */
     148
    134149        struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads  */
    135150
     
    138153    xlist_entry_t     barrier_root;     /*! root of the process barrier list                */
    139154    xlist_entry_t     condvar_root;     /*! root of the process condvar list                */
    140 
    141155    remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
     156
     157    uint32_t          state;            /*! RUNNING / STOPPED / KILLED / EXITED             */
     158
     159    bool_t            txt_owner;        /*! current TXT owner                               */
    142160}
    143161process_t;
     
    182200
    183201/*********************************************************************************************
     202 * This function initialize, in each cluster, the kernel "process_zero", that is the owner
     203 * of all kernel threads in a given cluster. It is called by the kernel_init() function.
     204 * The process_zero descriptor is allocated as a global variable in file kernel_init.c
     205 * Both the PID and PPID fields are set to zero, the ref_xp is the local process_zero,
     206 * and the parent process is set to XPTR_NULL. The th_tbl[] is initialized as empty.
     207 *********************************************************************************************
     208 * @ process      : [in] pointer on local process descriptor to initialize.
     209 ********************************************************************************************/
     210void process_zero_create( process_t * process );
     211
     212/*********************************************************************************************
    184213 * This function allocates memory and initializes the "process_init" descriptor and the
    185214 * associated "thread_init" descriptor. It is called once at the end of the kernel
    186  * initialisation procedure, by the kernel process in cluster_IO.
     215 * initialisation procedure. Its local process identifier is 1, and parent process
     216 * is the kernel process in cluster 0.
    187217 * The "process_init" is the first user process, and all other user processes will be forked
    188218 * from this process. The code executed by "process_init" is stored in a .elf file, whose
    189219 * pathname is defined by the CONFIG_PROCESS_INIT_PATH configuration variable.
    190  * The process_init streams are defined  by the CONFIG_INIT_[STDIN/STDOUT/STDERR] variables.
    191  * Its local process identifier is 1, and parent process is the local kernel process_zero.
     220 * The process_init does not use the [STDIN/STDOUT/STDERR] streams, but it is linked
     221 * to kernel TXT0, because these streams must be defined for all user processes.
    192222 ********************************************************************************************/
    193223void process_init_create();
    194224
    195225/*********************************************************************************************
    196  * This function initialize, in each cluster, the kernel "process_zero", that is the owner
    197  * of all kernel threads in a given cluster. It is called by the kernel_init() function.
    198  * Both the PID and PPID fields are set to zero, and the ref_xp is the local process_zero.
    199  * The th_tbl[] is initialized as empty.
    200  *********************************************************************************************
    201  * @ process      : [in] pointer on local process descriptor to initialize.
    202  ********************************************************************************************/
    203 void process_zero_init( process_t * process );
    204 
    205 /*********************************************************************************************
    206  * This function initializes a local, reference user process descriptor from another process
    207  * descriptor, defined by the <model_xp> argument. The <process> descriptor, the <pid>, and
    208  * the <ppid> arguments must be previously defined by the caller.
    209  * It can be called by two functions, depending on the process type:
    210  * 1) if "process" is the "process_init", the parent is the kernel process. It is
    211  *    called once, by the process_init_create() function in cluster[xmax-1][ymax-1].
    212  * 2) if the caller is the process_make_fork() function, the model is generally a remote
    213  *    process, that is also the parent process.
    214 
    215  * 3) if the caller is the process_make_exec() function, the model is always a local process,
    216  *    and the parent is the parent of the model process. DEPRECATED [AG]
    217 
    218  * The following fields are initialised (for all process but process_zero).
    219  * - It set the pid / ppid / ref_xp fields.
     226 * This function initializes a local, reference, user process descriptor from another process
     227 * descriptor, defined by the <model_xp> argument. The <process> and <pid> arguments must
     228 * be previously allocated by he caller. This function can be called by three functions:
     229 * 1) process_init_create() : process is the reference INIT process / pid = 1 /
     230 *    the parent and model process descriptors are both the kernel process_zero.
     231 * 2) process_make_fork() : the model process descriptor is the (generally remote)
     232 *    parent process.
     233 * 3) process_make exec() : the model process is the local old_process, the new_process
     234 *    parent is the same as the old_process parent.
     235 * The following fields are initialised :
     236 * - It set the pid / ppid / ref_xp / parent_xp / state fields.
    220237 * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
    221238 * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
     
    230247 * @ process      : [in] pointer on local process descriptor to initialize.
    231248 * @ pid          : [in] process identifier.
    232  * @ ppid         : [in] parent process identifier.
    233  * @ model_xp     : [in] extended pointer on model process descriptor (local or remote).
     249 * @ parent_xp    : [in] extended pointer on parent process descriptor.
     250 * @ model_xp     : [in] extended pointer on model process descriptor.
    234251 ********************************************************************************************/
    235252void process_reference_init( process_t * process,
    236253                             pid_t       pid,
    237                              pid_t       ppid,
     254                             xptr_t      parent_xp,
    238255                             xptr_t      model_xp );
    239256
     
    259276
    260277/*********************************************************************************************
    261  * This function returns a printable string defining the action for process_signa().
    262  *********************************************************************************************
    263  * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
     278 * This function returns a printable string defining the process state.
     279 *********************************************************************************************
     280 * @ state   : RUNNING / BLOCKED / EXITED / KILLED
    264281 * @ return a string pointer.
    265282 ********************************************************************************************/
    266 char * process_action_str( uint32_t action_type );
     283char * process_state_str( uint32_t state );
     284
     285/*********************************************************************************************
     286 * This debug function diplays on the kernel terminal TXT0 detailed informations on a
     287 * reference process identified by the <process_xp> argument.
     288 * It can be called by a thread running in any cluster.
     289 *********************************************************************************************
     290 * @ process_xp : extended pointer on reference process.
     291 ********************************************************************************************/
     292void process_display( xptr_t process_xp );
     293
     294/*********************************************************************************************
     295 * This function returns a printable string defining the sigaction type.
     296 *********************************************************************************************
     297 * @ sigaction_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
     298 * @ return a string pointer.
     299 ********************************************************************************************/
     300char * process_action_str( uint32_t sigaction_type );
    267301
    268302/*********************************************************************************************
     
    290324
    291325/*********************************************************************************************
    292  * This function blocks all threads of a given user process in a given cluster.
     326 * This function blocks all threads (but the client thread defined by the <client_xp>
     327 * argument) for a given <process> in a given cluster.
    293328 * It loops on all local threads of the process, set the THREAD_BLOCKED_GLOBAL bit,
    294329 * and request the relevant schedulers to acknowledge the blocking, using IPI if required.
    295330 * The threads are not detached from the scheduler, and not detached from the local process.
    296331 * This function returns only when all blockable threads in cluster are actually blocked.
    297  * WARNING : the client thread defined by the <client_xp> argument is NOT blocked.
    298332 *********************************************************************************************
    299333 * @ process     : pointer on the target process descriptor.
    300334 * @ client_xp   : extended pointer on the client thread, that should not be blocked.
    301335 ********************************************************************************************/
    302 void process_block( process_t * process,
    303                     xptr_t      client_xp );
     336void process_block_threads( process_t * process,
     337                            xptr_t      client_xp );
    304338
    305339/*********************************************************************************************
     
    308342 * @ process     : pointer on the process descriptor.
    309343 ********************************************************************************************/
    310 void process_unblock( process_t * process );
    311 
    312 /*********************************************************************************************
    313  * This function delete all threads, of a given user process in a given cluster.
     344void process_unblock_threads( process_t * process );
     345
     346/*********************************************************************************************
     347 * This function delete all threads, (but the client thread defined by the <client_xp>
     348 * argument) for a given <process> in a given cluster.
    314349 * It loops on all local threads of the process, and set the THREAD_FLAG_REQ_DELETE bit.
    315350 * For each marked thread, the following actions will be done by the scheduler at the next
     
    320355 * - the memory allocated to the thread descriptor is released.
    321356 * - the memory allocated to the process descriptor is released, if it is the last thread.
    322  * WARNING : the client thread defined by the <client_xp> argument is NOT deleted.
    323357 *********************************************************************************************
    324358 * @ process     : pointer on the process descriptor.
    325359 * @ client_xp   : extended pointer on the client thread, that should not be deleted.
    326360 ********************************************************************************************/
    327 void process_delete( process_t * process,
    328                      xptr_t      client_xp );
     361void process_delete_threads( process_t * process,
     362                             xptr_t      client_xp );
    329363
    330364/*********************************************************************************************
     
    509543
    510544
     545/***************   Terminals related operations  ********************************************/
     546
     547/*********************************************************************************************
     548 * This function scan the set of user TXT terminals to find a free terminal
     549 * (the list of attached processes is empty for a free TXT terminal).
     550 * It is called only by the process_reference_init() function when creating a KSH process.
     551 * It makes a kernel panic if no free TXT terminal is found.
     552 * As a KSH process is never deleted, the allocated TXT terminal is never released.
     553 *********************************************************************************************
     554 * @ return TXT terminal index if succes / kernel panic if no terminal found.
     555 ********************************************************************************************/
     556uint32_t process_txt_alloc();
     557
     558/*********************************************************************************************
     559 * This function attach a reference process descriptor, identified by the <process>
     560 * argument to a TXT terminal, identified by its <txt_id> channel index argument.
     561 * It insert the process descriptor in the xlist rooted in the TXT_RX device.
     562 * It is called by the process_reference_init() function.
     563 *********************************************************************************************
     564 * @ process  : local pointer on process descriptor.
     565 * @ txt_id   : TXT channel index.
     566 ********************************************************************************************/
     567void process_txt_attach( process_t * process,
     568                         uint32_t    txt_id );
     569
     570/*********************************************************************************************
     571 * This function detach a reference process descriptor, identified by the <process_xp>
     572 * argument, from the list of process attached to a given TXT terminal.
     573 * It is called when the process is killed.
     574 *********************************************************************************************
     575 * @ process  : local pointer on process descriptor.
     576 ********************************************************************************************/
     577void process_txt_detach( process_t * process );                     
     578
     579/*********************************************************************************************
     580 * This function gives to a process identified by the <process_xp> argument, and attached
     581 * to terminal TXT[i] the exclusive ownership of the TXT_RX[i] terminal.
     582 *********************************************************************************************
     583 * @ process_xp  : extended pointer on reference process descriptor.
     584 ********************************************************************************************/
     585void process_txt_set_ownership( xptr_t process_xp );
     586
     587/*********************************************************************************************
     588 * When the process identified by the <process_xp> argument has the exclusive ownership
     589 * of the TXT_RX[i] terminal, this function gives this ownership to the KSH[i] process.
     590 * It does nothing if the process is not the owner.
     591 *********************************************************************************************
     592 * @ process_xp  : extended pointer on reference process descriptor.
     593 ********************************************************************************************/
     594void process_txt_reset_ownership( xptr_t process_xp );
    511595
    512596#endif  /* _PROCESS_H_ */
Note: See TracChangeset for help on using the changeset viewer.