Expand description
Implementation of process ProcessControlBlock
and task(thread) TaskControlBlock
management mechanism
Here is the entry for task scheduling required by other modules (such as syscall or clock interrupt). By suspending or exiting the current task, you can modify the task state, manage the task queue through TASK_MANAGER (in task/manager.rs) , and switch the control flow through PROCESSOR (in task/processor.rs) .
Be careful when you see __switch
. Control flow around this function
might not be what you expect.
Modules
Implementation of TaskContext
Allocator for pid, task user resource, kernel stack using a simple recycle strategy.
Implementation of TaskManager
Implementation of ProcessControlBlock
Signal flags and function for convert signal flag to integer & string
provides __switch asm function to switch between two task contexts TaskContext
Types related to task management & Functions for completely changing TCB
Structs
Creation of initial process
Kernel stack for a task
A handle to a pid
Signal flags
task context structure containing some registers
Task control block structure
Enums
The execution status of the current process
Constants
The idle task’s pid is 0
Functions
Add init process to the manager
Add a task to ready queue
Make current task blocked and switch to the next task.
Check if the current task has any signal to handle
Add signal to the current task
get the top addr of kernel stack
get current process
Get a copy of the current task
Get the mutable reference to trap context of current task
get the user virtual address of trap context
Get the current user token(addr of page table)
Exit the current ‘Running’ task and run the next task in task list.
Allocate a kernel stack for a task
Get process by pid
Allocate a pid for a process
Remove item(pid, _some_pcb) from PDI2PCB map (called by exit_current_and_run_next)
the inactive(blocked) tasks are removed when the PCB is deallocated.(called by exit_current_and_run_next)
Remove a task from the ready queue
The main part of process execution and scheduling
Loop fetch_task
to get the process that needs to run, and switch the process through __switch
Return to idle control flow for new scheduling
Make current task suspended and switch to the next task
Get current task through take, leaving a None in its place
Wake up a task