Skip to content

Commit 8e775e6

Browse files
Update translated documentation (#1608)
1 parent d80a232 commit 8e775e6

File tree

5 files changed

+206
-27
lines changed

5 files changed

+206
-27
lines changed

docs/.translation_cache.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
"hash": "9a5c0ec57bae0576c30fbab60407f178"
4646
},
4747
"en:kernel/locking/index.rst": {
48-
"hash": "299b0ccecf4ef174fffcce4731a98728"
48+
"hash": "0e0e7cde9860a5e3b0cba2e026a06b51"
4949
},
5050
"en:kernel/sched/index.rst": {
51-
"hash": "cb2834d1e7bde7924e059290a1399f62"
51+
"hash": "261678cb50d23aa9879632de029f60ba"
5252
},
5353
"en:kernel/locking/locks.md": {
54-
"hash": "5514ff361db4677d2b4fa522852aaeea"
54+
"hash": "041e3ace893dcfcb2ecb85ddcc8b0d31"
5555
},
5656
"en:kernel/sched/cfs.md": {
5757
"hash": "7c89ba1c0416ec346f2982b3139cc819"
@@ -355,5 +355,8 @@
355355
},
356356
"en:kernel/locking/rwsem.md": {
357357
"hash": "f19bd3e7ace9536b7e5c49fb4a6163e1"
358+
},
359+
"en:kernel/sched/fifo.md": {
360+
"hash": "7193f93fd9af38c8b7d2ad0ad9453ce5"
358361
}
359362
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.. note:: AI Translation Notice
22

3-
This document was automatically translated by `Qwen/Qwen3-8B` model, for reference only.
3+
This document was automatically translated by `hunyuan-turbos-latest` model, for reference only.
44

55
- Source document: kernel/locking/index.rst
66

7-
- Translation time: 2025-05-19 01:41:08
7+
- Translation time: 2026-01-05 12:00:59
88

9-
- Translation model: `Qwen/Qwen3-8B`
9+
- Translation model: `hunyuan-turbos-latest`
1010

1111

1212
Please report issues via `Community Channel <https://github.com/DragonOS-Community/DragonOS/issues>`_
@@ -15,12 +15,13 @@
1515
Locks
1616
====================================
1717

18-
This is the documentation explaining the lock variables in DragonOS.
18+
This is the documentation for lock variables in DragonOS.
1919

2020
.. toctree::
2121
:maxdepth: 1
2222

2323
locks
2424
spinlock
25-
mutex
2625
rwlock
26+
mutex
27+
rwsem

docs/locales/en/kernel/locking/locks.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
:::{note}
22
**AI Translation Notice**
33

4-
This document was automatically translated by `Qwen/Qwen3-8B` model, for reference only.
4+
This document was automatically translated by `hunyuan-turbos-latest` model, for reference only.
55

66
- Source document: kernel/locking/locks.md
77

8-
- Translation time: 2025-05-19 01:41:26
8+
- Translation time: 2026-01-05 12:01:11
99

10-
- Translation model: `Qwen/Qwen3-8B`
10+
- Translation model: `hunyuan-turbos-latest`
1111

