Skip to content

Commit cabbc02

Browse files
committed
doc(core): introduce the term "boot phase", add a diagram depicting the kernel lifecycle
1 parent e151418 commit cabbc02

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

src/r3_core/doc/system_lifecycle.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
svgbobdoc::transform! { /**
2+
```svgbob,[system_lifecycle]
3+
4+
Main thread
5+
.-----------------------.
6+
| |
7+
| * |
8+
| | |
9+
| v |
10+
Boot phase | Kernel initialization |
11+
| | |
12+
| v |
13+
| Startup hooks |
14+
| "(user code)" |
15+
| | |
16+
'-----------+-----------'
17+
|
18+
- - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - -
19+
|
20+
| For each hardware thread...
21+
|
22+
+<------------------------------.
23+
| |
24+
v |
25+
Determine the next thread |
26+
to execute |
27+
| |
28+
| |
29+
v |
30+
.--------------+--------------+--------------+--- ... |
31+
| | Int. | Int. | |
32+
Task 1 | Task 2 | handler 1 | handler 2 | |
33+
.-----+-----. .-----+-----. .-----+-----. .-----+-----. |
34+
| | | | | | | | | | | | |
35+
| v | | v | | v | | v | |
36+
| User code | | User code | | User code | | User code | |
37+
| | | | | | | | | | | | |
38+
| | | | | | | | | | | | |
39+
'-----+-----' '-----+-----' '-----+-----' '-----+-----' |
40+
| | | | |
41+
'--------------+--------------+--------------+---------'
42+
The thread exiting, preempted, or blocked
43+
or an interrupt taken
44+
```
45+
*/ }

src/r3_core/src/kernel/hook.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use crate::{
1212
/// There are no operations defined for startup hooks, so this type
1313
/// is only used for static configuration.
1414
///
15-
/// Startup hooks execute during the boot process with [CPU Lock] active, after
16-
/// initializing kernel structures and before scheduling the first task.
15+
/// Startup hooks execute during [the boot phase][] with [CPU Lock][] active,
16+
/// after initializing kernel structures and before scheduling the first task.
17+
/// <!-- [ref:startup_hook_cpu_lock_active] -->
1718
///
19+
/// [the boot phase]: crate#threads
1820
/// [CPU Lock]: crate#system-states
1921
///
2022
/// <div class="admonition-follows"></div>

src/r3_core/src/lib.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,17 @@ Like a lock guard of a mutex, CPU Lock can be thought of as something to be “o
256256
257257
# Threads
258258

259-
An **(execution) thread** is a sequence of instructions executed by a processor. There can be multiple threads existing at the same time and the kernel is responsible for deciding which thread to run at any point on a processor (this process is called scheduling). The location in a program where a thread starts execution is called the thread's **entry point function** for the thread. A thread exits when it returns from its entry point function¹ or calls [`exit_task`](crate::kernel::Kernel::exit_task) (valid only for tasks).
259+
An **(execution) thread** is a logical sequence of instructions executed by a processor. There can be multiple threads existing at the same time, and the kernel is responsible for deciding which thread to run at any point on a processor (this process is called scheduling)². The location in a program where a thread starts execution is called the thread's **entry point function** for the thread. A thread exits when it returns from its entry point function¹ or calls [`exit_task`](crate::kernel::Kernel::exit_task) (valid only for tasks).
260260

261-
¹ More precisely, a thread starts execution with a hypothetical function call to the entry point function, and it exits when it returns from this hypothetical function call.
261+
<small> ¹ More precisely, a thread starts execution with a hypothetical function call to the entry point function, and it exits when it returns from this hypothetical function call.</small>
262+
263+
<small> ² The execution of code responsible for scheduling is not considered pertaining to any threads.</small>
262264

263265
The properties of threads such as how and when they are created and whether they can block or not are specific to each thread type.
264266

265-
The initial thread that starts up the kernel is called the **main thread**. This is where the initialization of kernel structures takes place. Additionally, an application can register one or more [**startup hooks**] to execute user code here. <!-- [tag:startup_hook_cpu_lock_active] --> Startup hooks execute with CPU Lock active and *should never deactivate CPU Lock*. The main thread exits when the kernel dispatches the first task.
267+
The initial thread that starts up the kernel is called the **main thread**. The part of the kernel's lifecycle where the main thread executes is called the kernel's **boot phase**, and this is where the initialization of kernel structures takes place. An application can register one or more [**startup hooks**] to execute user code here. <!-- [tag:startup_hook_cpu_lock_active] --> Startup hooks execute with CPU Lock active and *should never deactivate CPU Lock*. The main thread exits, i.e., the boot phase completes when the kernel dispatches the first task and starts multi-tasking. The following diagram depicts the kernel lifecycle during and after the boot phase.
266268

267-
<!-- TODO: It's useful to introduce a term "the boot phase". -->
269+
<span class="center">![system_lifecycle]</span>
268270

269271
[**startup hooks**]: crate::kernel::StartupHook
270272

src/r3_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
)]
5858
#![doc = include_str!("./lib.md")]
5959
#![doc = include_str!("./common.md")]
60+
#![doc = include!("../doc/system_lifecycle.rs")] // `![system_lifecycle]`
6061
#![doc = include!("../doc/trait_binding.rs")] // `![trait_binding]`
6162
#![doc = include!("../doc/static_cfg.rs")] // `![static_cfg]`
6263
#![cfg_attr(

0 commit comments

Comments
 (0)