os_kernel_lab/related_info/lab5/process-cpuio-homework.md
2015-04-08 11:28:37 +08:00

94 lines
2.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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
- 在命令行如下所示需要说明每进程的行为特征使用CPU ;(2)等待I/O
```
-l PROCESS_LIST, --processlist= X1:Y1,X2:Y2,...
X 是进程的执行指令数;
是执行yield指令进程放弃CPU,进入READY状态的比例(0..100)
是执行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
```