Multitasking and Scheduling Flashcards
What are the three possible states of a process?
Ready, running and Blocked
What does the scheduler decide
“The scheduler decides which process from the set of ready processes will get the CPU next”
What is a context switch
A context switch is the name given when one process stores its state and “yeilds” for another process to execute
What are the two reasons a context switch may take place
Pre-emptive switching where the OS choses to switch between processes
Interrupt driven switching where Hardware of Software Interrupts trigger a switch between processes
What is the main issue with Context Switching
It has overhear, for a context switch to occur it needs to:
+ Save/restore program counter
+ Save/restore stack register(s)
+ Save/restore status register
+ Save/restore general purpose registers
+ Save/restore memory map
+ Save/restore I/O status ← outstanding requests
+ Invalidate Memory Cache
+ Invalidate Working set of pages
What does the quantum in round-robin scheduling describe
The allowance of CPU time one process gets in one cycle
What are the tradeoffs between Short and Long Quantum in round-robin scheduling
Long Quantum:
+ Long response time
+ Good Efficiency
Short Quantum:
+ Fast response time
+ High overhead from context switching
What is the large drawback of lottery scheduling
There are no guarantees that a given process will get CPU timed as it uses random ticket selection
What are the two different approaches to deadlines for real-time systems
Soft real-time systems such as multimedia controllers where its acceptable to be slightly off
Hard real-time systems where it’s not ok to be off at all
What are the key features of RIOS
+ Minimalist but practical
+ Fixed priorites
+ Preemptive multitasking
+ Bounded stack usage
+ Small and understandable
Where do tasks execute when scheduling with RIOS
Within interupt service routines
What must we be careful about calling within RIOS tasks
We must be careful about calling non-rentrant functions within RIOS tasks, as these may be interrupted.
Say we need to use printf()
in multiple places, we should create our own task which prints from a queue and is the only task using printf()
, and then any function which wish to print should push to this.
What is the deadline of a task
The latest time by which a task has to be completed
What does it mean for a task to be periodic
It means that the task repeats itself at a regular interval of time
What does it mean for a task to be aperiodic
It means that the task does have a regular interval of time between when it needs to be ran
How can CPU Utilization be calculated (U), and what constraint always exists on this
U=Ctotal - Cidle <= 1
Where
- Ctotal is the total CPU time available, such as 100%
- Cidle is the Fraction of CPU time spent in idle task or sleeping
What assumptions are made when analysing the scheduling of tasks
- Tasks are periodic
- The deadline for a task is its next invocation
- Context switches take no time
When analysing the scheduling of tasks, how do we handle Aperiodic tasks
We use polling, and assume the worst case for every tick
Given a set of tasks T1…Tn with periodicity pi and fixed CPU time ci for task i, how do we calculate the load (U) of this set of tasks. And when are these tasks schedulable
U=∑ni=1ci / pi
This U value must be less than 1 for the system to be schedulable
What two methods can we use to assign priority to tasks
Fixed (static) priority which is assigned at compile time
Dynamic priority which changes during runtime
What is the advantage of Fixed Priority scheduling over Dynamic Priority scheduling
Fixed Priority has very simple code, and is well understood meaning we can have high confidence in its behaviour
What is the optimal priority scheme for fixed priority scheduling
Rate Monotonic Scheduling
What are the requirements for Rate Monotonic Scheduling
Tasks are independent
Tasks have fixed CPU requirement
Context switching is free
Deadline of a given task is its period
For RMS tasks must be independent
No task can block another task
for RMS tasks must have a fixed CPU requirement, what do we do if a task has a variable CPU requirement
We assume it to take the worst-case amount of time
For RMS we assume context switching to be free (when its not), how do we get around this
We include the time taken to context switch in the task time
How do we assign the fixed priorities for RMS
We give the most frequent task the highest priority
What must U=∑ni=1ci / pi be less than for RMS to be able to guarantee scheduling for
∑ni=1ci / pi must be less than n(21/n-1)
As n approaches infinity, what can we approximate the upper bound for RMS to be effective as
69%
When assigning priority for RMS, what does a priority of 0 mean
0 means that the task is of the highest priority
Assign the priority for the following tasks with RMS:
- Task A, Importance: Very High, Frequency: 2Hz
- Task B, Importance: High, Frequency: 0.5Hz
- Task C, Importance: Medium, Frequency: 50Hz
Priority:
C: 0 (Highest)
A: 1
B: 2
RMS is effective when U<=69% (generalisation but diligaf), what can be done such that we don’t “waste” the other 30% of CPU time
We can either use it to run non-real-time tasks with a “low priority” or optimise the task periods such that a regular execution pattern is achieved
If tasks are harmoic, what can we guarantee after observing one successful period of tasks
That all future periods will take the same form
How do we make a given task set harmonic
Reduce the deadlines of tasks (make the deadlines stricter) such that any task period is a multiple of the period of any higher priority task
For a set of tasks T, with task periods pi, what must hold for the task set to be harmonic
For each task ti in T
- For every other task tj in T / {ti}
- pj < pi or pj=pi * n given n is taken from the set of natural numbers
Give one example restriction which would make the following periods harmonic
1. 17ms
2. 31ms
3. 130ms
- 15ms
- 30ms
- 120ms
What CPU utilization can be reached with a harmonic task set
100% Utilization
What do we use instead of periods for Dynamic Priority Scheduling
We use Deadlines in place of periods, this is useful if the deadline is earlier than the next period
What is EDF and how does it work
Earliest Deadline First allows dynamic changes of priority and runs the most urgent task first
This can allow preemtion
What can we use to calculate the U value for EDF
U= ∑ni=1ci/pi ≤ 1
Where ci is the CPU time needed to complete the task and pi is the period of the task
What are some of the drawbacks of using EDF in place of RMS
The Scheduler is more complicated
The Scheduler has more overhead
EDF is not stable under overload
What can EDF handle which RMS cannot
+ Changing the importance of tasks
+ New tasks at runtime
+ Variable execution time