78 | | 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 must be created and initialized in target cluster Y for the child process. |
79 | | The calling thread can run in any cluster. If the target cluster Y is different from the calling thread cluster X, the calling thread must use 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. |
| 78 | 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. |
| 79 | 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. |
82 | 82 | * 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). |
83 | 83 | * 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. |
87 | | Regarding the thread descriptor, a new TRDID must be allocated in cluster Y, and the calling parent thread context (current values stored in the CPU and FPU registers) must be saved in the child thread CPU and FPU contexts, to be restored when the child thread will be selected for execution. |
88 | | Two slots corresponding to two CPU registers must be specifically initialized: |
| 87 | Regarding 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. |
| 88 | Three CPU context slots are not simple copies of the parent value: |
90 | | * the '''stack pointer''' register define the current 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 must be copied to the child kernel stack, and the '''stack pointer''' register cannot have the same value for parent and child. |
91 | | |
| 90 | * 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. |
| 91 | * 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 |
| 92 | register''' cannot have the same value for parent and child. |
98 | | NEW SPECIFICATION |
99 | | |
100 | | After a fork() system call, any thread of the the P process can execute an exec() system call. This system call forces the P process to execute a new application, while keeping the same PID. The P process keep all open files, and the environment variables. The P process reference descriptor must be re-initialised from values found in the .elf file defining the new application. All existing threads of process P must be killed (in all clusters), and a new main thread must be created in the reference cluster. 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. |
101 | | |
102 | | OLD SPECIFICATION (DEPRECATED) |
103 | | |
104 | | 1. The kernel K send an RPC_PROCESS_MIGRATE to cluster Z. The argument are the extended pointer on the C process descriptor in cluster K. |
105 | | 1. To execute this RPC, the kernel Z allocates a new reference process descriptor in cluster Z, and initializes it from informations found in process descriptor in cluster K, using a remote_memcpy(). |
106 | | 1. The kernel Z allocates and initializes from disk the structures contained in the process VMM: GPT(Z,C), VSL(Z,C). |
107 | | 1. The kernel Z creates the main thread associated to process C in cluster Z, initializes it, and register it in the TH_TBL(Z,C). |
108 | | 1. The kernel Z registers this thread in the scheduler of the core selected by the Z kernel and acknowledges the RPC. |
109 | | 1. When receiving the RPC acknowledge, the kernel K destroy the C process descriptor and the associated thread in cluster K, that is not anymore involved in process C execution. |
| 99 | After a fork() system call, any thread of the the P process can execute an exec() system call. This system call forces the P process to execute a new application, while keeping the same PID, |
| 100 | the same parent process, all open file descriptors, and the environment variables. The existing P process descriptors (both the reference and the copies) and all associated threads are 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. |