Expand description
Task management implementation
Everything about task management, like starting and switching tasks is implemented here.
A single global instance of TaskManager
called TASK_MANAGER
controls
all the tasks in the whole operating system.
A single global instance of Processor
called PROCESSOR
monitors running
task(s) for each core.
A single global instance of PidAllocator
called PID_ALLOCATOR
allocates
pid for user apps.
Be careful when you see __switch
ASM function in switch.S
. Control flow around this function
might not be what you expect.
Modules§
- context 🔒
- Implementation of
TaskContext
- manager 🔒
- Implementation of
TaskManager
- pid 🔒
- Implementation of
PidAllocator
- processor 🔒
- Implementation of
Processor
and Intersection of control flow - switch 🔒
- Wrap
switch.S
as a function - task 🔒
- Implementation of
TaskControlBlock
Structs§
- INITPROC
- Globle process that init user shell
- Kernel
Stack - Kernelstack for app
- PidAllocator
- Pid Allocator struct
- PidHandle
- Bind pid lifetime to
PidHandle
- Processor
- Processor management structure
- Task
Context - task context structure containing some registers
- Task
Manager - A array of
TaskControlBlock
that is thread-safe
Constants§
- IDLE_
PID - pid of usertests app in make run TEST=1
Functions§
- add_
initproc - Add init process to the manager
- add_
task - Interface offered to add task
- current_
task - Get running task
- current_
trap_ cx - Get the mutable reference to trap context of current task
- current_
user_ token - Get token of the address space of current task
- exit_
current_ and_ run_ next - Exit the current ‘Running’ task and run the next task in task list.
- fetch_
task - Interface offered to pop the first task
- pid_
alloc - Allocate a pid from PID_ALLOCATOR
- run_
tasks - 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
- schedule
- Return to idle control flow for new scheduling
- suspend_
current_ and_ run_ next - Suspend the current ‘Running’ task and run the next task in task list.
- take_
current_ task - Take the current task,leaving a None in its place