SlideShare a Scribd company logo
Scheduling Algorithms

Frédéric Haziza <daz@it.uu.se>
    Department of Computer Systems
          Uppsala University


           Spring 2007
Recall                 Basics             Algorithms   Multi-Processor Scheduling



Outline


         1   Recall

         2   Basics
               Concepts
               Criteria

         3   Algorithms

         4   Multi-Processor Scheduling
Recall             Basics             Algorithms         Multi-Processor Scheduling




         Interrupts
         Traps (software errors, illegal instructions)
         System calls
Recall              Basics       Algorithms             Multi-Processor Scheduling




            PCB
                             Job Queue
        process state
                             Linked list of PCBs
     process ID (number)
             PC
                                 (main) job queue
          Registers
     memory information          ready queue
          open files              device queues
              .
              .
              .
                             Schedulers
         other resources
                                 Long-term/Job scheduler
                                 (loads from disk)
                                 Short-term/CPU scheduler
                                 (dispatches from ready queue)
Recall                Basics           Algorithms          Multi-Processor Scheduling




         Note that...
         On Operating Systems which support threads,
         it is kernel-level threads – not processes –
         that are being scheduled.



         However, process sheduling ≈ thread scheduling.
Recall              Basics       Algorithms           Multi-Processor Scheduling



CPU and IO Bursts

     .
     .
     .
     load, store,
     add, store,
     read from file
         Wait for IO
     store,increment,
     branch, write to file
         Wait for IO         CPU Burst cycles
     load, store,            Intervals with no I/O usage
     read from file
         Wait for IO         Waiting time
     .
     .
     .                       Sum of time waiting in ready queue
Recall              Basics          Algorithms     Multi-Processor Scheduling



When should we schedule a process?



         From running state to waiting state
         From running state to ready state
         From waiting state to ready state
         Terminates


   Scheme                             Scheme
   non-preemptive                     preemptive
   or cooperative
Recall              Basics                Algorithms          Multi-Processor Scheduling



How do we select the next process?


         CPU utilization
         CPU as busy as possible
         Throughput
         Number of process that are completed per time unit
         Turnaround time
         Time between submisson and completion
         Waiting time
         Scheduling affects only waiting time
         Response time
         Time between submisson and first response
Recall            Basics             Algorithms             Multi-Processor Scheduling



First Come, First Served (FCFS)




         Non-preemptive
         Treats ready queue as FIFO.
         Simple, but typically long/varying waiting time.
Recall                 Basics               Algorithms             Multi-Processor Scheduling



First Come, First Served (FCFS)


         Example
          Process     Burst time    Arrival
             P1          24           0
             P2           3           0
             P3           3           0

         Gantt chart: Order P1 , P2 , P3
          |           P1            |      P2    |       P3    |
          0                        24           27            30

         Average waiting time: (0+24+27)/3 = 17
Recall                  Basics              Algorithms        Multi-Processor Scheduling



First Come, First Served (FCFS)


         Example
          Process      Burst time    Arrival
             P1           24           0
             P2            3           0
             P3            3           0

         Gantt chart: Order P2 , P3 , P1
          |   P2   |    P3       |         P1             |
          0        3             6                       30

         Average waiting time: (0+3+6)/3 = 3
Recall                 Basics           Algorithms   Multi-Processor Scheduling



Convoy effect




         Consider :
             P1 : CPU-bound
             P2 , P3 , P4 : I/O-bound
Recall                   Basics                 Algorithms     Multi-Processor Scheduling



Convoy effect

              P2 , P3 and P4 could quickly finish their IO request ⇒ ready
              queue, waiting for CPU.
              Note: IO devices are idle then.
              then P1 finishes its CPU burst and move to an IO device.
              P2 , P3 , P4 , which have short CPU bursts, finish quickly ⇒
              back to IO queue.
              Note: CPU is idle then.
              P1 moves then back to ready queue is gets allocated CPU
              time.
              Again P2 , P3 , P4 wait behind P1 when they request CPU
              time.
         One cause: FCFS is non-preemptive
         P1 keeps the CPU as long as it needs
