Changeset 564 for trunk/kernel/kern/process.h
- Timestamp:
- Oct 4, 2018, 11:47:36 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.h
r527 r564 1 1 /* 2 * process.h - process related management functions2 * process.h - process related functions definition. 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) … … 33 33 #include <xlist.h> 34 34 #include <bits.h> 35 #include <spinlock.h> 35 #include <busylock.h> 36 #include <queuelock.h> 37 #include <remote_queuelock.h> 38 #include <remote_rwlock.h> 36 39 #include <hal_atomic.h> 37 40 #include <vmm.h> … … 69 72 * A free entry in this array contains the XPTR_NULL value. 70 73 * The array size is defined by a the CONFIG_PROCESS_FILE_MAX_NR parameter. 71 * All modifications (open/close) in this structure must be done by the reference cluster, 72 * and reported in process copies. 74 * 75 * NOTE: - Only the fd_array[] in the reference process contains a complete list of open 76 * files, and is protected by the lock against concurrent access. 77 * - the fd_array[] in a process copy is simply a cache containing a subset of the 78 * open files to speed the fdid to xptr translation, but the "lock" and "current 79 * fields should not be used. 80 * - all modifications made by the process_fd_remove() are done in reference cluster 81 * and reported in all process_copies. 73 82 ********************************************************************************************/ 74 83 75 84 typedef struct fd_array_s 76 85 { 77 remote_ spinlock_t lock;/*! lock protecting fd_array */78 uint32_t current;/*! current number of open files */79 xptr_t array[CONFIG_PROCESS_FILE_MAX_NR]; /*! xptr on open file descriptors*/86 remote_queuelock_t lock; /*! lock protecting fd_array */ 87 uint32_t current; /*! current number of open files */ 88 xptr_t array[CONFIG_PROCESS_FILE_MAX_NR]; /*! open file descriptors */ 80 89 } 81 90 fd_array_t; … … 100 109 * complete in the reference process cluster, other copies are read-only caches. 101 110 * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated 102 * <sync_lock>, that aredynamically allocated, are only defined in the reference cluster.111 * <sync_lock>, dynamically allocated, are only defined in the reference cluster. 103 112 * 5) The <children_root>, <children_nr>, <children_list>, and <txt_list> fields are only 104 113 * defined in the reference cluster, and are undefined in other clusters. 105 * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, < th_lock> fields106 * are defined in all process descriptors copies.114 * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, <u_th_lock> or <k_th_lock> fields 115 * are specific n each cluster, and are defined in all process descriptors copies. 107 116 * 7) The termination <flags> and <exit_status> are only defined in the reference cluster. 108 * The term_state format is defined in the shared_syscalls.h file.117 * (The term_state format is defined in the shared_syscalls.h file ). 109 118 ********************************************************************************************/ 110 119 111 120 typedef struct process_s 112 121 { 113 vmm_t vmm; /*! embedded virtual memory manager */ 114 115 fd_array_t fd_array; /*! embedded open file descriptors array */ 116 117 xptr_t vfs_root_xp; /*! extended pointer on current VFS root inode */ 118 xptr_t vfs_bin_xp; /*! extended pointer on .elf file descriptor */ 119 pid_t pid; /*! process identifier */ 120 xptr_t ref_xp; /*! extended pointer on reference process */ 121 xptr_t owner_xp; /*! extended pointer on owner process */ 122 xptr_t parent_xp; /*! extended pointer on parent process */ 123 124 xptr_t vfs_cwd_xp; /*! extended pointer on current working dir inode */ 125 remote_rwlock_t cwd_lock; /*! lock protecting working directory changes */ 126 127 xlist_entry_t children_root; /*! root of the children process xlist */ 128 remote_spinlock_t children_lock; /*! lock protecting children process xlist */ 129 uint32_t children_nr; /*! number of children processes */ 130 131 xlist_entry_t children_list; /*! member of list of children of same parent */ 132 xlist_entry_t local_list; /*! member of list of process in same cluster */ 133 xlist_entry_t copies_list; /*! member of list of copies of same process */ 134 xlist_entry_t txt_list; /*! member of list of processes sharing same TXT */ 135 136 spinlock_t th_lock; /*! lock protecting th_tbl[] concurrent access */ 137 uint32_t th_nr; /*! number of threads in this cluster */ 138 139 struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads */ 140 141 xlist_entry_t sem_root; /*! root of the process semaphore list */ 142 xlist_entry_t mutex_root; /*! root of the process mutex list */ 143 xlist_entry_t barrier_root; /*! root of the process barrier list */ 144 xlist_entry_t condvar_root; /*! root of the process condvar list */ 145 remote_spinlock_t sync_lock; /*! lock protecting sem,mutex,barrier,condvar lists */ 146 147 uint32_t term_state; /*! termination status (flags & exit status) */ 122 vmm_t vmm; /*! embedded virtual memory manager */ 123 124 fd_array_t fd_array; /*! embedded open file descriptors array */ 125 126 xptr_t vfs_root_xp; /*! extended pointer on current VFS root inode */ 127 xptr_t vfs_bin_xp; /*! extended pointer on .elf file descriptor */ 128 pid_t pid; /*! process identifier */ 129 xptr_t ref_xp; /*! extended pointer on reference process */ 130 xptr_t owner_xp; /*! extended pointer on owner process */ 131 xptr_t parent_xp; /*! extended pointer on parent process */ 132 133 xptr_t vfs_cwd_xp; /*! extended pointer on current working dir inode */ 134 remote_rwlock_t cwd_lock; /*! lock protecting working directory changes */ 135 136 xlist_entry_t children_root; /*! root of the children process xlist */ 137 remote_queuelock_t children_lock; /*! lock protecting children process xlist */ 138 uint32_t children_nr; /*! number of children processes */ 139 140 xlist_entry_t children_list; /*! member of list of children of same parent */ 141 xlist_entry_t local_list; /*! member of list of process in same cluster */ 142 xlist_entry_t copies_list; /*! member of list of copies of same process */ 143 xlist_entry_t txt_list; /*! member of list of processes sharing same TXT */ 144 145 struct thread_s * th_tbl[CONFIG_THREADS_MAX_PER_CLUSTER]; /*! local threads */ 146 uint32_t th_nr; /*! number of threads in this cluster */ 147 rwlock_t th_lock; /*! lock protecting th_tbl[] i */ 148 149 xlist_entry_t sem_root; /*! root of the user definedsemaphore list */ 150 xlist_entry_t mutex_root; /*! root of the user defined mutex list */ 151 xlist_entry_t barrier_root; /*! root of the user defined barrier list */ 152 xlist_entry_t condvar_root; /*! root of the user defined condvar list */ 153 remote_queuelock_t sync_lock; /*! lock protecting user defined synchro lists */ 154 155 uint32_t term_state; /*! termination status (flags & exit status) */ 148 156 } 149 157 process_t; … … 210 218 211 219 /********************************************************************************************* 212 * This function initializes a local,reference, user process descriptor from another process213 * descriptor, defined by the <parent_xp> argument. The <process> and <pid> arguments must214 * be previously allocated by the caller. This function can be called by two functions:220 * This function initializes a reference, user process descriptor from another process 221 * descriptor, defined by the <parent_xp> argument. The <process> and <pid> arguments 222 * are previously allocated by the caller. This function can be called by two functions: 215 223 * 1) process_init_create() : process is the INIT process; parent is process-zero. 216 224 * 2) process_make_fork() : the parent process descriptor is generally remote. … … 411 419 412 420 /********************************************************************************************* 413 * This function uses as many remote accesses as required, to reset an entry in fd_array[],414 * in all clusters containing a copy. The entry is identified by the <fdid> argument.415 * This function must be executed by a thread running reference cluster, that contains416 * the complete list of process descriptors copies.417 *********************************************************************************************418 * @ process : pointer on the local process descriptor.419 * @ fdid : file descriptor index in the fd_array.420 ********************************************************************************************/421 void process_fd_remove( process_t * process,422 uint32_t fdid );423 424 /*********************************************************************************************425 * This function returns an extended pointer on a file descriptor identified by its index426 * in fd_array. It can be called by any thread running in any cluster.427 * It accesses first the local process descriptor. In case of local miss, it uses remote428 * access to access the reference process descriptor.429 * It updates the local fd_array when the file descriptor exists in reference cluster.430 * The file descriptor refcount is not incremented.431 *********************************************************************************************432 * @ process : pointer on the local process descriptor.433 * @ fdid : file descriptor index in the fd_array.434 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.435 ********************************************************************************************/436 xptr_t process_fd_get_xptr( process_t * process,437 uint32_t fdid );438 439 /*********************************************************************************************440 * This function checks the number of open files for a given process.441 * It can be called by any thread in any cluster, because it uses portable remote access442 * primitives to access the reference process descriptor.443 *********************************************************************************************444 * @ returns true if file descriptor array full.445 ********************************************************************************************/446 bool_t process_fd_array_full( void );447 448 /*********************************************************************************************449 421 * This function allocates a free slot in the fd_array of the reference process, 450 422 * register the <file_xp> argument in the allocated slot, and return the slot index. 451 423 * It can be called by any thread in any cluster, because it uses portable remote access 452 424 * primitives to access the reference process descriptor. 425 * It takes the lock protecting the reference fd_array against concurrent accesses. 453 426 ********************************************************************************************* 454 427 * @ file_xp : extended pointer on the file descriptor to be registered. … … 459 432 xptr_t file_xp, 460 433 uint32_t * fdid ); 434 435 /********************************************************************************************* 436 * This function uses as many remote accesses as required, to reset an entry in fd_array[], 437 * in all clusters containing a copy. The entry is identified by the <fdid> argument. 438 * This function must be executed by a thread running in reference cluster, that contains 439 * the complete list of process descriptors copies. 440 * It takes the lock protecting the reference fd_array against concurrent accesses. 441 * TODO this function is not implemented yet. 442 ********************************************************************************************* 443 * @ process : pointer on the local process descriptor. 444 * @ fdid : file descriptor index in the fd_array. 445 ********************************************************************************************/ 446 void process_fd_remove( process_t * process, 447 uint32_t fdid ); 448 449 /********************************************************************************************* 450 * This function returns an extended pointer on a file descriptor identified by its index 451 * in fd_array. It can be called by any thread running in any cluster. 452 * It accesses first the local process descriptor. In case of local miss, it takes 453 * the lock protecting the reference fd_array, and access the reference process descriptor. 454 * It updates the local fd_array when the file descriptor exists in reference cluster. 455 * It takes the lock protecting the reference fd_array against concurrent accesses. 456 * The file descriptor refcount is not incremented. 457 ********************************************************************************************* 458 * @ process : pointer on the local process descriptor. 459 * @ fdid : file descriptor index in the fd_array. 460 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found. 461 ********************************************************************************************/ 462 xptr_t process_fd_get_xptr( process_t * process, 463 uint32_t fdid ); 461 464 462 465 /********************************************************************************************* … … 465 468 * <dst_xp> fd_array, embedded in another process descriptor. 466 469 * The calling thread can be running in any cluster. 467 * It takes the remote lock protecting the <src_xp> fd_array during the copy.470 * It takes the lock protecting the reference fd_array against concurrent accesses. 468 471 * For each involved file descriptor, the refcount is incremented. 469 472 ********************************************************************************************* … … 474 477 xptr_t src_xp ); 475 478 479 /********************************************************************************************* 480 * This function checks the current number of open files for a given process. 481 * It can be called by any thread in any cluster, because it uses portable remote access 482 * primitives to access the reference process descriptor. 483 * It does not take the lock protecting the reference fd_array. 484 ********************************************************************************************* 485 * @ returns true if file descriptor array full. 486 ********************************************************************************************/ 487 bool_t process_fd_array_full( void ); 488 476 489 477 490 … … 479 492 480 493 /********************************************************************************************* 481 * This function registers a new thread in the local process descriptor. 482 * It checks that there is an available slot in the local th_tbl[] array, 483 * allocates a new LTID, and registers the new thread in the th_tbl[]. 484 * It takes the lock protecting exclusive access to the th_tbl[]. 494 * This function atomically registers a new thread in the local process descriptor. 495 * It checks that there is an available slot in the local th_tbl[] array, and allocates 496 * a new LTID using the relevant lock depending on the kernel/user type. 485 497 ********************************************************************************************* 486 498 * @ process : pointer on the local process descriptor. … … 494 506 495 507 /********************************************************************************************* 496 * This function removes a thread registration from the local process descriptor.497 * It takes the lock protecting exclusive access to the th_tbl[].508 * This function atomically removes a thread registration from the local process descriptor 509 * th_tbl[] array, using the relevant lock, depending on the kernel/user type. 498 510 ********************************************************************************************* 499 511 * @ thread : local pointer on thread to be removed. … … 541 553 542 554 /********************************************************************************************* 543 * This function gives the TXT ownership to a process identified by the <process_xp> argument. 555 * This function gives a process identified by the <process_xp> argument the exclusive 556 * ownership of its attached TXT_RX terminal (i.e. put the process in foreground). 544 557 * It can be called by a thread running in any cluster, but the <process_xp> must be the 545 558 * owner cluster process descriptor. … … 568 581 * process_xp must be the owner cluster process descriptor. 569 582 ********************************************************************************************* 570 * @ return a non-zero value if target process is TXT owner.571 ********************************************************************************************/ 572 uint32_t process_txt_is_owner( xptr_t process_xp );583 * @ returns true if target process is TXT owner. 584 ********************************************************************************************/ 585 bool_t process_txt_is_owner( xptr_t process_xp ); 573 586 574 587 /*********************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.