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开始轮流执行