Recall                Basics            Algorithms          Multi-Processor Scheduling



Shortest Job First (SJF)




             Give CPU to the process with the shortest next burst
             If equal, use FCFS
             Better name: shortest next cpu burst first

         Assumption
         Know the length of the next CPU burst of each process in
         Ready Queue
Recall                  Basics               Algorithms        Multi-Processor Scheduling



Short Job First (SJF)

         Example
          Process      Burst time       Arrival
             P1            6              0
             P2            8              0
             P3            7              0
             P4            3              0

         Gantt chart: Order P1 , P2 , P3 , P4
          |   P4   |       P1       |      P3         |   P2    |
          0        3                9                16        24

         Average waiting time: (0+3+16+9)/4 = 7
         With FCFS: (0+6+(6+8)+(6+8+7))/4 = 10.25
Recall                 Basics           Algorithms    Multi-Processor Scheduling



SJF – Characteristics


         Optimal wrt. waiting time!

         Problem: how to know the next burst?
             User specifies (e.g. for batch system)
             Guess/predict based on earlier bursts,
             using exponential average:
             τn+1 = αtn + (1 − α)τn
             tn : most recent information
             τn : past history

         Can be preemptive or not
Recall                          Basics                         Algorithms           Multi-Processor Scheduling



SJF with Preemption




         Shortest Remaining Time First
         When a process arrives to RQ, sort it in and select the SJF
         including the running process, possibly interrupting it
         (Remember: SJF schedules a new process only when the running is finished)
Recall                  Basics                  Algorithms         Multi-Processor Scheduling



SJF with Preemption

         Example
          Process      Burst time         Arrival
             P1            8                0
             P2            4                1
             P3            9                2
             P4            5                3

         Gantt chart
          |   P1   |    P2       |   P4     |   P1        |   P3    |
          0        1             5         10            17        26

         Average waiting time: ((10-1)+(1-1)+(17-2)+(5-3))/4 = 6.5
         With SJF: (0+4+(4+5)+(4+5+8))/4 = 7.75
Recall            Basics            Algorithms           Multi-Processor Scheduling



Priority Scheduling Algorithms




         Priority associated with each process
         CPU allocated to the process with highest priority
         If equal, use FCFS



            Note: SJF is a priority scheduling algorithm with
                                        1
                       p = (predicted) next CPU burst
Recall                  Basics               Algorithms             Multi-Processor Scheduling



Priority Scheduling Algorithms

         Example
          Process      Burst time       Arrival    Priority
             P1           10              0           3
             P2            1              0           1
             P3            2              0           4
             P4            1              0           5
             P5            5              0           2

         Gantt chart
          |   P2   |       P5       |      P1         |   P3    |   P4       |
          0        1                6                16        18           19

         Average waiting time: (0+1+6+16+18)/5 = 8.2
Recall            Basics            Algorithms          Multi-Processor Scheduling



Priority Criteria


         Internal Priority
         time limits, mem requirements, number of open files,
         ratio Average CPUburst
                Average IO
                           burst
         External Priority
         Critera outside the OS. Choice related to computer usage.

         Can be preemptive or not

         Problem: Starvation (or Indefinite Blocking)
         Solution: Aging
Recall            Basics           Algorithms    Multi-Processor Scheduling



Round-Robin (RR)




         FCFS with Preemption
         Time quantum (or time slice)
         Ready Queue treated as circular queue
Recall                 Basics                 Algorithms               Multi-Processor Scheduling



Round-Robin (RR)


         Example
                       Process           Burst time         Arrival
                          P1                24                0
         Quantum q = 4
                          P2                 3                0
                          P3                 3                0

         Gantt chart
          |   P1   |   P2       |   P3    |   P1        |   ...    |   P1        |
          0        4            7        10            14         26            30

         Average waiting time: (0+4+7+(10-4))/3 = 5.66
         With FCFS: (0+24+27)/3 = 17
