add process-cpuio-homework.md
This commit is contained in:
parent
87d6923d69
commit
9926671507
93
related_info/lab5/process-cpuio-homework.md
Normal file
93
related_info/lab5/process-cpuio-homework.md
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#lec10 进程/线程控制spoc练习
|
||||||
|
|
||||||
|
## SPOC小组思考题
|
||||||
|
|
||||||
|
(1) (spoc)设计一个简化的进程管理子系统,可以管理并调度如下简化进程.给出了[参考代码](https://github.com/chyyuu/ucore_lab/blob/master/related_info/lab5/process-cpu-cpuio-homework.py),请理解代码,并完成"YOUR CODE"部分的内容. 可2个人一组
|
||||||
|
|
||||||
|
### 进程的状态
|
||||||
|
```
|
||||||
|
- RUNNING - 进程正在使用CPU
|
||||||
|
- READY - 进程可使用CPU
|
||||||
|
- WAIT - 进程等待I/O完成
|
||||||
|
- DONE - 进程结束
|
||||||
|
```
|
||||||
|
|
||||||
|
### 进程的行为
|
||||||
|
```
|
||||||
|
- 使用CPU,
|
||||||
|
- 发出YIELD请求,放弃使用CPU
|
||||||
|
- 发出I/O操作请求,放弃使用CPU
|
||||||
|
```
|
||||||
|
|
||||||
|
### 进程调度
|
||||||
|
- 使用FIFO/FCFS:先来先服务,
|
||||||
|
- 先查找位于proc_info队列的curr_proc元素(当前进程)之后的进程(curr_proc+1..end)是否处于READY态,
|
||||||
|
- 再查找位于proc_info队列的curr_proc元素(当前进程)之前的进程(begin..curr_proc-1)是否处于READY态
|
||||||
|
- 如都没有,继续执行curr_proc直到结束
|
||||||
|
|
||||||
|
### 关键模拟变量
|
||||||
|
- 进程控制块
|
||||||
|
```
|
||||||
|
PROC_CODE = 'code_'
|
||||||
|
PROC_PC = 'pc_'
|
||||||
|
PROC_ID = 'pid_'
|
||||||
|
PROC_STATE = 'proc_state_'
|
||||||
|
```
|
||||||
|
- 当前进程 curr_proc
|
||||||
|
- 进程列表:proc_info是就绪进程的队列(list),
|
||||||
|
- 在命令行(如下所示)需要说明每进程的行为特征:(1)使用CPU ;(2)等待I/O
|
||||||
|
```
|
||||||
|
-l PROCESS_LIST, --processlist= X1:Y1,X2:Y2,...
|
||||||
|
X 是进程的执行指令数;
|
||||||
|
Y是执行yield指令(进程放弃CPU,进入READY状态)的比例(0..100)
|
||||||
|
Z是执行I/O请求指令(进程放弃CPU,进入WAIT状态)的比例(0..100)
|
||||||
|
```
|
||||||
|
- 进程切换行为:系统决定何时(when)切换进程:进程结束或进程发出yield请求
|
||||||
|
|
||||||
|
### 进程执行
|
||||||
|
```
|
||||||
|
instruction_to_execute = self.proc_info[self.curr_proc][PROC_CODE].pop(0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 关键函数
|
||||||
|
- 系统执行过程:run
|
||||||
|
- 执行状态切换函数: move_to_ready/running/done
|
||||||
|
- 调度函数:next_proc
|
||||||
|
|
||||||
|
### 执行实例
|
||||||
|
|
||||||
|
#### 例1
|
||||||
|
```
|
||||||
|
$./process-simulation.py -l 5:30:30,5:40:30 -c
|
||||||
|
Produce a trace of what would happen when you run these processes:
|
||||||
|
Process 0
|
||||||
|
io
|
||||||
|
io
|
||||||
|
yld
|
||||||
|
cpu
|
||||||
|
yld
|
||||||
|
|
||||||
|
Process 1
|
||||||
|
yld
|
||||||
|
io
|
||||||
|
yld
|
||||||
|
yld
|
||||||
|
yld
|
||||||
|
|
||||||
|
Important behaviors:
|
||||||
|
System will switch when the current process is FINISHED or ISSUES AN YIELD or IO
|
||||||
|
Time PID: 0 PID: 1 CPU IOs
|
||||||
|
1 RUN:io READY 1
|
||||||
|
2 WAITING RUN:yld 1 1
|
||||||
|
3 WAITING RUN:io 1 1
|
||||||
|
4 WAITING WAITING 2
|
||||||
|
5 WAITING WAITING 2
|
||||||
|
6* RUN:io WAITING 1 1
|
||||||
|
7 WAITING WAITING 2
|
||||||
|
8* WAITING RUN:yld 1 1
|
||||||
|
9 WAITING RUN:yld 1 1
|
||||||
|
10 WAITING RUN:yld 1 1
|
||||||
|
11* RUN:yld DONE 1
|
||||||
|
12 RUN:cpu DONE 1
|
||||||
|
13 RUN:yld DONE 1
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user