Modul 3 - Scheduling Flashcards
What is turnaround time? (Omloppstiden)
- Turnaround time = Finish time - Arrival time
- The time it takes for a process to finish execution minus the time when the process entered the system.
- It’s the time required for a particular process to complete, from submission time to completion. It is equal to the sum total of Waiting time and Execution time.
What is response time? (Responstiden)
- Response time = First run time (first scheduled) - Arrival time
- The time a process first gets to run minus the time the process entered the system
- Response time - The time taken in a program from the issuance of a command to the commence of a response to that command.(i.e., the time-interval between submission of a request, and the first response to that request, not the output .)
Scheduling algorithms?
- First in first out (FIFO)
- Shortest job first (SJF)
- Shortest time to completion first (STCF)
- Round Robin (RR)
- Multilevel feedback queue (MLFQ)
Explain First in first out (FIFO) scheduling algorithm
The processes run to completion in the order in which they came in.
Explain Shortest job first (SJF) scheduling algorithm
Runs the processes that has the shortest execution time to run first. It’s a non-preempt scheduler.
Explain Shortest time to completion first (STCF) scheduling algorithm
Like SJF, which runs the processes that has the shortest execution time first, but it is possible to stop and run processes alternately (växelvis). It’s a preempt scheduler.
Solves the problem of SJF, if a process that takes longer time to complete arrives before another process that is shorter.
So any time a new process enters the system the STCF scheduler determines which of the remaining jobs (including the new job) has the least time left, and schedules that one.
Alltså om process1 tar 30 ms anländer vid tid 0ms och process2 tar 10 ms och anländer vid tid 10 ms. Så kommer process1 att pausas och process2 börja köras tills den blir klar. Sen återuptas process1 igen. (Om inte det finns någon annan kortare process som väntar på att köras)
- Bad response time.
Explain Round Robin (RR) scheduling algorithm
•Runs processes in time slices.
For example if we have three process that all take 40 ms to complete. Then we can improve the response time by giving each process a time-slice of 10 ms. So it alternates between the processes every 10ms.
•Good for response time but really bad for turnaround time. (worst policy for turnaround time).
- What RR is doing is stretching out each job as long as it can, by only running each job for a short bit before moving to the next. Because turnaround time only cares about when jobs finish, RR is nearly pessimal, even worse than simple FIFO in many cases.
- Making the time slice too short is problematic: suddenly the cost of context switching will dominate overall performance.
What are the problems with scheduling algorithms such as Shortest job first (SJF) and Shortest time to completion first (STCF) and how can we address the problem?
- Problems with algorithms such as SJF and STCF is that we cannot know in advance how long a program will run.
- Multilevel feedback queue addresses this problem
How does Multilevel feedback queue (MLFQ) scheduling algorithm work?
- It decides which processes run first by observing their behavior and assigning different priorities. Processes with high priority are chosen to run first. Processes with the same priority runs with round-robin scheduling (RR).
- MLFQ has a number of distinct queues, each assigned to a different priority level.
- MLFQ tries to optimize turnaround time and minimize response time (to make the program feel more interactive).
- If a process uses the CPU under a long amount of time => low priority
- If a process gives away CPU time often, for example while waiting for input from the keyboard => keeps its high priority (as this is how an interactive process might behave.)
- MLFQ will try to learn about processes as they run, and thus use the history of the job to predict its future behavior.
- Because it dosen’t know how long a processes will be, it will assume that is short (set to high priority first) and then lower the priority if the processes consumes all the time that is given in each priority level.
Assume we have a scheduler that implements “shortest job first” i.e. not able to preempt jobs. If we have three jobs that will take 10ms, 20ms and 30ms it’s a better strategy than taking the jobs in random order, show why. (Tenta fråga)
Answer:
- Turnaround time = (10 + 30 + 60) / 3 = 33 ms
- Wrong order could give turnaround time = (30 + 50 + 60) / 3 = 47 ms
Where turnaround time is : Finish time - Arrival time
What happens to a process if it initiates a I/O-operation? (Scheduling)
- An I/O-operation will take time to complete and we (the CPU) could do some useful work while a process is waiting.
- That is why a process is descheduled if it is preempted or if it initiates a I/O-operation. It enters the blocked state. When the I/O is completed it will enter the ready state.
What is the convoy effect?
It when a number of relatively-short potential consumers of a resource get queued behind a heavyweight resource consumer.
For example if we use FIFO (first in first out) with with two processes , process1 (takes 5 ms to complete) and process2 (takes 20 ms to complete). If process2 arrives before, then we get the convoy effect.
To fix this use SJF (Shortest job first).
Preemptive vs non-preemptive schedulers?
- non-preemptive schedulers run each job to completion before considering whether to run a new job.
- preemptive schedulers quite willing to stop one process from running in order to run another. Virtually all modern schedulers are this way.
This implies that the scheduler employs a context switch, stopping one running process temporarily and resuming (or starting) another.
What is the cost of a context switch? (switching which process that runs on the CPU)
The cost of context switching does not arise solely from the OS actions of saving and restoring a few registers. When programs run, they build up a great deal of state in CPU caches, TLBs, branch predictors, and other on-chip hardware. Switching to another job causes this state to be flushed and new state relevant to the currently running job to be brought in, which may exact a noticeable performance cost.
Which rules has the Multilevel feedback queue (MLFQ) scheduling policy?
MLFQ rules:
- Rule 1: If Priority(A) > Priority (B) => A is scheduled for execution.
- Rule 2: If Priority(A) = Priority (B) => A and B are scheduled in round-robin (RR), i.e., time-slices.
- Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). i.e., when a new job is created it starts with the highest priority.
— A job is given a allotted time, to consume at each priority level. —-
• Rule 4: a job that has consumed its allotted time (regardless of how many times it has given up the CPU) is moved to a lower priority.
- With such protections in place, regardless of the I/O behavior of the process, it slowly moves down the queues, and thus cannot gain an unfair share of the CPU.
• Rule 5: After some time period S, move all jobs to the highest priority. (Solves starvation problem: which is if there are too many short jobs it will never let a long running job finish.)