Recall               Basics                            Algorithms                          Multi-Processor Scheduling



RR – Characteristics



         Turnaround time typically larger than SRTF but better
         response time

         Performance depends on quantum q
             Small q: Overhead due to context switches (& scheduling)
             q should be large wrt context-switching time

             Large q: Behaves like FCFS
             rule of thumb: 80% of bursts should be shorter than q (also improves turnaround time)
Recall                 Basics            Algorithms           Multi-Processor Scheduling



Multilevel Queue Scheduling

         Observation
         Different algorithms suit different types of processes
         (e.g. interactive vs batch/background processes)
         and systems are often not only running interactive or "batch"
         processes.

         Multilevel queues
         We split the Ready Queue in several queues,
         each with its own scheduling algorithm

         Example
         interactive processes: RR
         background processes: FCFS/SRTF
Recall                 Basics             Algorithms            Multi-Processor Scheduling



Multilevel Queue – Scheduling among Queues




         One more dimension
         We need scheduling between the Ready Queues

         Example (Common implementation)
         Fixed-priority preemption (with priority to interactive processes)
Recall                           Basics                           Algorithms                                Multi-Processor Scheduling



Multilevel Queue – More complex example


         1   System processes                                                      where each queue has absolute priority over

         2   Interactive processes                                                 lower-priority queues.

         3   Interactive editing processes
                                                                                   No process in low-priority queues can run if
         4   Batch processes                                                       high-priority queues are not empty
         5   Student processes
         So, if a lower-priority queue is only used when all higher-priority RQs are
         empty & higher-priority processes preempt lower-priority ones,
         we risk starvation.

         Possible solution: give time-slices to each Ready Queue
         (basically RR between the queues, with different quanta for each queue)

         ⇒ Each queue gets a certain guaranteed slice of the CPU time.
Recall                Basics            Algorithms           Multi-Processor Scheduling



Multi-Level Feedback Queue Scheduling (MLFQ)

         With MLQ, each process is permanently assigned to one queue
         (based on type, priority etc).
         MLFQ
         allow processes to move between queues

         Idea: Separate processes according to their CPU bursts.
         Example
             Let processes with long CPU bursts move down in the
             queue levels
             Leave I/O bound and interactive processes in high-priority
             queues
             Combine with aging principle to prevent starvation
Recall                    Basics                  Algorithms                Multi-Processor Scheduling



MLFQ – Example


          1   Round-Robin with quantum 8
          2   Round-Robin with quantum 16
          3   FCFS
         Qi has priority over, and preempts, Qi+1 .
         New processes are added to Q1 .
         If a process in Q1 or Q2 does not finish within its quantum, it is
         moved down to the next queue.
         Thus:
              short bursts (I/O bound and interactive proc) are served quickly;
              slightly longer are also served quickly but with less priority;
              long (CPU bound processes) are served when there is CPU to be
              spared.
Recall                Basics           Algorithms      Multi-Processor Scheduling



Symmetry / Asymmetry




         Asymmetric MPs scheduling
         One Master Server does all scheduling.
         Others execute only user code

         Symmetric MPs (SMP) scheduling
         Each processor does scheduling.
         (whether CPUs have a common or private Ready Queues)
Recall                          Basics                         Algorithms   Multi-Processor Scheduling



Processor Affinity



         Try to keep a process on the same processor as last time,
         because of Geographical Locality
         (Moving the process to another CPU causes cache misses)


                Soft affinity
                The process may move to another processor

                Hard affinity
                The process must stay on the same processor
Recall                Basics            Algorithms           Multi-Processor Scheduling



Load Balancing



         Keep the workload evenly distributed over the processors
             push migration
             periodically check the load, and "push" processes to less
             loaded queues.
             pull migration
             idle processors "pull" processes from busy processors
         Note: Load balancing goes against processor affinity.
