Skip to content

Commit

Permalink
wip(lab/4): add note for io buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Feb 24, 2024
1 parent 37be300 commit d62fb0c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/labs/0x04/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ int _start() {

为了在系统调用中实现基础的读写操作,代码中定义了一个 `Resource` 枚举,并借用 Linux 中“文件描述符”的类似概念,将其存储在进程信息中。

!!! note "缓冲区与系统调用开销"

为了简化实验,这里的实现并不需要考虑 I/O 缓冲区和批处理的问题。但是在实际的操作系统中,这些考量对性能非常重要。

在 libc 中,数据在用户态被累积起来,在达到一定数量后,通过一次系统调用进行处理(flush)—— 相较于 1024 次系统调用、每次输出一个字符的总开销,显然具有缓冲区之后的开销更小。

`src/proc/data.rs` 中,修改 `ProcessData` 结构体,类似于环境变量的定义,添加一个“文件描述符表”:

```rust
Expand Down Expand Up @@ -701,7 +707,7 @@ pub fn syscall3(n: Syscall, arg0: usize, arg1: usize, arg2: usize) -> usize {
3. 对用户输入的等待行为应当在用户态程序中实现,并应该提供非阻塞的读取方式。
4. 对于一个固定的输入序列,需要特殊处理控制字符,如回车、退格等。这些处理需要在用户态进行,并通过 `write` 系统调用进行反馈输出。
5. 在用户态需要控制好缓冲区的大小,遵守系统调用返回的长度进行处理。
6. 使用 `from_raw_parts_mut` 将用户程序的缓冲区转换为 `&mut [u8]`
6. 可以使用 `from_raw_parts_mut` 将用户程序的缓冲区转换为 `&mut [u8]`

### 进程的退出

Expand Down Expand Up @@ -791,9 +797,7 @@ pub fn still_alive(pid: ProcessId) -> bool {
}
```

对于具体的进程操作、目录操作等功能,将会移步到用户态程序进行实现。为了给予用户态程序操作进程、等待进程退出的能力,这里还缺少最后两个系统调用需要实现:`spawn``waitpid`

对这两个系统调用有如下约定:
对于具体的进程操作、目录操作等功能,将会移步到用户态程序进行实现。为了给予用户态程序操作进程、等待进程退出的能力,这里还缺少最后两个系统调用需要实现:`spawn``waitpid`,对这两个系统调用有如下约定:

```rust
// path: &str (arg0 as *const u8, arg1 as len) -> pid: u16
Expand Down

0 comments on commit d62fb0c

Please sign in to comment.