Module os::task

source · []
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

Globle process that init user shell

Kernelstack for app

Pid Allocator struct

Bind pid lifetime to PidHandle

Processor management structure

task context structure containing some registers

A array of TaskControlBlock that is thread-safe

Functions

Add init process to the manager

Interface offered to add task

Get running task

Get the mutable reference to trap context of current task

Get token of the address space of current task

Exit the current ‘Running’ task and run the next task in task list.

Interface offered to pop the first task

Allocate a pid from PID_ALLOCATOR

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

Suspend the current ‘Running’ task and run the next task in task list.

Take the current task,leaving a None in its place