Recall                Basics           Algorithms         Multi-Processor Scheduling



Hyperthreaded CPUs




         CPUs with multiple "cores"

         Sharing cache and bus influences affinity concept and thus
         scheduling.

         The OS can view each core as a CPU, but can make additional
         benefits with threads
Ad

More Related Content

What's hot (20)

Chapter6
Chapter6Chapter6
Chapter6
Denis Nsiimenta
 
Scheduling
SchedulingScheduling
Scheduling
Mohd Arif
 
Scheduling Algorithms
Scheduling AlgorithmsScheduling Algorithms
Scheduling Algorithms
PT Mecoindo Itron
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
Harshit Jain
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
Sonali Chauhan
 
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
Solaiman Hridoy
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
Arafat Hossan
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
Dr. Loganathan R
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU Scheduling
Izaz Roghani
 
Ch6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinCh6 CPU Scheduling galvin
Ch6 CPU Scheduling galvin
Shubham Singh
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
Abhishek Nagar
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
Tayba Farooqui
 
OSCh6
OSCh6OSCh6
OSCh6
Joe Christensen
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
Nagarajan
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
harini0810
 
Lecture 5, 6 and 7 cpu scheduling
Lecture 5, 6 and 7  cpu schedulingLecture 5, 6 and 7  cpu scheduling
Lecture 5, 6 and 7 cpu scheduling
Rushdi Shams
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
Abhijith Reloaded
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Universitas Pembangunan Panca Budi
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
shekhar1991
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
Nagarajan
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
Harshit Jain
 
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
CPU Scheduling Algorithm (SJF, Round-Robin, Priority)
Solaiman Hridoy
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU Scheduling
Izaz Roghani
 
Ch6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinCh6 CPU Scheduling galvin
Ch6 CPU Scheduling galvin
Shubham Singh
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
Tayba Farooqui
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
Nagarajan
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
harini0810
 
Lecture 5, 6 and 7 cpu scheduling
Lecture 5, 6 and 7  cpu schedulingLecture 5, 6 and 7  cpu scheduling
Lecture 5, 6 and 7 cpu scheduling
Rushdi Shams
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Universitas Pembangunan Panca Budi
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
Nagarajan
 

Similar to Algorithm o.s. (20)

CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
Shubhashish Punj
 
Os module 2 ba
Os module 2 baOs module 2 ba
Os module 2 ba
Gichelle Amon
 
Process Scheduling in Ope Spptystems rating
Process Scheduling in Ope Spptystems ratingProcess Scheduling in Ope Spptystems rating
Process Scheduling in Ope Spptystems rating
Aryan904173
 
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ssuserc35fa4
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
tech2click
 
Os..
Os..Os..
Os..
pri534
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
Chankey Pathak
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
pri534
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Scheduling
vinay arora
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
gopi7
 
Operating systems - Processes Scheduling
Operating systems - Processes  SchedulingOperating systems - Processes  Scheduling
Operating systems - Processes Scheduling
Dr. Chandrakant Divate
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
ImranKhan880955
 
Ch6
Ch6Ch6
Ch6
C.U
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
Yogesh Santhan
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
jamilaltiti1
 
Ch5
Ch5Ch5
Ch5
Lokesh Kannaiyan
 
Scheduling Algorithms-Examples.pptx
Scheduling Algorithms-Examples.pptxScheduling Algorithms-Examples.pptx
Scheduling Algorithms-Examples.pptx
Revathi Kmp
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
Supriya Shrivastava
 
Week 5a.pptx of cpu scheduling operating system class
Week 5a.pptx of cpu scheduling operating system classWeek 5a.pptx of cpu scheduling operating system class
Week 5a.pptx of cpu scheduling operating system class
Alishan442314
 
