Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scheduling Algorithms

4,271 views

Published on

Scheduling algorithms for embedded system

Published in: Technology
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/369VOVb ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/369VOVb ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Scheduling Algorithms

  1. 1. Nov 2nd 2012 Julian Ilham Dept. of Electronic Engineering Pukyong National University Email: ilham.julian@gmail.com1
  2. 2.  Introduction Preemptive vs Non-Preemptive First Come First Served (FCFS) Shortest Job First (SJF) Priority Based Scheduling Round Robin (RR) 2
  3. 3. What is scheduling? Choosing which task to run and for how long Why do we need it?- Improve the system performance- Support multitasking 3
  4. 4. Running task can be forced to release even Preemptive though it is neither completed Each running task keeps processing until itNon - Preemptive completed 4
  5. 5.  Only available in Non-Preemptive mode Example: Tasks Arrival Times (ms) Burst Time (ms) P2 0.0 12 P3 3.0 8 P4 5.0 4 P1 10.0 10 P5 12.0 6 Gantt chart P2 P3 P4 P1 P5 0 20 24 34 40 (ms) 3 5 10 12 5
  6. 6.  Time Calculation P1 : 24 – 10 = 12 ms P2 : 0 ms P3 : 12 – 3 = 9 ms P4 : 20 – 5 = 15 ms P5 : 34 – 12 = 22 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 58 msAverage waiting time : 58 ms / 5 = 11.6 ms 6
  7. 7.  Advantage: Very simple code and structure Disadvantage: Large average waiting time 7
  8. 8.  Available in Preemptive and Non-Preemptive mode Example (Preemptive) Tasks Arrival Times (ms) Burst Time (ms) P2 0.0 12 P3 3.0 8 P4 5.0 4 P1 10.0 10 P5 12.0 6 Gantt chart P2 P3 P4 P3 P5 P2 P1 0 9 15 21 30 40 (ms) 3 5 10 12 8
  9. 9.  Time Calculation (Preemptive) P1 : 30 – 10 = 20 ms P2 : 0 + (21 – 3) = 18 ms P3 : (3 – 3) + (9 – 5) = 4 ms P4 : 5 – 5 = 0 ms P5 : 15 – 12 = 3 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 45 msAverage waiting time : 45 ms / 5 = 9 ms 9
  10. 10.  Example (Non-Preemptive) Tasks Arrival Times (ms) Burst Time (ms) P2 0.0 12 P3 3.0 8 P4 5.0 4 P1 10.0 10 P5 12.0 6 Gantt chart P2 P4 P5 P3 P1 0 16 22 30 40 (ms) 3 5 10 12 10
  11. 11.  Time Calculation (Non-Preemptive) P1 : 30 – 10 = 20 ms P2 : 0 ms P3 : 22 – 3 = 19 ms P4 : 12 – 5 = 7 ms P5 : 16 – 12 = 4 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 50 msAverage waiting time : 50 ms / 5 = 10 ms 11
  12. 12.  Advantage: Minimum average waiting time for a given set of process Disadvantage: Difficult to estimate burst time, starvation (indefinite blocking) 12
  13. 13.  Available in Preemptive and Non-Preemptive mode Example (Preemptive) Tasks Arrival Times (ms) Burst Time (ms) Priority P2 0.0 12 2 P3 3.0 8 5 P4 5.0 4 1 P1 10.0 10 4 P5 12.0 6 3 Gantt chart P2 P4 P2 P5 P1 P3 0 9 16 22 32 40 (ms) 3 5 10 12 13
  14. 14.  Time Calculation (Preemptive) P1 : 22 – 10 = 12 ms P2 : 9 – 5 = 4 ms P3 : 32 – 3 = 29 ms P4 : 5 – 5 = 0 ms P5 : 16 – 12 = 4 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 49 msAverage waiting time : 49 ms / 5 = 9.8 ms 14
  15. 15.  Example (Non-Preemptive) Tasks Arrival Times (ms) Burst Time (ms) Priority P2 0.0 12 2 P3 3.0 8 5 P4 5.0 4 1 P1 10.0 10 4 P5 12.0 6 3 Gantt chart P2 P4 P5 P1 P3 16 22 32 40 (ms) 3 5 10 12 15
  16. 16.  Time Calculation (Non-Preemptive) P1 : 22 – 10 = 12 ms P2 : 0 ms P3 : 32 – 3 = 29 ms P4 : 12 – 5 = 7 ms P5 : 16 – 12 = 4 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 52 msAverage waiting time : 52 ms / 5 = 10.4 ms 16
  17. 17.  Advantage: Easier than SJF Disadvantage: Can cause indefinite blocking 17
  18. 18.  Only available in Non-Preemptive mode FCFS is used in sequencing policy Need to determine time slice/ quantum as a unit of time for each process Then continue to the next process after reaching maximum of quantum - Too small time quantum -> too many tasks switched - Too large time quantum -> inherits the problem of FCFS 18
  19. 19.  Example (assuming quantum is 5 ms): Tasks Arrival Times (ms) Burst Time (ms) P2 0.0 12 P3 3.0 8 P4 5.0 4 P1 10.0 10 P5 12.0 6 Gantt chart0 5 10 14 19 24 29 32 37 38 40 P2 P3 P4 P1 P5 P2 P3 P1 P5 P2 3 5 10 12 19
  20. 20.  Time Calculation P1 : (14 – 10) + (32 – 19) = 17 ms P2 : 0 + (24 – 5) + (38 – 29) = 28 ms P3 : (5 – 3) + (29 – 10) = 21 ms P4 : 10 – 5 = 5 ms P5 : (19 – 12) + (37 – 24) = 20 msTotal waiting time : P1 + P2 + P3 + P4 + P5 = 91 msAverage waiting time : 91 ms / 5 = 18.2 ms 20
  21. 21.  Advantage: Guarantee fairness (bounded waiting time and no starvation) Disadvantage: Average waiting time is long 21
  22. 22. Q n A 22

×