第8章 调度:多级反馈队列

Homework:

    This program, mlfq.py, allows you to see how the MLFQ scheduler presented in this chapter behaves. See the README for details.

#作者源码有一个bug
job[j]['ticksLeft'] = allotment[hiQueue] #249行是这样写的

#应该改为如下
job[j]['ticksLeft'] = quantum[hiQueue]

Questions:

1. Run a few randomly-generated problems with just two jobs and two queues; compute the MLFQ execution trace for each. Make your life easier by limiting the length of each job and turning off I/Os.

python mlfq.py -j 2 -n 2 -l 0,100,0:0,100,0 -c

2.How would you run the scheduler to reproduce each of the examples in the chapter?

Figure 8.2: Long-running Job Over Time

python mlfq.py -j 1 -n 3 -l 0,200,0 -c

Figure 8.3: Along Came An Interactive Job

python mlfq.py -j 2 -n 3 -l 0,200,0:100,20,0 -c 

Figure 8.4: A Mixed I/O-intensive and CPU-intensive Workload

python mlfq.py -j 2 -n 3 -l 0,200,0:50,17,1 -i 9 -S -c

Figure 8.5: Without (Left) Priority Boost 

python mlfq.py -j 3 -n 3 -l 0,200,0:100,50,5:100,50,5 -i 5 -S -c

With (Right) Priority Boost

python mlfq.py -j 3 -n 3 -l 0,150,0:100,50,5:100,50,5 -q 10 -i 5 -S -B 50 -c

Figure 8.6: Without (Left) Gaming Tolerance

python mlfq.py -j 2 -n 3 -l 0,200,0:50,100,9 -i 1 -S -c

 With (Right) Gaming Tolerance

python mlfq.py -j 2 -n 3 -l 0,200,0:50,100,9 -i 1 -c

Figure 8.7: Lower Priority, Longer Quanta

python mlfq.py -j 2 -n 3 -l 0,200,0:0,200,0 -Q 10,20,40 -c

3. How would you configure the scheduler parameters to behave just like a round-robin scheduler?

当只有一个队列时

python mlfq.py -j 3 -n 1 -l 0,50,0:0,50,0:0,50,0 -c

4. Craft a workload with two jobs and scheduler parameters so that one job takes advantage of the older Rules 4a and 4b (turned on with the -S flag) to game the scheduler and obtain 99% of the CPU over a particular time interval.

python mlfq.py -j 2 -n 3 -l 0,1000,0:0,1000,99 -i 1 -q 100 -S -c

5. Given a system with a quantum length of 10 ms in its highest queue, how often would you have to boost jobs back to the highest priority level (with the -B flag) in order to guarantee that a single long running (and potentially-starving) job gets at least 5% of the CPU?

设置每200ms有一个优先级提升

python mlfq.py -j 3 -n 3 -l 0,1500,0:300,1000,5:300,1000,5 -q 10 -i 5 -S -B 200 -c

6. One question that arises in scheduling is which end of a queue to add a job that just finished I/O; the -I flag changes this behavior for this scheduling simulator. Play around with some workloads and see if you can see the effect of this flag

python mlfq.py -j 3 -n 3 -l 0,30,5:0,50,5:0,50,5 -S -c

python mlfq.py -j 3 -n 3 -l 0,30,5:0,50,5:0,50,5 -S -I -c

如果没有-I,则0,1,2三个job轮流执行,说明刚完成I/O作业的job添加到队尾

而如果有-I,则job0和job1轮流执行,job2没有机会执行,直到job0执行完,job1和job2开始轮流执行 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
多级反馈队列调度算法是一种常见的进程调度算法,它将进程按照优先级划分为多个队列,并且每个队列都有一个时间片大小,优先级高的队列时间片小,优先级低的队列时间片大。当一个进程进入队列时,它被放置在最高优先级的队列中,如果它在该队列中运行完了时间片,但是还没有完成,则它会被移到下一个优先级的队列中,以此类推,直到完成或者到达最低优先级的队列。 下面是一个简单的多级反馈队列调度算法的C++实现: ```c++ #include <iostream> #include <queue> using namespace std; struct Process { int pid; // 进程ID int priority; // 进程优先级 int burst_time; // 进程执行时间 }; int main() { // 创建5个队列 queue<Process> q0, q1, q2, q3, q4; // 初始化进程 Process p1 = {1, 0, 8}; Process p2 = {2, 1, 10}; Process p3 = {3, 2, 6}; Process p4 = {4, 3, 4}; Process p5 = {5, 4, 2}; // 将进程放入第0个队列 q0.push(p1); q0.push(p2); q0.push(p3); q0.push(p4); q0.push(p5); // 模拟调度过程 int time = 0; while (!q0.empty() || !q1.empty() || !q2.empty() || !q3.empty() || !q4.empty()) { if (!q0.empty()) { Process p = q0.front(); q0.pop(); cout << "Time " << time << ": Running process " << p.pid << " in queue 0" << endl; p.burst_time -= 1; time += 1; if (p.burst_time > 0) { q1.push(p); } } else if (!q1.empty()) { Process p = q1.front(); q1.pop(); cout << "Time " << time << ": Running process " << p.pid << " in queue 1" << endl; p.burst_time -= 1; time += 2; if (p.burst_time > 0) { q2.push(p); } } else if (!q2.empty()) { Process p = q2.front(); q2.pop(); cout << "Time " << time << ": Running process " << p.pid << " in queue 2" << endl; p.burst_time -= 1; time += 4; if (p.burst_time > 0) { q3.push(p); } } else if (!q3.empty()) { Process p = q3.front(); q3.pop(); cout << "Time " << time << ": Running process " << p.pid << " in queue 3" << endl; p.burst_time -= 1; time += 8; if (p.burst_time > 0) { q4.push(p); } } else if (!q4.empty()) { Process p = q4.front(); q4.pop(); cout << "Time " << time << ": Running process " << p.pid << " in queue 4" << endl; p.burst_time -= 1; time += 16; } } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值