刚刚读了操作《操作系统导论》第七章的内容,在这做一下课后练习题,虽然和考试内容关系不大,但是和课本上的概念还是想通的,读这本书也确实会学习到一些其他的思想和思考方法。
以下内容,属个人看法,可能不对,后期找到标准答案再改。
本章涉及到的一些基本概念:
- 周转时间:任务完成的时间 - 任务到达的时间
- 响应时间:任务第一次被执行的时间 - 任务到达的时间
当然平均周转时间和平均响应时间就不说了。
- Compute the response time and turnaround time when running three jobs of length 200 with the SJF and FIFO schedulers.
准确的来说应该是平均响应时间和平均周转时间。
SJF(短作业优先调度)
响应时间:(0+200+400)/3=200(0 + 200 + 400) / 3 = 200(0+200+400)/3=200
周转时间:(200+400+600)/3=400(200 + 400 + 600) / 3 = 400(200+400+600)/3=400
FIFO(先到先服务FCFS)
响应时间:(0+200+400)/3=200(0 + 200 + 400) / 3 = 200(0+200+400)/3=200
周转时间:(200+400+600)/3=400(200 + 400 + 600) / 3 = 400(200+400+600)/3=400
- Now do the same but with jobs of different lengths: 100, 200, and 300.
SJF(短作业优先调度)
响应时间:(0+100+300)/3≈133.33(0 + 100 + 300) / 3 \approx 133.33(0+100+300)/3≈133.33
周转时间:(100+300+600)/3≈333.33(100 + 300 + 600) / 3 \approx 333.33(100+300+600)/3≈333.33
FIFO(先到先服务FCFS),即使是同时到达,也有先后关系,不用纠结与这一点。
响应时间:(0+100+300)/3≈133.33(0 + 100 + 300) / 3 \approx 133.33(0+100+300)/3≈133.33
周转时间:(100+300+600)/3≈333.33(100 + 300 + 600) / 3 \approx 333.33(100+300+600)/3≈333.33
- Now do the same, but also with the RR scheduler and a time-slice of 1.
时间片为1
响应时间:(0+1+2)/3=1(0 + 1 + 2) / 3 = 1(0+1+2)/3=1
周转时间:(298+400+501)/3≈399.67(298 + 400 + 501) / 3 \approx 399.67(298+400+501)/3≈399.67
显然,使用轮转调度算法显著提高了系统的响应时间,但是周转时间表现的很差。
- For what types of workloads does SJF deliver the same turnaround times as FIFO?
任务按照运行时间的长短进行顺序到达
- For what types of workloads and quantum lengths does SJF deliver the same response times as RR?
任务总是当上一个任务完成后到达或者说一个时间片的长度足以完成一项任务。
- What happens to response time with SJF as job lengths increase? Can you use the simulator to demonstrate the trend?
假设初始三个任务的长度分别为100,200,300,同时到达。
如果任务的时间增长呈线性的话,那么SJF的响应时间也是呈线性增长的。
- What happens to response time with RR as quantum lengths increase? Can you write an equation that gives the worst-case response time, given N job
响应时间是逐渐增加的。
时间片:rrr
时间片按照线性增长,假设为:r=f(x)=k∗x;k>0,x=1,2,...,∞r = f(x) = k*x;k > 0, x = 1,2,...,\inftyr=f(x)=k∗x;k>0,x=1,2,...,∞
N个任务:[N1,N2,...,Nn][N_1, N_2,...,N_n][N1,N2,...,Nn]
N该任务对应的执行时间:[T1,T2,...,T3][T_1, T_2,...,T_3][T1,T2,...,T3]
响应时间:responseTime=∑i=1nr∗(i−1)responseTime=\sum_{i=1}^{n}{r*(i-1)}responseTime=∑i=1nr∗(i−1)
所以响应时间随时间片的增长的函数关系:
f(r)=∑i=1n(r∗(i−1))=n∗(n−1)∗r/2
f(r) = \sum_{i=1}^{n}{(r*(i-1))}=n*(n-1)*r/2
f(r)=i=1∑n(r∗(i−1))=n∗(n−1)∗r/2
从上面的方程中可以看出,随着r的增长,f®也是增长的,但是增长的速度和任务的数量也有关系。
但是我感觉这问题有点奇怪,时间片调度的响应时间应该是平均的,