pub fn spawn(
index: usize,
source: Source,
place: usize,
bounds: usize,
spgs: &mut SpawnArgs,
) -> Result<u64, SysError>
native-simulator
nor crate feature stub-syscalls
.Expand description
The parent process calls the Spawn system call, which creates a new process (a child process) that is an independent ckb-vm instance. It’s important to note that the parent process will not be blocked by the child process as a result of this syscall. Note: available after ckb 2nd hardfork.
§Arguments
index
,source
,bounds
andplace
- same as exec.spgs
- spawn arguments.
Returns success or a syscall error.
§Scheduler Algorithm V1
This document describes the design and functionality of a scheduler algorithm, covering process states, system call behavior, message handling, and priority rules. The scheduler manages virtual processes, transitioning them through various states based on operations and interactions, to ensure efficient scheduling.
§Process States
Each process within this scheduler has one of the following six states:
- Runnable: The process is ready to execute.
- Running: The process is running.
- Terminated: The process has completed its execution.
- WaitForRead: The process is waiting for data to be available for it to read.
- WaitForWrite: The process is waiting for another process to read data it wants to write.
- WaitForExit: The process is waiting for another process to exit before it can continue.
§System Calls and State Transitions
Specific system calls are responsible for changing the state of a process within this scheduler:
- spawn: Creates a new process, initializing it in the Runnable state.
- read: Attempts to read data from a file descriptor. If data is unavailable or is less than expected, the process state changes to WaitForRead.
- write: Attempts to write data to a file descriptor. If the operation is blocked due to data needing to be read by another process, the process enters the WaitForWrite state. The process will stay in state WaitForWrite until all data has been consumed.
- wait: Waits for a target process to exit. Once the target process has terminated, the waiting process transitions to Runnable.
§IO Handling and State Recovery
IO handling allows processes in certain states to transition back to Runnable when specific conditions are met:
- A WaitForRead process becomes Runnable once the needed data has been read successfully.
- A WaitForWrite process transitions to Runnable once its data has been successfully read by another process.
§Process Priority
The scheduler assigns incremental IDs to processes, establishing an execution order:
- The root process has an ID of 0.
- When multiple processes are in the Runnable state, the scheduler selects the process with the lowest ID to execute first. This ensures a predictable and fair ordering of execution for processes ready to run. The selected process status is changed to Running, and it continues to run until its status is changed.