Process Scheduling in Ope Spptystems rating
Process Scheduling in Ope Spptystems ratingProcess Scheduling in Ope Spptystems rating
Process Scheduling in Ope Spptystems rating
Aryan904173
 
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ssuserc35fa4
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
tech2click
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
pri534
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Scheduling
vinay arora
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
gopi7
 
Operating systems - Processes Scheduling
Operating systems - Processes  SchedulingOperating systems - Processes  Scheduling
Operating systems - Processes Scheduling
Dr. Chandrakant Divate
 
Ch6
Ch6Ch6
Ch6
C.U
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
Yogesh Santhan
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
jamilaltiti1
 
Scheduling Algorithms-Examples.pptx
Scheduling Algorithms-Examples.pptxScheduling Algorithms-Examples.pptx
Scheduling Algorithms-Examples.pptx
Revathi Kmp
 
Week 5a.pptx of cpu scheduling operating system class
Week 5a.pptx of cpu scheduling operating system classWeek 5a.pptx of cpu scheduling operating system class
Week 5a.pptx of cpu scheduling operating system class
Alishan442314
 
Ad

More from Mohd Tousif (20)

Sql commands
Sql commandsSql commands
Sql commands
Mohd Tousif
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
Mohd Tousif
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
Mohd Tousif
 
Entity Relationship Model - An Example
Entity Relationship Model - An ExampleEntity Relationship Model - An Example
Entity Relationship Model - An Example
Mohd Tousif
 
Entity Relationship (ER) Model Questions
Entity Relationship (ER) Model QuestionsEntity Relationship (ER) Model Questions
Entity Relationship (ER) Model Questions
Mohd Tousif
 
Entity Relationship (ER) Model
Entity Relationship (ER) ModelEntity Relationship (ER) Model
Entity Relationship (ER) Model
Mohd Tousif
 
SQL Practice Question set
SQL Practice Question set SQL Practice Question set
SQL Practice Question set
Mohd Tousif
 
Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1
Mohd Tousif
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
Mohd Tousif
 
Data Warehouse Concepts and Architecture
Data Warehouse Concepts and ArchitectureData Warehouse Concepts and Architecture
Data Warehouse Concepts and Architecture
Mohd Tousif
 
SQL practice questions set - 2
SQL practice questions set - 2SQL practice questions set - 2
SQL practice questions set - 2
Mohd Tousif
 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
Mohd Tousif
 
SQL practice questions for beginners
SQL practice questions for beginnersSQL practice questions for beginners
SQL practice questions for beginners
Mohd Tousif
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
Mohd Tousif
 
Sql (Introduction to Structured Query language)
Sql (Introduction to Structured Query language)Sql (Introduction to Structured Query language)
Sql (Introduction to Structured Query language)
Mohd Tousif
 
Sql commands
Sql commandsSql commands
Sql commands
Mohd Tousif
 
Virtual box
Virtual boxVirtual box
Virtual box
Mohd Tousif
 
Deadlock
DeadlockDeadlock
Deadlock
Mohd Tousif
 
System components of windows xp
System components of windows xpSystem components of windows xp
System components of windows xp
Mohd Tousif
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
Mohd Tousif
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
Mohd Tousif
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
Mohd Tousif
 
Entity Relationship Model - An Example
Entity Relationship Model - An ExampleEntity Relationship Model - An Example
Entity Relationship Model - An Example
Mohd Tousif
 
Entity Relationship (ER) Model Questions
Entity Relationship (ER) Model QuestionsEntity Relationship (ER) Model Questions
Entity Relationship (ER) Model Questions
Mohd Tousif
 
Entity Relationship (ER) Model
Entity Relationship (ER) ModelEntity Relationship (ER) Model
Entity Relationship (ER) Model
Mohd Tousif
 
SQL Practice Question set
SQL Practice Question set SQL Practice Question set
SQL Practice Question set
Mohd Tousif
 
Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1
Mohd Tousif
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
Mohd Tousif
 
