Chapter 3
Introduction
We need to place multiple app to multiple memory address to run app in cycle. Rather run once and clear for next.
First We want to place each app to each isolated addr, due to our kernel restriction, we need to load it with build.py
.
Task
Task: a workflow process
Define every time slice of Task as Task Slice
Define the switch between app as Task switching
We need to store Task Context
Design:
We will store these register in ctx:
1 | // os/src/task/context.rs |
1 | .altmacro |
Expose to Rust
1 | // os/src/task/switch.rs |
We will design TaskManager
:
- Store each App state array and current running app.
- each state store
TaskContext
andTaskState
for running or exited etc… - Init and ready by store the
__restore
ctx toTaskContext
- Run for switch cx if needed.
1 | let current_task_cx_ptr = &mut inner.tasks[current].task_cx as *mut TaskContext; |
Dispatch Design
Collaboration
Manually design interface yield
for App to use
1 | pub fn sys_yield() -> isize { |
But it can be inefficient for some case that app already done its work but reluctant to exit.
Preemptive
We will design interrupt clock in a fixed time bound to force switch between app.
- Set timer design and get time
- Set timer for trigger
- enable timer and handle the interrupt cause of Timer in
ecall
You should know this as a pre-knowledge:
1 | const SBI_SET_TIMER: usize = 0; |