Changes between Version 101 and Version 102 of processus_thread


Ignore:
Timestamp:
Jun 26, 2018, 1:41:44 PM (3 years ago)
Author:
nicolas.van.phan@…
Comment:

Fix typos

Legend:

Unmodified
Added
Removed
Modified
  • processus_thread

    v101 v102  
    1010The PID (Process Identifier) is coded on 32 bits. It is unique in the system, and has a fixed format:  The 16 MSB (CXY) contain the owner cluster identifier. The  16 LSB bits (LPID) contain the local process index in owner cluster. The '''owner cluster''' is therefore defined by the 16 MSB bits of PID.
    1111
    12 As it exists several copies of the process descriptors, ALMOS-MKH defines a reference process descriptor, located in the '''reference cluster'''. The other copies are used as local caches, and ALMOS-MKH must guaranty the coherence between the reference and the copies.
     12Since there are several copies of the process descriptors, ALMOS-MKH defines a reference process descriptor, located in the '''reference cluster'''. The other copies are used as local caches, and ALMOS-MKH must guaranty the coherence between the reference and the copies.
    1313
    1414As ALMOS-MKH supports process migration, the '''reference cluster''' can be different from the '''owner cluster'''. The '''owner cluster''' cannot change (because the PID is fixed), but the '''reference cluster''' can change in case of process migration.
     
    3939- '''CHILDREN_ROOT''' : root of global list of children process.
    4040
    41 All elements of a ''local'' list are in the same cluster, and ALMOS-MKH uses local pointers. Elements of a ''global'' list can be distributed on all clusters, and ALMOS-MKH uses extended pointers. 
     41All elements of a ''local'' list are in the same cluster, so ALMOS-MKH uses local pointers. Elements of a ''global'' list can be distributed on all clusters, so ALMOS-MKH uses extended pointers. 
    4242
    4343== __2) Thread definition__ ==
     
    4646 * one '''USR''' thread is created by a pthread_create() system call.
    4747 * one '''DEV''' thread is created by the kernel to execute all I/O operations for a given channel device.
    48  * one '''RPC''' thread is activated by the kernel to execute pending RPC requests in the local RPC fifo.
     48 * one '''RPC''' thread is activated by the kernel to execute pending RPC requests in the local RPC FIFO.
    4949 * the  '''IDL''' thread is executed when there is no other thread to execute on a core.
    5050
     
    5353In a given process, a thread is identified by a fixed format TRDID kernel identifier, coded on 32 bits : The 16 MSB bits (CXY) define the cluster K where the thread has been created. The 16 LSB bits (LTID) define the thread local index in the local TH_TBL[K,P] of a process descriptor P in a cluster K. This LTID index is allocated by the local process descriptor when the thread is created.
    5454
    55 Therefore, the TH_TBL(K,P) thread table for a given process in a given clusters contains only the threads of P placed in cluster K. The set of all threads of a given process is defined by the union of all TH_TBL(K,P) for all active clusters K.
    56 To scan the set off all threads of a process P, ALMOS-MKH traverse the COPIES_LIST of all process_descriptors associated to P process.
     55Therefore, the TH_TBL(K,P) thread table for a given process in a given cluster contains only the threads of P placed in cluster K. The set of all threads of a given process is defined by the union of all TH_TBL(K,P) for all active clusters K.
     56To scan the set of all threads of a process P, ALMOS-MKH traverses the COPIES_LIST of all process_descriptors associated to P process.
    5757
    58 This implementation of ALMOS-MKH does not support thread migration: a thread is pinned on a given core in a given cluster. In the future process migration mechanism, all threads of given process in a given cluster can migrate to another cluster for load balancing. This mechanism is not implemented yet (february 2018), and will require to distinguish the kernel thread identifier (TRDID, that will be modified by a migration), and the user thread identifier (THREAD, that cannot be modified by a migration). In the current implementation, the user identifier (returned by the pthread_create() sys call), is identical to the kernel identifier.
     58This implementation of ALMOS-MKH does not support thread migration: a thread is pinned on a given core in a given cluster. In the future process migration mechanism, all threads of given process in a given cluster can migrate to another cluster for load balancing. This mechanism is not implemented yet (february 2018), and will require to distinguish the kernel thread identifier (TRDID, that will be modified by a migration), and the user thread identifier (THREAD, that cannot be modified by a migration). In the current implementation, the user identifier (returned by the pthread_create() sys call) is identical to the kernel identifier.
    5959
    6060You can find below a partial list of information stored in a thread descriptor ([https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/thread.h thread_t] in ALMOS-MKH):
     
    7676== __3) Process creation__ ==
    7777
    78 The process creation in a remote cluster implement the POSIX fork() / exec()  mechanism.
     78The process creation in a remote cluster implements the POSIX fork() / exec()  mechanism.
    7979When a parent process P executes the fork() system call, a new child process C is created.
    80 The new C process inherit from the parent process P the open files (FDT), and the memory image (VSL and GPT). These structures must be replicated in the new process descriptor. After a fork(), the C process can execute an exec() system call, that allocate a new memory image to the C process, but the new process can also continue to execute with the inherited memory image. For load balancing, ALMOS-MKH uses the DQDT to create the child process C on a different cluster from the parent cluster P, but the user application can also use the non-standard fork_place() system call to specify the target cluster.
     80The new C process inherits (from the parent process P) the open files (FDT), and the memory image (VSL and GPT). These structures must be replicated in the new process descriptor. After a fork(), the C process can execute an exec() system call, that allocates a new memory image to the C process, but the new process can also continue to execute with the inherited memory image. For load balancing, ALMOS-MKH uses the DQDT to create the child process C on a different cluster from the parent cluster P, but the user application can also use the non-standard fork_place() system call to specify the target cluster.
    8181
    8282=== 3.1) fork() ===
     
    8484See [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_fork.c sys_fork.c].
    8585
    86 The fork() system call is the only method to create a new process. A thread of parent process P, running in a cluster X,  executes the fork() system call to create a child process C on a remote cluster Y, that will  become both the owner and the reference cluster for the C process. A new process descriptor, and a new thread descriptor are created and initialized in target cluster Y for the child process.
    87 The calling thread  can run in any cluster. If the target cluster Y is different from the calling thread cluster X, the calling thread uses a RPC to ask the target cluster Y to do the work, because only the target cluster Y can allocate memory for the new process and thread descriptor.
     86The fork() system call is the only method to create a new process. A thread of parent process P, running in a cluster X,  executes the fork() system call to create a child process C on a remote cluster Y, that will  become both the owner and the reference cluster for the C process. A new process descriptor and a new thread descriptor are created and initialized in target cluster Y for the child process.
     87The calling thread can run in any cluster. If the target cluster Y is different from the calling thread cluster X, the calling thread uses a RPC to ask the target cluster Y to do the work, because only the target cluster Y can allocate memory for the new process and thread descriptor.
    8888
    89 Regarding the process descriptor, a new PID is allocated in cluster Y.  The child process C inherit the vsegs registered in the parent process reference VSL, but the ALMOS-MKH replication policy depends on the vseg type:
     89Regarding the process descriptor, a new PID is allocated in cluster Y.  The child process C inherits the vsegs registered in the parent process reference VSL, but the ALMOS-MKH replication policy depends on the vseg type:
    9090 * for the '''DATA, MMAP, REMOTE''' vsegs (containing shared, non replicated data), all vsegs registered in the parent reference VSL(Z,P) are registered in the child  reference VSL(Y,C), and all valid GPT entries in the reference parent GPT(Z,P) are copied in the child reference GPT(Y,C). For all pages, the WRITABLE flag is reset and the COW flag is set, in both (parent and child) GPTs. This require to update all corresponding entries in the parent GPT copies (in clusters other than the reference).
    9191 * for the '''STACK''' vsegs (that are private), only one vseg is registered in the child reference VSL(Y,C). This vseg contains the user stack of the user thread requesting the fork, running in cluster X. All valid GPT entries in the parent GPT(X,P) are copied in the child GPT(Y,C). For all pages, the WRITABLE flag is reset and the COW flag is set, in both (client and child) GPTs.
    92  * for the '''CODE''' vsegs (that must be replicated in all clusters containing a thread), all vsegs registered in the reference parent VSL(Z,P) are registered in the child  reference VSL(Y,C), but the reference child GPT(Y,C) is not updated by the fork: It will be dynamically updated on demand in case of page fault. 
    93  * for the '''FILE''' vsegs (containing shared memory mapped files), all vsegs registered in the reference parent VSL(Z,P) are registered in the child  reference VSL(Y,C), and all valid entries registered in the reference parent GPT(Z,P) are copied in the reference child GPT(Y,C). The COW flag is not set for these shared data.
     92 * for the '''CODE''' vsegs (that must be replicated in all clusters containing a thread), all vsegs registered in the reference parent VSL(Z,P) are registered in the child reference VSL(Y,C), but the reference child GPT(Y,C) is not updated by the fork: It will be dynamically updated on demand in cases of page fault. 
     93 * for the '''FILE''' vsegs (containing shared memory mapped files), all vsegs registered in the reference parent VSL(Z,P) are registered in the child reference VSL(Y,C), and all valid entries registered in the reference parent GPT(Z,P) are copied in the reference child GPT(Y,C). The COW flag is not set for these shared data.
    9494
    9595Regarding the thread descriptor, a new TRDID is allocated in cluster Y, and the calling parent thread context (current values stored in the CPU and FPU registers) is saved in the child thread CPU and FPU contexts, to be restored when the child thread will be selected for execution.
    9696Three CPU context slots are not simple copies of the parent value:
    9797 * the '''thread pointer''' register contains the current thread descriptor address. This '''thread pointer''' register cannot have the same value for parent and child.   
    98  * the '''stack pointer''' register contains the current pointer on the kernel stack. ALMOS-MKH uses a specific kernel stack when an user thread enters the kernel, and this kernel stack is implemented in the thread descriptor. As parent and child cannot use the same kernel stack, the parent kernel stack content is copied to the child kernel stack, and the '''stack pointer''' register cannot have the same value for parent and child.
     98 * the '''stack pointer''' register contains the current pointer on the kernel stack. ALMOS-MKH uses a specific kernel stack when a user thread enters the kernel, and this kernel stack is implemented in the thread descriptor. As parent and child cannot use the same kernel stack, the parent kernel stack content is copied to the child kernel stack, and the '''stack pointer''' register cannot have the same value for parent and child.
    9999 * the '''page table pointer''' register contains the physical base address of the current generic page table. As the child GPT is a copy of the parent GPT in the child cluster, this '''page table register''' cannot have the same value for parent and child.
    100100
    101 At the end of the fork(), cluster Y is both the owner cluster and the reference cluster for the new  C process, that contains one single thread running in the Y cluster.
    102 All pages of DATA, REMOTE, and MMAP vsegs are marked ''Copy On Write'' in the child C process GPT (clusters Y), and in all copies of the parent P process GPT (all clusters containing a copy of P). 
     101At the end of the fork(), cluster Y is both the owner cluster and the reference cluster for the new C process, that contains one single thread running in the Y cluster.
     102All pages of DATA, REMOTE, and MMAP vsegs are marked ''Copy On Write'' in the child C process GPT (cluster Y), and in all copies of the parent P process GPT (all clusters containing a copy of P).
    103103
    104104=== 3.2) exec() ===
     
    106106See [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_exec.c sys_exec.c]
    107107
    108 After a fork() system call, any thread of a process P can execute an exec() system call. This system call forces the P process to execute a new application, while keeping the same PID, the same parent process, the same open file descriptors, and the same environment variables. The existing P process descriptors (both the reference and the copies)  and all associated threads will be destroyed. A new process descriptor and a new main thread descriptor are created in the reference cluster, and initialized from values found in the existing process descriptor, and from values contained in the .elf file defining the new application. The calling thread can run in any cluster. If the reference cluster Z for process P is different from the calling thread cluster X, the calling thread must use a RPC to ask the reference cluster Z to do the work.
     108After a fork() system call, any thread of a process P can execute an exec() system call. This system call forces the P process to execute a new application, while keeping the same PID, the same parent process, the same open file descriptors, and the same environment variables. The existing P process descriptors (both the reference and the copies) and all associated threads will be destroyed. A new process descriptor and a new main thread descriptor are created in the reference cluster, and initialized from values found in the existing process descriptor, and from values contained in the .elf file defining the new application. The calling thread can run in any cluster. If the reference cluster Z for process P is different from the calling thread cluster X, the calling thread must use a RPC to ask the reference cluster Z to do the work.
    109109
    110 At the end of the exec() system call, the cluster Z is both the owner and the reference cluster for process C, that contains one single thread in cluster Z.
     110At the end of the exec() system call, the cluster Z is both the owner and the reference cluster for process C, the latter of which contains one single thread in cluster Z.
    111111
    112112== __4) Thread creation__ ==
     
    118118 * The target core in cluster K' can be specified by the user application, using the CORE_LID field of the pthread_attr_t argument. If the CORE_LID is not defined by the user, the target core is selected by the target kernel K'.
    119119
    120 If the target cluster K' is different from the client cluster K, the cluster K send a RPC_THREAD_USER_CREATE request to cluster K'. The argument is a complete structure pthread_attr_t (defined in the ''thread.h'' file in ALMOS-MK), containing the PID, the function to execute and its arguments, and optionally, the target cluster and target core. This RPC should return the thread TRDID.
     120If the target cluster K' is different from the client cluster K, the cluster K sends a RPC_THREAD_USER_CREATE request to cluster K'. The argument is a complete structure pthread_attr_t, containing the PID, the function to execute and its arguments, and optionally, the target cluster and target core. This RPC should return the thread TRDID.
    121121
    122  * If the target cluster K' does not contain a copy of the P process descriptor, the kernel K' creates a process descriptor copy from the reference P process descriptor, using a remote_memcpy(), and using the cluster_get_reference_process_from_pid() to get the extended pointer on reference cluster. It allocates memory for the associated structures GPT(M,P), VSL(M,P), FDT(M,P).  These structures being used as read-only caches will be dynamically filled by the page faults. This new process descriptor is registered in the COPIES_LIST and in the LOCAL_LIST.
     122 * If the target cluster K' does not contain a copy of the P process descriptor, the kernel K' creates a process descriptor copy from the reference P process descriptor, using a remote_memcpy(), and using the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/kern/cluster.c#L349 cluster_get_reference_process_from_pid()] to get the extended pointer on reference cluster. It allocates memory for the associated structures GPT(M,P), VSL(M,P), FDT(M,P).  These structures, being used as read-only caches, will be dynamically filled by the page faults. This new process descriptor is registered in the COPIES_LIST and in the LOCAL_LIST.
    123123 * When the local process descriptor is set, the kernel K' select the core that will execute the new thread, allocates a TRDID to this thread, creates the thread descriptor, and registers it in the local process descriptor, and in the selected core scheduler.
    124124
    125125== __5) Thread destruction__ ==
    126126
    127 The destruction of a target thread T can be caused by another thread K, executing  the '''pthread_cancel()''' sys call (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_cancel.c sys_thread_cancel.c]) requesting the target thread T to stop execution. It can be caused by the thread T itself, executing the '''pthread_exit()''' sys call (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_exit.c sys_thread_exit.c]) to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscalls requesting the destruction of all threads of a given process.
     127The destruction of a target thread T can be caused by another thread K, executing  the '''pthread_cancel()''' sys call (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_cancel.c sys_thread_cancel.c]) requesting the target thread T to stop execution. It can be caused by the thread T itself, executing the '''pthread_exit()''' syscall (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_exit.c sys_thread_exit.c]) to suicide. Finally, it can be caused by the ''exit()'' or ''kill()'' syscalls requesting the destruction of all threads of a given process.
    128128
    129 The unique method to destroy a thread is to call the '''thread_kill()''' function, that set the THREAD_FLAG_REQ_DELETE bit in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point.
    130 The scheduler calls the ''thread_destroy()'' function that detach the thread from the scheduler, detach the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The '''thread_kill()''' function can be called by the target thread itself (for an exit), or by another thread (for a kill).
     129The unique method to destroy a thread is to call the '''thread_kill()''' function, that sets the THREAD_FLAG_REQ_DELETE bit in the ''flags'' field of the target thread descriptor. The thread will be asynchronously deleted by the scheduler at the next scheduling point.
     130The scheduler calls the ''thread_destroy()'' function that detaches the thread from the scheduler, detaches the thread from the local process descriptor, and releases the memory allocated to the thread descriptor. The '''thread_kill()''' function can be called by the target thread itself (for an exit), or by another thread (for a kill).
    131131
    132 If the target thread is running in attached mode, the '''thread_kill()''' function synchronize with the joining thread, waiting the actual execution of the pthread_join() (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_join.c sys_thread_join.c]) syscall before marking the target thread for delete.
     132If the target thread is running in attached mode, the '''thread_kill()''' function synchronizes with the joining thread, waiting the actual execution of the pthread_join() syscall (see [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_thread_join.c sys_thread_join.c]) before marking the target thread for delete.
    133133
    134 If the target thread is main thread (i.e. the thread 0 in the process owner cluster) the  '''thread_kill()''' does not mark the target thread for delete, because this must be done by the parent process main thread executing the ''sys_wait()'' syscall (see section [6] below).   
     134If the target thread is the main thread (i.e. the thread 0 in the process owner cluster) the  '''thread_kill()''' does not mark the target thread for delete, because this must be done by the parent process main thread executing the ''sys_wait()'' syscall (see section [6] below).   
    135135
    136 === 5.1) thread running in DETACHED mode ===
     136=== 5.1) Thread running in DETACHED mode ===
    137137
    138138The scenario is rather simple when the target thread T is not running in ATTACHED mode.
    139 The killer thread (that can be the target thread itself for an exit) call the thread_kill() function that does the following actions: 
    140  * the killer thread  sets the THREAD_BLOCKED_GLOBAL bit in the target thread ''blocked'' field,
     139The killer thread (that can be the target thread itself for an exit) calls the thread_kill() function that does the following actions:
     140 * the killer thread sets the THREAD_BLOCKED_GLOBAL bit in the target thread ''blocked'' field,
    141141 * the killer thread sets the THREAD_FLAG_REQ_DELETE bit in the target thread ''flags'' field,
    142142 * the killer thread returns without waiting the actual deletion.
    143143
    144 === 5.2) thread running in ATTACHED mode ===
     144=== 5.2) Thread running in ATTACHED mode ===
    145145
    146 The thread destruction is more complex if the target thread T is running in ATTACHED mode, because another joining thread J, executing the ''pthread_join()'' system call, must be informed of the termination of thread T. As the ''thread_kill()'' function, executed by the killer thread K, and the ''sys_thread_join()'', executed by the joining thread J, can be executed in any order, this requires a "rendez-vous": The first arrived thread blocks and deschedules. It will be unblocked by the other thread.
     146The thread destruction is more complex if the target thread T is running in ATTACHED mode, because another joining thread J, executing the ''pthread_join()'' system call, must be informed of the termination of thread T. As the ''thread_kill()'' function (executed by the killer thread K) and the ''sys_thread_join()'' (executed by the joining thread J) can be executed in any order, this requires a "rendez-vous": The first arrived thread blocks and deschedules. It will be unblocked by the other thread.
    147147
    148148This destruction mechanism can involve three threads: the target thread T, the killer thread K, and the joining thread J:
     
    152152 * Both the killer thread K, executing the thread_kill() function), and the joining thread J, executing the sys_thread_join() function, try to take the ''join_lock'' implemented in the T thread descriptor (the ''join_lock'' in the J thread is not used).
    153153 * The K thread test the FLAG_JOIN_DONE in the T thread descriptor:
    154    * If the FLAG_JOIN_DONE is set, the J thread arrived first and is blocked on the BLOCKED_JOIN condition: the K thread unblock the J thread from the BLOCKED_JOIN condition (using the ''join_xp'' field in the T thread), reset the JOIN_DONE flag in T thread, releases the ''join_lock'' in T thread, and completes the T thread destruction as described in the detached case.
    155    * If the FLAG_JOIN_DONE is not set, the K thread arrived first: the K thread blocks the K thread on the BLOCKED_JOIN condition, set the FLAG_KILL_DONE in the T thread, register the killer thread extended pointer in the T thread ''join_xp'' field, releases the ''join_lock'' in the T thread, and deschedules. It completes the T thread destruction as described in the detached case when it is unblocked by the J thread.
    156  * The J thread test the FLAG_KILL_DONE in the T thread descriptor:
    157    * If the FLAG_KILL_DONE is set, the K thread arrived first and is blocked on the BLOCKED_JOIN condition: the J thread unblocks the killer thread, reset the FLAF_KILL_DONE in the T thread, releases the "join_lock" in T thread, and returns.
    158    * If the FLAG_KILL_DONE is not set, the J thread arrived first: the J thread register its extended pointer in the T thread "join_xp" field, set the FLAG_JOIN_DONE in the T thread, sets the BLOCKED_EXIT bit in the J thread, releases the "join_lock" in the T thread, and deschedules. It simply returns when it is unblocked by the K thread.
     154   * If the FLAG_JOIN_DONE is set, the J thread arrived first and is blocked on the BLOCKED_JOIN condition: the K thread unblocks the J thread from the BLOCKED_JOIN condition (using the ''join_xp'' field in the T thread), reset the JOIN_DONE flag in T thread, releases the ''join_lock'' in T thread, and completes the T thread destruction as described in the detached case.
     155   * If the FLAG_JOIN_DONE is not set, the K thread arrived first: the K thread blocks the K thread on the BLOCKED_JOIN condition, sets the FLAG_KILL_DONE in the T thread, registers the killer thread extended pointer in the T thread ''join_xp'' field, releases the ''join_lock'' in the T thread, and deschedules. It completes the T thread destruction as described in the detached case when it is unblocked by the J thread.
     156 * The J thread tests the FLAG_KILL_DONE in the T thread descriptor:
     157   * If the FLAG_KILL_DONE is set, the K thread arrived first and is blocked on the BLOCKED_JOIN condition: the J thread unblocks the killer thread, resets the FLAG_KILL_DONE in the T thread, releases the "join_lock" in T thread, and returns.
     158   * If the FLAG_KILL_DONE is not set, the J thread arrived first: the J thread registers its extended pointer in the T thread "join_xp" field, set the FLAG_JOIN_DONE in the T thread, sets the BLOCKED_EXIT bit in the J thread, releases the "join_lock" in the T thread, and deschedules. It simply returns when it is unblocked by the K thread.
    159159
    160160== __6) Process destruction__ ==
     
    162162The destruction of a process P can be caused by a [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_exit.c sys_exit()] system call executed by any thread of process P,  or by another process executing the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_kill.c sys_kill(SIGKILL)] system call. It can also be caused by a CtrlC signal typed on the process terminal. In all cases, the work must be done for all process copies in all clusters, using the list of copies rooted in the owner cluster.
    163163
    164 === 6.1) parent / children synchronization
     164=== 6.1) Parent / children synchronization
    165165
    166 The process descriptors copies (other than the process descriptor in owner cluster) are simply deleted by the scheduler when the last thread of a given process in a given cluster is  deleted. The process descriptor copy is removed from the list of copies in the owner process cluster descriptor, and the process copy disappears.
     166The process descriptors copies (other than the process descriptor in owner cluster) are simply deleted by the scheduler when the last thread of a given process in a given cluster is deleted. The process descriptor copy is removed from the list of copies in the owner process cluster descriptor, and the process copy disappears.
    167167
    168 The process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the main thread of the parent process executes the blocking [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_wait.c sys_wait()] system call (in the parent owner cluster). Therefore, the child process in owner cluster cannot be destroyed before the parent calls the sys_wait() function. As the '''sys_wait()''' function, and the '''sys_kill()''' or '''sys_exit()''' function are executed by different threads running in different clusters, this requires a parent/child synchronization. To keep a process descriptor in ''zombi'' state after a sys-kill() or sys_exit(), the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process main thread.  This synchronization uses the '''term_state'''  field in process descriptor, that contains the following informations :
    169  * the PROCESS_FLAG_KILL indicates that a KILL request has been received by the child; 
    170  * the PROCESS_FLAG_EXIT indicates that an EXIT request has been made by the child; 
    171  * the PROCESS_FLAG_BLOCK indicates that a SIGSTOP signal has been received by the child;
    172  * the PROCESS_FLAG_WAIT flag indicates that a WAIT  request from parent has been received by the child.
    173  * moreover, for an exit(),  the exit() argument value is registered in this ''term_state'' field.
     168The process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the main thread of the parent process executes the blocking [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/syscalls/sys_wait.c sys_wait()] system call (in the parent owner cluster). Therefore, the child process in owner cluster cannot be destroyed before the parent calls the sys_wait() function. As the '''sys_wait()''' and the '''sys_kill()''' (or '''sys_exit()''') functions are executed by different threads running in different clusters, this requires a parent/child synchronization. To keep a process descriptor in ''zombie'' state after a sys-kill() or sys_exit(), the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process main thread. This synchronization uses the '''term_state'''  field in process descriptor, that contains the following information :
     169 * The PROCESS_FLAG_KILL indicates that a KILL request has been received by the child; 
     170 * The PROCESS_FLAG_EXIT indicates that an EXIT request has been made by the child; 
     171 * The PROCESS_FLAG_BLOCK indicates that a SIGSTOP signal has been received by the child;
     172 * The PROCESS_FLAG_WAIT flag indicates that a WAIT  request from parent has been received by the child.
     173 * Moreover, for an exit(),  the exit() argument value is registered in this ''term_state'' field.
    174174
    175 The actual deletion of the child owner process descriptor and child main thread are done by the sys_wait() function, executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration the parent main thread scan all children owner descriptors. When it detects that one child terminated, it set the PROCESS_FLAG_WAIT in child owner process descriptor, set the THREAD_FLAG_DELETE in the child main thread, and returns to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() syscall for the other children. When the parent process does not detect a terminated child at the end of an iteration, it deschedules without blocking. 
     175The actual deletion of the child owner process descriptor and child main thread are done by the sys_wait() function, executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration, the parent main thread scans all children owner descriptors. When it detects that one child terminated, it sets the PROCESS_FLAG_WAIT in child owner process descriptor, sets the THREAD_FLAG_DELETE in the child main thread, and returns to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() syscall for the other children. When the parent process does not detect a terminated child at the end of an iteration, it deschedules without blocking. 
    176176
    177177
     
    184184 1. These marked threads will be actually destroyed by the scheduler at the next scheduling point. The remote process descriptor copies are also destroyed by the scheduler when the last thread in remote cluster is destroyed.
    185185 1. The sys_exit() function blocks and marks for delete the calling thread itself, when it is different from the main thread.
    186  1. The sys_exit() function block the main thread, and set the PROCESS_TERM_EXIT flag in owner process descriptor to ask the parent process (sys_wait function) to mark this main thread for delete, and deschedules. The calling thread will be destroyed at the next scheduling point.
    187  1. The main thread, and the owner process descriptor on one hand, the calling thread and the associated process  will be destroyed by the scheduler at the next scheduling point.
     186 1. The sys_exit() function blocks the main thread, and sets the PROCESS_TERM_EXIT flag in owner process descriptor to ask the parent process (sys_wait function) to mark this main thread for delete, and deschedules. The calling thread will be destroyed at the next scheduling point.
     187 1. The main thread, and the owner process descriptor on one hand, the calling thread and the associated process will be destroyed by the scheduler at the next scheduling point.
    188188
    189189=== 6.3) detailed kill scenario ===
     
    191191This section describes the termination of a target process caused by a sys_kill(  SIGKILL ).
    192192 
    193  1. The sys_kill() syscali must be executed by the main thread of the target process, OR by any thread of another process than the target process.
    194  1. The sys_kill() function calls the process_sigaction() function that send a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the target process, to block all process threads, but the main thread. This function returns only when all threads (but the main) are blocked and descheduled.
    195  1. The sys_kill() function calls again the process_sigaction() function that send another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The target process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed.
    196  1. The sys_kill() function set the PROCESS_TERM_KILL flag in the target process descriptor in owner cluster to ask synchronize with its parent process, and returns.
     193 1. The sys_kill() syscall must be executed by the main thread of the target process, OR by any thread of another process than the target process.
     194 1. The sys_kill() function calls the process_sigaction() function that sends a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the target process, to block all process threads, except for the main thread. This function returns only when all threads (but the main) are blocked and descheduled.
     195 1. The sys_kill() function calls again the process_sigaction() function that sends another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The target process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed.
     196 1. The sys_kill() function sets the PROCESS_TERM_KILL flag in the target process descriptor in owner cluster to ask synchronize with its parent process, and returns.
    197197 1. The target process main thread, and the target process descriptor in owner cluster  will be actually destroyed by the scheduler when the parent process sys_wait() function marks this main thread for delete.