OSTEP Chapter 7: Process Scheduling: Introduction

OSTEP: Process Scheduling: An Introduction

This series mainly completes the after-school homework of Introduction to Operating Systems (Operating Systems: Three Easy Pieces ), and also involves some summaries and insights of each chapter. Most of the questions do not have a standard answer. Students are welcome to find disputes and errors. discuss together.

related resources

Website:http://www.ostep.org/

Homework:https://github.com/remzi-arpacidusseau/ostep-homework/

Column: Introduction to Operating Systems (ostep)

Answers to exercises

This job is scheduler.pycompleted by running.

First use -hthe command to get some usage:

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 scheduler.py -h
Usage: scheduler.py [options]

Options:
  -h, --help            show this help message and exit
  -s SEED, --seed=SEED  the random seed
  -j JOBS, --jobs=JOBS  number of jobs in the system
  -l JLIST, --jlist=JLIST
                        instead of random jobs, provide a comma-separated list
                        of run times
  -m MAXLEN, --maxlen=MAXLEN
                        max length of job
  -p POLICY, --policy=POLICY
                        sched policy to use: SJF, FIFO, RR
  -q QUANTUM, --quantum=QUANTUM
                        length of time slice for RR policy
  -c                    compute answers for me

1.SJF: response times are 0, 200, 400 respectively. The turnaround times are 200, 400, and 600 respectively.

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 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 -- Response: 0.00  Turnaround 200.00  Wait 0.00
  Job   1 -- Response: 200.00  Turnaround 400.00  Wait 200.00
  Job   2 -- Response: 400.00  Turnaround 600.00  Wait 400.00

FIFO: response times are 0, 200, 400 respectively. The turnaround times are 200, 400, and 600 respectively.

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 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 -- Response: 0.00  Turnaround 200.00  Wait 0.00
  Job   1 -- Response: 200.00  Turnaround 400.00  Wait 200.00
  Job   2 -- Response: 400.00  Turnaround 600.00  Wait 400.00

  Average -- Response: 200.00  Turnaround 400.00  Wait 200.00

For this question, the scheduling order of these two scheduling methods is the same, so the results are also the same.

2.SJF: The response time is 0, 100, 300, and the turnaround time is 100, 300, 600 respectively.

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 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 -- Response: 0.00  Turnaround 100.00  Wait 0.00
  Job   1 -- Response: 100.00  Turnaround 300.00  Wait 100.00
  Job   2 -- Response: 300.00  Turnaround 600.00  Wait 300.00

  Average -- Response: 133.33  Turnaround 333.33  Wait 133.33

FIFO: response times are 0, 100, 300, and turnaround times are 100, 300, 600 respectively.

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 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 -- Response: 0.00  Turnaround 100.00  Wait 0.00
  Job   1 -- Response: 100.00  Turnaround 300.00  Wait 100.00
  Job   2 -- Response: 300.00  Turnaround 600.00  Wait 300.00

  Average -- Response: 133.33  Turnaround 333.33  Wait 133.33

For this question, the scheduling order of these two scheduling methods is the same, so the results are also the same.

3.RR: The response times are 0, 1, and 2 respectively. The turnaround times are 298, 499, and 600 respectively. (Response time has improved significantly, but average turnaround time has improved)

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched$ python3 scheduler.py -p RR -l 200,200,200 -c
Final statistics:
  Job   0 -- Response: 0.00  Turnaround 298.00  Wait 198.00
  Job   1 -- Response: 1.00  Turnaround 499.00  Wait 299.00
  Job   2 -- Response: 2.00  Turnaround 600.00  Wait 300.00

  Average -- Response: 1.00  Turnaround 465.67  Wait 265.67

4. For workloads whose task lengths are arranged in ascending order by time, SJF and FIFO will schedule processes in the same order, so there will be the same turnaround time.

5. The job lengths are the same, and the quantum length (the quantum length here means the length of a time slice in the RR scheduling algorithm) is equal to the job length.

6. Except for the first task, the response time of subsequent tasks will gradually increase. You can use the following command to simulate the test:

python3 scheduler.py -p SJF -q 1 -l 100,100,100 -c

python3 scheduler.py -p SJF -q 1 -l 200,200,200 -c

python3 scheduler.py -p SJF -q 1 -l 300,300,300 -c

7. Response time will increase.

Assume that the length of a time slice is T, then the response time of the nth job is (n - 1) * T. According to the equal-additive sequence summation formula, the average response time can be calculated as (n - 1) * T / 2.

Summary and insights

  • In this chapter, the evaluation indicators of process scheduling are turnaround time and response time . Turnaround time is task completion time minus task arrival time. Response time is first run time minus arrival time.
  • FIFO is first in first out scheduling. That is, they run in turn according to the order of tasks.
  • SJF is shortest task first scheduling. That is, run the shortest task first, then the next-shortest task, and so on.
  • STCF is shortest completion time priority scheduling. That is, preemption is added to SJF. Whenever a new task enters the system, the run with the shortest remaining time among all tasks will be re-selected.
  • RR is round robin scheduling. That is, a task is run within a time slice, and after the time slice ends, the next task is run.
  • FIFO, SJF, and STCF are optimized for turnaround time . RR is optimized for response time .
  • The scheduling algorithms in this chapter are all scheduled when the running time and arrival time of the process are determined. However, existing operating systems cannot predict task running conditions in most cases. Based on this, the multi-level feedback queue in the next chapter implements the function of using recent history to predict the future.

Guess you like

Origin blog.csdn.net/doreen211/article/details/125588965