Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

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

    r14 r23  
    44 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
    55 *          Mohamed Lamine Karaoui (2015)
    6  *          Alain Greiner (2016)
     6 *          Alain Greiner (2016,2017)
    77 *
    88 * Copyright (c) UPMC Sorbonne Universites
     
    5454
    5555/*********************************************************************************************
    56  * These macros are used to compose or decompose global thread identifier (TRDID)
    57  * to or from cluster identifier / local thread index (CXY , LTID)
    58  ********************************************************************************************/
    59 
    60 #define LTID_FROM_TRDID( trdid )   (ltid_t)(trdid & 0x0000FFFF)
    61 #define CXY_FROM_TRDID( trdid )    (cxy_t)(trdid >> 16)
    62 #define TRDID( cxy , ltid )        (trdid_t)((cxy << 16) | ltid )
    63 
    64 /*********************************************************************************************
    6556 * This structure defines an array of extended pointers on the open file descriptors
    6657 * for a given process. We use an extended pointer because the open file descriptor
     
    6859 * A free entry in this array contains the XPTR_NULL value.
    6960 * The array size is defined by a the CONFIG_PROCESS_FILE_MAX_NR parameter.
    70  * All modifications (open/close) must be done by the reference cluster, and reported
     61 * All modifications (open/close) in this structure must be done by the reference cluster,
     62 * and reported in process copies.
    7163 ********************************************************************************************/
    7264
     
    7567        remote_spinlock_t lock;             /*! lock protecting fd_array[] change.              */
    7668    uint32_t          current;          /*! current number of open files                    */
    77     uint32_t          max;              /*! max number of open files (can be increased)     */
    7869        xptr_t            array[CONFIG_PROCESS_FILE_MAX_NR]; 
    7970}
     
    8879 * allocated to this cluster.
    8980 * The process descriptor for a PID process is replicated in all clusters containing
    90  * at least one thread of the PID process, with some restrictions:
    91  * - The list of registered vsegs, the page table (contained in vmm), and the fd_array[]
    92  *   are only complete in the reference process descriptor, other copies are read-only caches.
    93  * - The following fields are NOT defined in copies other than the reference:
    94  *   children_root , children_list , children_nr , sig_mgr
     81 * at least one thread of the PID process, with the following rules :
     82 *
     83 * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp>  fields are defined
     84 *    in all process descriptor copies.
     85 * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified,
     86 *    are only defined in the reference process descriptor.
     87 * 2) The <vmm>, containing the list of registered vsegs, and the page table, are only
     88 *    complete in the reference process cluster, other copies are read-only caches.
     89 * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only
     90 *    complete in the reference process cluster, other copies are read-only caches.
     91 * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated
     92 *    <sync_lock>, that are dynamically allocated, are only defined in the reference cluster.
     93 * 5) The <children_root>, and <children_nr> fields are only defined in the reference
     94 *    cluster, and are undefined in other clusters.
     95 * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
     96 *    are defined in all process descriptors copies.
     97 * 7) The <sig_mgr> field is only defined in the reference cluster. TODO
    9598 ********************************************************************************************/
    9699
    97100typedef struct process_s
    98101{
    99         vmm_t            vmm;               /*! embedded virtual memory manager                 */
    100 
    101         fd_array_t       fd_array;          /*! embedded file descriptors array                 */
    102 
    103         xptr_t           vfs_root_xp;       /*! extende pointer on current file system root     */
    104         xptr_t           vfs_cwd_xp;        /*! extended pointer on current working directory   */
    105         xptr_t           vfs_bin_xp;        /*! extended pointer on associate .elf file         */
    106 
    107         spinlock_t       cd_lock;           /*! lock protecting working directory changes       */
     102        vmm_t             vmm;              /*! embedded virtual memory manager                 */
     103
     104        fd_array_t        fd_array;         /*! embedded open file descriptors array            */
     105
     106        xptr_t            vfs_root_xp;      /*! extende pointer on current VFS root inode       */
     107        xptr_t            vfs_bin_xp;       /*! extended pointer on .elf file inode             */
     108        pid_t             pid;              /*! process identifier                              */
     109        pid_t             ppid;             /*! parent process identifier                       */
     110    xptr_t            ref_xp;           /*! extended pointer on reference process           */
     111
     112        xptr_t            vfs_cwd_xp;       /*! extended pointer on current working dir inode   */
     113        remote_rwlock_t   cwd_lock;         /*! lock protecting working directory changes       */
    108114 
    109         pid_t            pid;               /*! process identifier                              */
    110         pid_t            ppid;              /*! parent process identifier                       */
    111         bool_t           is_ref;            /*! this is the reference process if true           */
    112     xptr_t           ref_xp;            /*! extended pointer on reference process           */
    113 
    114         xlist_entry_t    children_root;     /*! root of the children process xlist              */
    115     uint32_t         children_nr;       /*! number of children processes                    */
    116 
    117         xlist_entry_t    brothers_list;     /*! member of list of children of same parent       */
    118 
    119     list_entry_t     local_list;        /*! member of list of process in same cluster       */
    120 
    121     xlist_entry_t    copies_list;       /*! member of list of copies of same process        */
    122 
    123         spinlock_t       th_lock;           /*! lock protecting th_tbl[] concurrent access      */
    124         uint32_t         th_nr;             /*! number of threads in this cluster               */
    125 
     115        xlist_entry_t     children_root;    /*! root of the children process xlist              */
     116    uint32_t          children_nr;      /*! number of children processes                    */
     117
     118        xlist_entry_t     brothers_list;    /*! member of list of children of same parent       */
     119    xlist_entry_t     local_list;       /*! member of list of process in same cluster       */
     120    xlist_entry_t     copies_list;      /*! member of list of copies of same process        */
     121
     122        spinlock_t        th_lock;          /*! lock protecting th_tbl[] concurrent access      */
     123        uint32_t          th_nr;            /*! number of threads in this cluster               */
    126124        struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads  */
    127125
    128     xlist_entry_t    sem_root;          /*! root of the process semaphores list             */
    129     uint32_t         sem_nr;            /*! number of semaphores                            */
    130 
    131         sig_mgr_t        sig_mgr;           /*! embedded signal manager TODO [AG]               */
     126    xlist_entry_t     sem_root;         /*! root of the process semaphore list              */
     127    xlist_entry_t     mutex_root;       /*! root of the process mutex list                  */
     128    xlist_entry_t     barrier_root;     /*! root of the process barrier list                */
     129    xlist_entry_t     condvar_root;     /*! root of the process condvar list                */
     130
     131    remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
     132
     133        sig_mgr_t         sig_mgr;          /*! embedded signal manager TODO [AG]               */
    132134}
    133135process_t;
     
    149151    xptr_t             vfs_bin_xp;     /*! extended pointer on process .elf file            */
    150152
    151     char               path[256];      /*! pathname for  .elf file                          */
     153    char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
    152154
    153155    char            ** args_pointers;  /*! physical base address of array of pointers       */
     
    162164exec_info_t;
    163165
    164 /*********************************************************************************************
    165  * This macro returns a pointer on the process descriptor for the calling thread.
    166  ********************************************************************************************/
    167 
    168 #define CURRENT_PROCESS (hal_get_current_thread()->process)
    169 
    170166/***************   Process Descriptor Operations    *****************************************/
    171167
     
    204200 * The PID value must have been defined previously by the owner cluster manager.
    205201 * The reference cluster can be different from the owner cluster.
    206  * It set the pid / ppid / is_ref / pref / fields.
     202 * It set the pid / ppid / ref_xp fields.
    207203 * It registers this process descriptor in three lists:
    208204 * - the children_list in the parent process descriptor.
     
    232228/*********************************************************************************************
    233229 * This function releases all memory allocated for a process descriptor in the local cluster,
    234  * after releasing memory allocated for embedded substructures (fd_array, vmm, etc).
     230 * including memory allocated for embedded substructures (fd_array, vmm, etc).
    235231 * The local th_tbl[] array must be empty.
    236232 *********************************************************************************************
     
    255251 * If this local copy does not exist yet, it is dynamically created, from the reference
    256252 * process descriptor, registered in the global copies_list, and registered in the local_list.
    257  * This function is used by both thread_user_create() and thread_user_copy() functions.
     253 * This function is used by the thread_user_create() function.
    258254 *********************************************************************************************
    259255 * @ pid     : searched process identifier.
     
    288284
    289285/*********************************************************************************************
    290  * This function reset the file descriptor array for a given process: no open file.
     286 * This function initialises all entries of the local fd_array as empty.
    291287 *********************************************************************************************
    292288 * @ process  : pointer on the local process descriptor.
     
    295291
    296292/*********************************************************************************************
    297  * This function closes all open files and releases all file descriptors.
     293 * This function uses as many remote accesses as required, to reset an entry in fd_array[],
     294 * in all clusters containing a copy. The entry is identified by the <file_id> argument.
     295 * This function must be executed by a thread running reference cluster, that contain
     296 * the complete list of process descriptors copies.
    298297 *********************************************************************************************
    299298 * @ process  : pointer on the local process descriptor.
    300  ********************************************************************************************/
    301 void process_fd_destroy( process_t * process );
     299 * @ file_id  : file descriptor index in the fd_array.
     300 ********************************************************************************************/
     301void process_fd_remove( process_t * process,
     302                        uint32_t    file_id );
     303
     304/*********************************************************************************************
     305 * This function returns an extended pointer on a file descriptor identified by its index
     306 * in fd_array. It can be called by any thread running in any cluster.
     307 * It access first the local process descriptor. In case of local miss, it uses remote access
     308 * to access the reference process descriptor.
     309 * It updates the local fd_array when the file descriptor exist in reference cluster.
     310 * The file descriptor refcount is not incremented.
     311 *********************************************************************************************
     312 * @ process  : pointer on the local process descriptor.
     313 * @ file_id  : file descriptor index in the fd_array.
     314 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.
     315 ********************************************************************************************/
     316xptr_t process_fd_get_xptr( process_t * process,
     317                            uint32_t    file_id );
    302318
    303319/*********************************************************************************************
    304320 * This function checks the number of open files for a given process.
    305  *********************************************************************************************
    306  * @ process  : pointer on the local process descriptor.
     321 * It can be called by any thread in any cluster, because it uses portable remote access
     322 * primitives to access the reference process descriptor.
     323 *********************************************************************************************
    307324 * @ returns true if file descriptor array full.
    308325 ********************************************************************************************/
    309 bool_t process_fd_array_full( process_t * process );
    310 
    311 /*********************************************************************************************
    312  * These functions allocates a slot in the fd_array for a given process,
    313  * and returns the file descriptor index.
    314  *********************************************************************************************
    315  * @ process  : pointer on the local process descriptor.
    316  * @ file     : extended pointer on the file descriptor.
    317  * @ fd       : [out] file descriptor index
     326bool_t process_fd_array_full();
     327
     328/*********************************************************************************************
     329 * This function allocates a free slot in the fd_array of the reference process,
     330 * register the <file_xp> argument in the allocated slot, and return the slot index.
     331 * It can be called by any thread in any cluster, because it uses portable remote access
     332 * primitives to access the reference process descriptor.
     333 *********************************************************************************************
     334 * @ file_xp  : extended pointer on the file descriptor to be registered.
     335 * @ file_id  : [out] buffer for fd_array slot index.
    318336 * @ return 0 if success / return EMFILE if array full.
    319337 ********************************************************************************************/
    320 error_t process_fd_allocate( process_t * process,
    321                              xptr_t      file_xp,
    322                              uint32_t  * fd );
    323 
    324 /*********************************************************************************************
    325  * This function releases an existing file descriptor from the process fd_array.
    326  *********************************************************************************************
    327  * @ process  : pointer on the local process descriptor.
    328  * @ return 0 if success / return EBADF if illegal file descriptor.
    329  ********************************************************************************************/
    330 error_t process_fd_release( process_t * process,
    331                             uint32_t    fd );
    332 
    333 /*********************************************************************************************
    334  * This function copies all non-zero entries from a local <src> fd_array,
    335  * embedded in a process descriptor, to another local <dst_xp> fd_array, embedded
    336  * in another process descriptor.
    337  * It takes the remote lock protecting the <src> fd_array during the copy.
    338  * For each involved file descriptor, the refcount is incremented.
    339  *********************************************************************************************
    340  * @ dst   : pointer on the destination fd_array_t.
    341  * @ src   : pointer on the source fd_array_t.
    342  ********************************************************************************************/
    343 void process_fd_local_copy( fd_array_t * dst,
    344                             fd_array_t * src );
     338error_t process_fd_register( xptr_t      file_xp,
     339                             uint32_t  * file_id );
    345340
    346341/*********************************************************************************************
     
    358353
    359354
     355
    360356/********************   Thread Related Operations   *****************************************/
    361357
Note: See TracChangeset for help on using the changeset viewer.