Data Warehouse Concepts and Architecture
Data Warehouse Concepts and ArchitectureData Warehouse Concepts and Architecture
Data Warehouse Concepts and Architecture
Mohd Tousif
 
SQL practice questions set - 2
SQL practice questions set - 2SQL practice questions set - 2
SQL practice questions set - 2
Mohd Tousif
 
SQL practice questions - set 3
SQL practice questions - set 3SQL practice questions - set 3
SQL practice questions - set 3
Mohd Tousif
 
SQL practice questions for beginners
SQL practice questions for beginnersSQL practice questions for beginners
SQL practice questions for beginners
Mohd Tousif
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
Mohd Tousif
 
Sql (Introduction to Structured Query language)
Sql (Introduction to Structured Query language)Sql (Introduction to Structured Query language)
Sql (Introduction to Structured Query language)
Mohd Tousif
 
System components of windows xp
System components of windows xpSystem components of windows xp
System components of windows xp
Mohd Tousif
 
Ad

Recently uploaded (20)

03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 

Algorithm o.s.

  • 1. Scheduling Algorithms Frédéric Haziza <[email protected]> Department of Computer Systems Uppsala University Spring 2007
  • 2. Recall Basics Algorithms Multi-Processor Scheduling Outline 1 Recall 2 Basics Concepts Criteria 3 Algorithms 4 Multi-Processor Scheduling
  • 3. Recall Basics Algorithms Multi-Processor Scheduling Interrupts Traps (software errors, illegal instructions) System calls
  • 4. Recall Basics Algorithms Multi-Processor Scheduling PCB Job Queue process state Linked list of PCBs process ID (number) PC (main) job queue Registers memory information ready queue open files device queues . . . Schedulers other resources Long-term/Job scheduler (loads from disk) Short-term/CPU scheduler (dispatches from ready queue)
  • 5. Recall Basics Algorithms Multi-Processor Scheduling Note that... On Operating Systems which support threads, it is kernel-level threads – not processes – that are being scheduled. However, process sheduling ≈ thread scheduling.
  • 6. Recall Basics Algorithms Multi-Processor Scheduling CPU and IO Bursts . . . load, store, add, store, read from file Wait for IO store,increment, branch, write to file Wait for IO CPU Burst cycles load, store, Intervals with no I/O usage read from file Wait for IO Waiting time . . . Sum of time waiting in ready queue
  • 7. Recall Basics Algorithms Multi-Processor Scheduling When should we schedule a process? From running state to waiting state From running state to ready state From waiting state to ready state Terminates Scheme Scheme non-preemptive preemptive or cooperative
  • 8. Recall Basics Algorithms Multi-Processor Scheduling How do we select the next process? CPU utilization CPU as busy as possible Throughput Number of process that are completed per time unit Turnaround time Time between submisson and completion Waiting time Scheduling affects only waiting time Response time Time between submisson and first response
  • 9. Recall Basics Algorithms Multi-Processor Scheduling First Come, First Served (FCFS) Non-preemptive Treats ready queue as FIFO. Simple, but typically long/varying waiting time.
  • 10. Recall Basics Algorithms Multi-Processor Scheduling First Come, First Served (FCFS) Example Process Burst time Arrival P1 24 0 P2 3 0 P3 3 0 Gantt chart: Order P1 , P2 , P3 | P1 | P2 | P3 | 0 24 27 30 Average waiting time: (0+24+27)/3 = 17
  • 11. Recall Basics Algorithms Multi-Processor Scheduling First Come, First Served (FCFS) Example Process Burst time Arrival P1 24 0 P2 3 0 P3 3 0 Gantt chart: Order P2 , P3 , P1 | P2 | P3 | P1 | 0 3 6 30 Average waiting time: (0+3+6)/3 = 3
  • 12. Recall Basics Algorithms Multi-Processor Scheduling Convoy effect Consider : P1 : CPU-bound P2 , P3 , P4 : I/O-bound
  • 13. Recall Basics Algorithms Multi-Processor Scheduling Convoy effect P2 , P3 and P4 could quickly finish their IO request ⇒ ready queue, waiting for CPU. Note: IO devices are idle then. then P1 finishes its CPU burst and move to an IO device. P2 , P3 , P4 , which have short CPU bursts, finish quickly ⇒ back to IO queue. Note: CPU is idle then. P1 moves then back to ready queue is gets allocated CPU time. Again P2 , P3 , P4 wait behind P1 when they request CPU time. One cause: FCFS is non-preemptive P1 keeps the CPU as long as it needs
  • 14. Recall Basics Algorithms Multi-Processor Scheduling Shortest Job First (SJF) Give CPU to the process with the shortest next burst If equal, use FCFS Better name: shortest next cpu burst first Assumption Know the length of the next CPU burst of each process in Ready Queue
  • 15. Recall Basics Algorithms Multi-Processor Scheduling Short Job First (SJF) Example Process Burst time Arrival P1 6 0 P2 8 0 P3 7 0 P4 3 0 Gantt chart: Order P1 , P2 , P3 , P4 | P4 | P1 | P3 | P2 | 0 3 9 16 24 Average waiting time: (0+3+16+9)/4 = 7 With FCFS: (0+6+(6+8)+(6+8+7))/4 = 10.25
  • 16. Recall Basics Algorithms Multi-Processor Scheduling SJF – Characteristics Optimal wrt. waiting time! Problem: how to know the next burst? User specifies (e.g. for batch system) Guess/predict based on earlier bursts, using exponential average: τn+1 = αtn + (1 − α)τn tn : most recent information τn : past history Can be preemptive or not
  • 17. Recall Basics Algorithms Multi-Processor Scheduling SJF with Preemption Shortest Remaining Time First When a process arrives to RQ, sort it in and select the SJF including the running process, possibly interrupting it (Remember: SJF schedules a new process only when the running is finished)
  • 18. Recall Basics Algorithms Multi-Processor Scheduling SJF with Preemption Example Process Burst time Arrival P1 8 0 P2 4 1 P3 9 2 P4 5 3 Gantt chart | P1 | P2 | P4 | P1 | P3 | 0 1 5 10 17 26 Average waiting time: ((10-1)+(1-1)+(17-2)+(5-3))/4 = 6.5 With SJF: (0+4+(4+5)+(4+5+8))/4 = 7.75
  • 19. Recall Basics Algorithms Multi-Processor Scheduling Priority Scheduling Algorithms Priority associated with each process CPU allocated to the process with highest priority If equal, use FCFS Note: SJF is a priority scheduling algorithm with 1 p = (predicted) next CPU burst
  • 20. Recall Basics Algorithms Multi-Processor Scheduling Priority Scheduling Algorithms Example Process Burst time Arrival Priority P1 10 0 3 P2 1 0 1 P3 2 0 4 P4 1 0 5 P5 5 0 2 Gantt chart | P2 | P5 | P1 | P3 | P4 | 0 1 6 16 18 19 Average waiting time: (0+1+6+16+18)/5 = 8.2
  • 21. Recall Basics Algorithms Multi-Processor Scheduling Priority Criteria Internal Priority time limits, mem requirements, number of open files, ratio Average CPUburst Average IO burst External Priority Critera outside the OS. Choice related to computer usage. Can be preemptive or not Problem: Starvation (or Indefinite Blocking) Solution: Aging
  • 22. Recall Basics Algorithms Multi-Processor Scheduling Round-Robin (RR) FCFS with Preemption Time quantum (or time slice) Ready Queue treated as circular queue
  • 23. Recall Basics Algorithms Multi-Processor Scheduling Round-Robin (RR) Example Process Burst time Arrival P1 24 0 Quantum q = 4 P2 3 0 P3 3 0 Gantt chart | P1 | P2 | P3 | P1 | ... | P1 | 0 4 7 10 14 26 30 Average waiting time: (0+4+7+(10-4))/3 = 5.66 With FCFS: (0+24+27)/3 = 17
  • 24. Recall Basics Algorithms Multi-Processor Scheduling RR – Characteristics Turnaround time typically larger than SRTF but better response time Performance depends on quantum q Small q: Overhead due to context switches (& scheduling) q should be large wrt context-switching time Large q: Behaves like FCFS rule of thumb: 80% of bursts should be shorter than q (also improves turnaround time)
  • 25. Recall Basics Algorithms Multi-Processor Scheduling Multilevel Queue Scheduling Observation Different algorithms suit different types of processes (e.g. interactive vs batch/background processes) and systems are often not only running interactive or "batch" processes. Multilevel queues We split the Ready Queue in several queues, each with its own scheduling algorithm Example interactive processes: RR background processes: FCFS/SRTF
  • 26. Recall Basics Algorithms Multi-Processor Scheduling Multilevel Queue – Scheduling among Queues One more dimension We need scheduling between the Ready Queues Example (Common implementation) Fixed-priority preemption (with priority to interactive processes)
  • 27. Recall Basics Algorithms Multi-Processor Scheduling Multilevel Queue – More complex example 1 System processes where each queue has absolute priority over 2 Interactive processes lower-priority queues. 3 Interactive editing processes No process in low-priority queues can run if 4 Batch processes high-priority queues are not empty 5 Student processes So, if a lower-priority queue is only used when all higher-priority RQs are empty & higher-priority processes preempt lower-priority ones, we risk starvation. Possible solution: give time-slices to each Ready Queue (basically RR between the queues, with different quanta for each queue) ⇒ Each queue gets a certain guaranteed slice of the CPU time.
  • 28. Recall Basics Algorithms Multi-Processor Scheduling Multi-Level Feedback Queue Scheduling (MLFQ) With MLQ, each process is permanently assigned to one queue (based on type, priority etc). MLFQ allow processes to move between queues Idea: Separate processes according to their CPU bursts. Example Let processes with long CPU bursts move down in the queue levels Leave I/O bound and interactive processes in high-priority queues Combine with aging principle to prevent starvation
  • 29. Recall Basics Algorithms Multi-Processor Scheduling MLFQ – Example 1 Round-Robin with quantum 8 2 Round-Robin with quantum 16 3 FCFS Qi has priority over, and preempts, Qi+1 . New processes are added to Q1 . If a process in Q1 or Q2 does not finish within its quantum, it is moved down to the next queue. Thus: short bursts (I/O bound and interactive proc) are served quickly; slightly longer are also served quickly but with less priority; long (CPU bound processes) are served when there is CPU to be spared.
  • 30. Recall Basics Algorithms Multi-Processor Scheduling Symmetry / Asymmetry Asymmetric MPs scheduling One Master Server does all scheduling. Others execute only user code Symmetric MPs (SMP) scheduling Each processor does scheduling. (whether CPUs have a common or private Ready Queues)
  • 31. Recall Basics Algorithms Multi-Processor Scheduling Processor Affinity Try to keep a process on the same processor as last time, because of Geographical Locality (Moving the process to another CPU causes cache misses) Soft affinity The process may move to another processor Hard affinity The process must stay on the same processor
  • 32. Recall Basics Algorithms Multi-Processor Scheduling Load Balancing Keep the workload evenly distributed over the processors push migration periodically check the load, and "push" processes to less loaded queues. pull migration idle processors "pull" processes from busy processors Note: Load balancing goes against processor affinity.
  • 33. Recall Basics Algorithms Multi-Processor Scheduling Hyperthreaded CPUs CPUs with multiple "cores" Sharing cache and bus influences affinity concept and thus scheduling. The OS can view each core as a CPU, but can make additional benefits with threads