第7章 进程调度:介绍 homework详解
实验环境
笔者采用的是Ubuntu22.04的虚拟机。
本次作业需要先通过所学知识手动解题,再按教程运行程序scheduler.py即可。
需要用到cpu-sched文件,先阅读readme文件。
实验内容
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ ./scheduler.py -p SJF -l 200,200,200 -c ARG policy SJF ARG jlist 200,200,200
Here is the job list, with the run time of each job: Job 0 ( length = 200.0 ) Job 1 ( length = 200.0 ) Job 2 ( length = 200.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 200.00 secs ( DONE at 200.00 ) [ time 200 ] Run job 1 for 200.00 secs ( DONE at 400.00 ) [ time 400 ] Run job 2 for 200.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ ./scheduler.py -p FIFO -l 200,200,200 -c ARG policy FIFO ARG jlist 200,200,200
Here is the job list, with the run time of each job: Job 0 ( length = 200.0 ) Job 1 ( length = 200.0 ) Job 2 ( length = 200.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 200.00 secs ( DONE at 200.00 ) [ time 200 ] Run job 1 for 200.00 secs ( DONE at 400.00 ) [ time 400 ] Run job 2 for 200.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
这两个代码块分别是SJF和FIFO调度,因为三个任务长度相等且同时到达,所以它们的响应时间和周转时间相同。
2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ ./scheduler.py -p SJF -l 100,200,300 -c ARG policy SJF ARG jlist 100,200,300
Here is the job list, with the run time of each job: Job 0 ( length = 100.0 ) Job 1 ( length = 200.0 ) Job 2 ( length = 300.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 100.00 secs ( DONE at 100.00 ) [ time 100 ] Run job 1 for 200.00 secs ( DONE at 300.00 ) [ time 300 ] Run job 2 for 300.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ ./scheduler.py -p FIFO -l 100,200,300 -c ARG policy FIFO ARG jlist 100,200,300
Here is the job list, with the run time of each job: Job 0 ( length = 100.0 ) Job 1 ( length = 200.0 ) Job 2 ( length = 300.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 100.00 secs ( DONE at 100.00 ) [ time 100 ] Run job 1 for 200.00 secs ( DONE at 300.00 ) [ time 300 ] Run job 2 for 300.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
因为是按照100,200,300的顺序插入任务的,所以二者调度模式是相同的,如果将100,200,300的顺序交换,结果会产生差异。例如,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ ./scheduler.py -p FIFO -l 200,100,300 -c ARG policy FIFO ARG jlist 200,100,300
Here is the job list, with the run time of each job: Job 0 ( length = 200.0 ) Job 1 ( length = 100.0 ) Job 2 ( length = 300.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 200.00 secs ( DONE at 200.00 ) [ time 200 ] Run job 1 for 100.00 secs ( DONE at 300.00 ) [ time 300 ] Run job 2 for 300.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
响应时间和周转时间都发生了变化。
3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| $ ./scheduler.py -p RR -l 100,200,300 -c ARG policy RR ARG jlist 100,200,300
Here is the job list, with the run time of each job: Job 0 ( length = 100.0 ) Job 1 ( length = 200.0 ) Job 2 ( length = 300.0 )
** Solutions **
Execution trace: [ time 0 ] Run job 0 for 1.00 secs [ time 1 ] Run job 1 for 1.00 secs [ time 2 ] Run job 2 for 1.00 secs [ time 3 ] Run job 0 for 1.00 secs [ time 4 ] Run job 1 for 1.00 secs …… [ time 598 ] Run job 2 for 1.00 secs [ time 599 ] Run job 2 for 1.00 secs ( DONE at 600.00 )
Final statistics: Job 0 Job 1 Job 2
Average
|
采用RR调度程序交换三者顺序也不会有影响了,牺牲了周转时间和等待时间换取了极快的响应时间。
4
当工作负载为长度自小到大升序排列时,二者产生的效果是一样的,其周转时间和等待时间一致。
5
当量子长度大于最大工作负载长度时,二者等效。
6
容易得出结论,工作负载长度增加,其必然会使响应时间增加。
7
量子长度增加,响应时间会随之增加。
当给定N个任务时,假设量子长度为m
-
当每个任务长度都大于m时,其响应时间为
N∑i=1Ni×m=2m(N+1)
-
当每个任务长度都小于m时,其响应时间为总任务长度除以N。