Chen Minqi
Q1a. Given that the probability of a task accessing an I/O device is , explain why the probability of n processes accessing an I/O device is .
2. Explain, with an example, why the highest priority task can still be interrupted by the lowest priority interrupt, and how this affects ISR design. (Hint: Interrupts are implemented in hardware in the CPU itself).
Interrupt
Preemption
3. Given four batch jobs T1, T2, T3 and T4 with running times of 190 cycles, 300 cycles, 30 cycles and 130 cycles, find the average waiting time to run if the jobs are
a: FIFO
b: SJF.
| T | Ci |
|---|---|
| T1 | 190 |
| T2 | 300 |
| T3 | 30 |
| T4 | 130 |
| T | Waiting time | Time@completion |
|---|---|---|
| T1 | 0 | 0+190 |
| T2 | 190 | 190+300 |
| T3 | 490 | 490+30 |
| T4 | 520 | 520+130 |
Total = 0 + 190 + 490 + 520 = 1200 cycles
Average = 300 cycles waiting time.
| T | Ci |
|---|---|
| T1 | 190 |
| T2 | 300 |
| T3 | 30 |
| T4 | 130 |
| T | Waiting time | Time@completion |
|---|---|---|
| T3 | 0 | 0+30 |
| T1 | 30 | 30+130 |
| T4 | 160 | 160+190 |
| T2 | 350 | 350+300 |
Total = 0 + 30 + 160 + 350 = 540 cycles
Average = 135 cycles
| Algorithm | Decision Mode | Priority Function | Arbitration rule |
|---|---|---|---|
| FIFO | Non-preemptive | r | Random |
| SJF | Non-preemptive | -t | Chronological or random |
r - real time in system
t - service time
Pros of SJF:
Cons:
4. Explain why, in critical instance analysis, if for each , every task is guaranteed to meet its deadline.
Shorter period, higher priority.
Shorter period, higher priority.
Sum of the service time of all processes up to i.
Also the turnaround time for process i if there is no pre-emption.
Process j occurs again before process i can complete.
Hence j will pre-empt i.
| T | Ci | Pi |
|---|---|---|
| 1 | 1 | 3 |
| 2 | 3 | 10 |
This captures the total number of times that i will be blocked by j.
Total time that i spent waiting for j.
Total time that i spent waiting for all higher priority processes.
This is a new estimate of the turnaround time for process i.
But now that this turnaround time estimation is potentially longer than the old one, it will be pre-empted a few more times.
This estimate keeps growing, but eventually it reaches a point where it reflects the actual scheduling.
As long as all processes can meet its deadline, everything can be scheduled.
Scheduling is feasible using EDF if
This is actually CPU utilization.
Using the same formula for RMS:
Scheduling is feasible with RMS as long as the CPU utilization is less than approximately 0.7.
Furthermore, the condition is sufficient but not necessary
i.e., feasible schedules may still be possible for U > 0.7, but RM is not guaranteed to always find them.