1212
Please report issues via [Community Channel](https://github.com/DragonOS-Community/DragonOS/issues)
1313

@@ -20,43 +20,44 @@ Please report issues via [Community Channel](https://github.com/DragonOS-Communi
2020
&emsp;&emsp;The DragonOS kernel implements several types of locks, which can be broadly categorized into two types:
2121

2222
- Sleepable locks
23-
- Spin locks
23+
- Spinlocks
2424

25-
## Types of Locks
25+
## Lock Types
2626

2727
### Sleepable Locks
2828

29-
&emsp;&emsp;Sleepable locks can only be acquired in a context that is preemptible.
29+
&emsp;&emsp;Sleepable locks can only be acquired in preemptible contexts.
3030

3131
&emsp;&emsp;In DragonOS, the following sleepable locks are implemented:
3232

3333
- semaphore
34+
- rwsem
3435
- mutex_t
3536

36-
### Spin Locks
37+
### Spinlocks
3738

3839
- spinlock_t
3940
- {ref}`RawSpinLock <_spinlock_doc_rawspinlock>` (Rust version of spinlock_t, but incompatible with spinlock_t)
40-
- {ref}`SpinLock <_spinlock_doc_spinlock>` Built on top of RawSpinLock, it wraps a guard, binding the lock and the data it protects into a single structure. This allows for compile-time checks to prevent accessing data without holding the lock.
41+
- {ref}`SpinLock <_spinlock_doc_spinlock>` — Built on RawSpinLock, it encapsulates a Guard layer, binding the lock and the data it protects within a single structure, and prevents accessing data without locking at compile time.
4142

42-
&emsp;&emsp;When a process acquires a spin lock, it changes the lock count in the PCB, thereby implicitly disabling preemption. To provide more flexible operations, spinlock also provides the following methods:
43+
&emsp;&emsp;When a process acquires a spinlock, it modifies the lock variable holding count in the PCB, thereby implicitly disabling preemption. For more flexible operations, spinlocks also provide the following methods:
4344

44-
| Suffix | Description |
45-
|----------------------|--------------------------------------------------------|
46-
| _irq() | Disable interrupts when acquiring the lock, enable them when releasing |
47-
| _irqsave()/_irqrestore() | Save the interrupt state when acquiring the lock, and restore it when releasing |
45+
| Suffix | Description |
46+
| ------------------------ | --------------------------------------------------- |
47+
| _irq() | Disables interrupts when acquiring the lock / Enables interrupts when releasing the lock |
48+
| _irqsave()/_irqrestore() | Saves interrupt state and disables interrupts when acquiring the lock / Restores interrupt state when releasing the lock |
4849

49-
## Detailed Introduction
50+
## Detailed Descriptions
5051

51-
### Detailed Introduction to Spin Locks
52+
### Detailed Description of Spinlocks
5253

53-
&emsp;&emsp;For a detailed introduction to spin locks, please refer to the document: {ref}`自旋锁 <_spinlock_doc>`
54+
&emsp;&emsp;For detailed information about spinlocks, please refer to the document: {ref}`自旋锁 <_spinlock_doc>`
5455

5556
### Semaphore
5657

57-
&emsp;&emsp;A semaphore is implemented based on a counter.
58+
&emsp;&emsp;The semaphore is implemented based on counting.
5859

59-
&emsp;&emsp;When the available resources are insufficient, a process attempting to perform a down operation on the semaphore will be put to sleep until the resources become available.
60+
&emsp;&emsp;When available resources are insufficient, a process attempting to perform a down operation on the semaphore will be put to sleep until resources become available.
6061

6162
### Mutex
6263

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
:::{note}
2+
**AI Translation Notice**
3+
4+
This document was automatically translated by `hunyuan-turbos-latest` model, for reference only.
5+
6+
- Source document: kernel/sched/fifo.md
7+
8+
- Translation time: 2026-01-05 12:01:34
9+
10+
- Translation model: `hunyuan-turbos-latest`
11+
12+
Please report issues via [Community Channel](https://github.com/DragonOS-Community/DragonOS/issues)
13+
14+
:::
15+
16+
# FIFO Scheduler
17+
18+
&emsp;&emsp; The FIFO (First-In-First-Out) scheduler is a real-time scheduling policy implemented in DragonOS. The FIFO scheduler adopts an advanced-first-out scheduling algorithm to provide deterministic scheduling behavior for real-time tasks.
19+
20+
## 1. Design Overview
21+
22+
&emsp;&emsp; The FIFO scheduler is designed for real-time tasks, with the following core characteristics:
23+
24+
1. **No time slice mechanism**: Once a FIFO task obtains the CPU, it will run continuously until it voluntarily releases the CPU or is preempted by a higher-priority task.
25+
2. **Priority scheduling**: Supports 100 priorities from 0 to 99, where a smaller number indicates a higher priority.
26+
3. **Same-priority FIFO**: Tasks with the same priority are executed strictly in the order they enter the queue.
27+
28+
## 2. Data Structures
29+
30+
### 2.1 FifoRunQueue
31+
32+
&emsp;&emsp; `FifoRunQueue` is the run queue of the FIFO scheduler, with one instance maintained per CPU.
33+
34+
```rust
35+
pub struct FifoRunQueue {
36+
queues: Vec<VecDeque<Arc<ProcessControlBlock>>>, // 100个优先级队列
37+
active: u128, // 优先级位图,快速查找最高优先级
38+
nr_running: usize, // 运行队列中的进程数
39+
}
40+
```
41+
42+
**Design Highlights:**
43+
44+
- **Multi-level queues**: Uses 100 `VecDeque` to store processes of different priorities separately.
45+
- **Bitmap optimization**: The `active` field uses a 128-bit bitmap to record which priority queues are non-empty, quickly locating the highest priority through the `trailing_zeros()` instruction.
46+
- **O(1) selection**: Utilizes the bitmap and deque to achieve O(1) time complexity for the `pick_next()` operation.
47+
48+
### 2.2 FifoScheduler
49+
50+
&emsp;&emsp; `FifoScheduler` implements the `Scheduler` trait, providing the core logic of the FIFO scheduling policy.
51+
52+
## 3. Implemented Features
53+
54+
### 3.1 Basic Scheduling Operations
55+
56+
| Function | Functionality | Implementation Status |
57+
|----------|---------------|-----------------------|
58+
| `enqueue()` | Add a process to the scheduling queue | ✅ Implemented |
59+
| `dequeue()` | Remove a process from the scheduling queue | ✅ Implemented |
60+
| `pick_next_task()` | Select the next process to execute | ✅ Implemented |
61+
| `yield_task()` | Current process voluntarily yields the CPU | ✅ Implemented |
62+
63+
### 3.2 Preemption Mechanism
64+
65+
**check_preempt_currnet()**: When a new process is awakened, check whether the current process needs to be preempted.
66+
- If the new process has a higher priority, trigger preemption.
67+
- Supports preemption between real-time tasks and normal tasks.
68+
69+
**tick()**: Clock interrupt handling.
70+
- Check whether a higher-priority task has entered the queue.
71+
- If so, trigger rescheduling.
72+
73+
### 3.3 Scheduling Priority
74+
75+
The FIFO scheduler uses a priority range compatible with Linux:
76+
77+
```rust
78+
pub const MAX_RT_PRIO: i32 = 100; // 实时优先级范围 0-99
79+
```
80+
81+
- Priority 0: Highest priority.
82+
- Priority 99: Lowest real-time priority.
83+
- Priority >=100: Normal processes (CFS scheduling).
84+
85+
### 3.4 Policy Switching
86+
87+
Through the `ProcessManager::set_fifo_policy()` interface, it supports switching kernel threads to the FIFO scheduling policy at runtime:
88+
89+
```rust
90+
pub fn set_fifo_policy(pcb: &Arc<ProcessControlBlock>, prio: i32) -> Result<(), SystemError>
91+
```
92+
93+
This function will:
94+
1. Verify that the process must be a kernel thread (KTHREAD flag).
95+
2. Verify that the priority is within the valid range (0-99).
96+
3. Handle the state change of the process in the run queue.
97+
4. Trigger preemption checks.
98+
99+
## 4. Scheduling Process
100+
101+
### 4.1 Process Enqueue
102+
103+
```
104+
enqueue()
105+
106+
计算进程优先级索引
107+
108+
加入对应优先级队列尾部
109+
110+
更新位图active
111+
112+
nr_running++
113+
```
114+
115+
### 4.2 Selecting the Next Process
116+
117+
```
118+
pick_next_task()
119+
120+
从位图获取最高优先级(trailing_zeros
121+
122+
返回该优先级队列队首进程
123+
```
124+
125+
### 4.3 Preemption Judgment
126+
127+
```
128+
新进程唤醒 / 时钟中断
129+
130+
获取当前进程和新进程优先级
131+
132+
if (新进程优先级 < 当前进程优先级): // 数字越小优先级越高
133+
134+
设置重调度标志
135+
```
136+
137+
## 5. Demo Functionality
138+
139+
&emsp;&emsp; The demo functionality can be enabled through the `fifo_demo` feature (`kernel/src/sched/fifo_demo.rs`), which creates a FIFO-scheduled kernel thread:
140+
- Sets CPU affinity to Core 0.
141+
- Sets the FIFO scheduling policy with priority 50.
142+
- Outputs a log every 5 seconds.
143+
144+
Enabling method: Add the feature in `Cargo.toml` and call `fifo_demo_init()`.
145+
146+
## 6. TODO
147+
148+
### 6.1 Multi-core Support
149+
150+
- [ ] Implement FIFO task load balancing between multiple CPUs.
151+
- [ ] Support setting and migrating CPU affinity for tasks.
152+
153+
### 6.2 Scheduling Enhancements
154+
155+
- [ ] Implement the SCHED_RR (round-robin) scheduling policy.
156+
- [ ] Support dynamic priority adjustment.
157+
- [ ] Add scheduling latency statistics and monitoring.
158+
159+
### 6.3 Real-time Guarantees
160+
161+
- [ ] Implement real-time task bandwidth limits.
162+
- [ ] Add priority inheritance mechanism (to prevent priority inversion).
163+
- [ ] Support EDF (Earliest Deadline First) scheduling policy.
164+
165+
### 6.4 User-space Interface
166+
167+
- [ ] Implement the `sched_setscheduler` system call.
168+
169+
### 6.5 Optimization and Debugging
170+
171+
- [ ] Add debugging information output for the FIFO scheduler.
172+
- [ ] Implement a scheduling latency monitoring interface.
173+
- [ ] Optimize bitmap operations to support more priority levels.

docs/locales/en/kernel/sched/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Source document: kernel/sched/index.rst
66

7-
- Translation time: 2025-12-10 06:04:46
7+
- Translation time: 2026-01-05 12:00:59
88

99
- Translation model: `hunyuan-turbos-latest`
1010

@@ -22,6 +22,7 @@ DragonOS Scheduling
2222

2323
core
2424
cfs
25+
fifo
2526
rt
2627
kernel_timer
2728
wait_queue

0 commit comments

Comments
 (0)