SlideShare una empresa de Scribd logo
1 de 30
Operating
Systems
     Lecture 18
Syed Mansoor Sarwar
Agenda for Today
 Review  of previous lecture
 UNIX System V scheduling

 Algorithm evaluation

 Process synchronization

 Recap of lecture

19 September 2012   © Copyright Virtual University of
                              Pakistan
Review of Lecture 17
 Multi-level queues scheduling
 Multi-level feedback queues
  scheduling
 UNIX System V scheduling
  algorithm

19 September 2012   © Copyright Virtual University of
                              Pakistan
UNIX System V
   Scheduling Algorithm
 Every second, the priority number of all
  those processes that are in the main
  memory and ready to run is updated by
  using the following formula:
 Priority# = (Recent CPU Usage)/2 + Thr. Pri.+ nice
 Threshold priority and nice values are
  always positive to prevent a user from
  migrating out of its assigned group
19 September 2012   © Copyright Virtual University of
                              Pakistan
UNIX System V Example
                     PA                          PB                     PC
                          CPU                          CPU                   CPU
        Time Priority     Count          Priority      Count     Priority    Count
                60          0               60            0
    0                                                              60          0
                            1
                           …
                           60
                75         30               60             0
    1                                                      1       60          0
                                                          …
                           30                             60
    2           67         15               75            30       60          0
                                                                               1
                                                                              …
                                                          30
                                                          15                  60
    3           63          7               67                     75
                            8                                                 30
                           …
                           67                                                 30
    4           76         33               63             7
                                                           8
                                                                   67         15
                                                          …
                                                          67
                68
19 September 2012
    5                      16© Copyright Virtual University of
                                           76             33                   7
                                                                   63
                                         Pakistan
Round Robin Scheduling
   and Process Priorities
                  60
Higher Priority




                                                               B

                                     B                         A

                                     A
                       A
                       1             2                         3

                       B      A             B                  B   A runs first
                       A




    19 September 2012      © Copyright Virtual University of
                       4             Pakistan
                                     5                         6
Algorithm Evaluation
 Analytic Evaluation
    The algorithm and some system
     workload are used to produce a
     formula or number which gives the
     performance of the algorithm for that
     workload.
    Deterministic modeling
    Queuing models
 Implementation
19 September 2012   © Copyright Virtual University of
                              Pakistan
Deterministic Modeling
 Predetermined workload and
  performance of each algorithm for
  that workload. Use of Gantt charts.
 Simple and fast
 Exact numbers for comparison
 Requires exact input
 Performance figures may not be
  true in general
19 September 2012   © Copyright Virtual University of
                              Pakistan
Deterministic Modeling
 Process           Arrival Time                         Burst Time
     P1                  0.0                                  7
     P2                  2.0                                  4
     P3                  4.0                                  1
     P4                  5.0                                  4
 Gantt chart
                    P1       P2        P3       P2         P4        P1


                0        2         4        5        7          11        16

19Average waiting time =University of1 + 0 +2)/4 = 3
   September 2012 © Copyright Virtual
                                      (9 +
                                  Pakistan
Queuing Modeling
 Computer system viewed as a
  network of queues and servers:
  ready queue, I/O queue, event
  queues, CPUs, I/O device
  controllers, etc.
 Input: Arrival and service rates
 Output: CPU utilization, average
            queue length, average
            waiting time, …
19 September 2012   © Copyright Virtual University of
                              Pakistan
Queuing Modeling
Little’s Formula:
         n = λ* W
  where
        n = average queue length
        λ = average arrival rate
        W = average waiting time in a
             queue
19 September 2012   © Copyright Virtual University of
                              Pakistan
Queuing Modeling
Let the average job arrival rate be 0.5
Algorithm              Average Wait                     Average Queue
                           Time                           Length(n)
                          W=tw
         FCFS               4.6                              2.3
           SJF                   3.6                         1.8
         SRTF                    3.2                         1.6
      RR (q=1)                   7.0                         3.5
      RR (q=4)
19 September 2012
                                 6.0
                    © Copyright Virtual University of
                                                             3.0
                              Pakistan
Queuing Modeling
 Complicated mathematics
 Distributions (Poisson, uniform,
  exponential, etc) for the arrival and
  departure rates can be difficult to
  work with
 Assumptions may not be accurate
 Approximation of the real system
19 September 2012   © Copyright Virtual University of
                              Pakistan
Simulation
 Programming model for the
  computer system
 Workload generated by
  assuming some distribution and
  a random number generator, or
  by collecting data from the
  actual system.
19 September 2012    © Copyright Virtual University of
                               Pakistan
Simulation
 Characteristics
  Expensive: hours of
   programming and execution
   time
  May be erroneous because
   of the assumptions about
   distributions
19 September 2012    © Copyright Virtual University of
                               Pakistan
Simulation




19 September 2012    © Copyright Virtual University of
                               Pakistan
Implementation
   Best
   Most expensive
        Good option due to Open
         Source kernels such as Linux



19 September 2012   © Copyright Virtual University of
                              Pakistan
Process
               Synchronization
 Concurrent access to shared
  data may result in data
  inconsistency.
 Maintaining data consistency
  requires mechanisms to ensure
  that cooperating processes
  access shared data
  sequentially.
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
   Shared data
   #define BUFFER_SIZE 10
   typedef struct {
          ...
         } item;
    item buffer[BUFFER_SIZE];
    int in = 0, out = 0;
    int counter = 0;
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
Producer process
item nextProduced;
…
while (1) {
   while (counter == BUFFER_SIZE) ;
   buffer[in] = nextProduced;
   in = (in + 1) % BUFFER_SIZE;
   counter++;
}
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
Consumer process
item nextConsumed;
while (1) {
   while (counter == 0) ;
   nextConsumed = buffer[out];
   out = (out + 1) % BUFFER_SIZE;
   counter--;
}
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
 “counter++” in assembly language
 MOV R1, counter
 INC R1
 MOV counter, R1

 “counter--” in assembly language
 MOV R2, counter
 DEC R2
 MOV counter, R2
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
 If both the producer and consumer
  attempt to update the buffer
  concurrently, the machine language
  statements may get interleaved.
 Interleaving depends upon how the
  producer and consumer processes
  are scheduled.
19 September 2012   © Copyright Virtual University of
                              Pakistan
Bounded-Buffer Problem
 Assume counter is initially 5. One
  interleaving of statements is:

  producer: MOV      R1, counter (R1 = 5)
            INC      R1          (R1 = 6)
  consumer: MOV      R2, counter (R2 = 5)
            DEC      R2           (R2 = 4)
  producer: MOV      counter, R1 (counter = 6)
  consumer: MOV      counter, R2 (counter = 4)

 The value of count may be either 4 or
  6, where the correct resultofshould be 5.
 19 September 2012 © Copyright Virtual University
                        Pakistan
Process
             Synchronization
 Race Condition: The situation
  where several processes access
  and manipulate shared data
  concurrently, the final value of the
  data depends on which process
  finishes last.
19 September 2012   © Copyright Virtual University of
                              Pakistan
Process
             Synchronization
 Critical Section: A piece of code
  in a cooperating process in which
  the process may updates shared
  data (variable, file, database, etc.).
 Critical Section Problem:
  Serialize executions of critical
  sections in cooperating processes
19 September 2012   © Copyright Virtual University of
                              Pakistan
Solution of the Critical
       Problem
 Software based solutions
 Hardware based solutions
 Operating system based
  solution


19 September 2012   © Copyright Virtual University of
                              Pakistan
Structure of Solution
do {
                    entry section
                     critical section
                    exit section

                     reminder section
} while (1);
19 September 2012        © Copyright Virtual University of
                                   Pakistan
Recap of Lecture

 UNIX  System V scheduling
 Algorithm evaluation

 Process synchronization

 Recap of lecture



19 September 2012   © Copyright Virtual University of
                              Pakistan
Operating
Systems
     Lecture 18
Syed Mansoor Sarwar

Más contenido relacionado

Destacado

Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronizationcscarcas
 
Synchronization Pradeep K Sinha
Synchronization Pradeep K SinhaSynchronization Pradeep K Sinha
Synchronization Pradeep K SinhaJawwad Rafiq
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems SHATHAN
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...LinkedIn Higher Education
 
Construction equipments - Introduction and Classification
Construction equipments - Introduction and ClassificationConstruction equipments - Introduction and Classification
Construction equipments - Introduction and ClassificationSagar Radadiya
 

Destacado (12)

Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Synchronization Pradeep K Sinha
Synchronization Pradeep K SinhaSynchronization Pradeep K Sinha
Synchronization Pradeep K Sinha
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Unix
UnixUnix
Unix
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...
Everything I Knew about the College Job Hunt Was WRONG - And Here's How You C...
 
Software design
Software designSoftware design
Software design
 
Construction equipments - Introduction and Classification
Construction equipments - Introduction and ClassificationConstruction equipments - Introduction and Classification
Construction equipments - Introduction and Classification
 

Último

"Fly with Ease: Booking Your Flights with Air Europa"
"Fly with Ease: Booking Your Flights with Air Europa""Fly with Ease: Booking Your Flights with Air Europa"
"Fly with Ease: Booking Your Flights with Air Europa"flyn goo
 
Haitian culture and stuff and places and food and travel.pptx
Haitian culture and stuff and places and food and travel.pptxHaitian culture and stuff and places and food and travel.pptx
Haitian culture and stuff and places and food and travel.pptxhxhlixia
 
Inspirational Quotes About Italy and Food
Inspirational Quotes About Italy and FoodInspirational Quotes About Italy and Food
Inspirational Quotes About Italy and FoodKasia Chojecki
 
question 2: airplane vocabulary presentation
question 2: airplane vocabulary presentationquestion 2: airplane vocabulary presentation
question 2: airplane vocabulary presentationcaminantesdaauga
 
Exploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideExploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideTime for Sicily
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)Mazie Garcia
 
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsx
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsxHoi An Ancient Town, Vietnam (越南 會安古鎮).ppsx
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsxChung Yen Chang
 
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)Escort Service
 
Aeromexico Airlines Flight Name Change Policy
Aeromexico Airlines Flight Name Change PolicyAeromexico Airlines Flight Name Change Policy
Aeromexico Airlines Flight Name Change PolicyFlyFairTravels
 
How Safe Is It To Witness Whales In Maui’s Waters
How Safe Is It To Witness Whales In Maui’s WatersHow Safe Is It To Witness Whales In Maui’s Waters
How Safe Is It To Witness Whales In Maui’s WatersMakena Coast Charters
 
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big JuicyDubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big Juicyhf8803863
 
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCRsoniya singh
 
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCRdollysharma2066
 
Authentic Travel Experience 2024 Greg DeShields.pptx
Authentic Travel Experience 2024 Greg DeShields.pptxAuthentic Travel Experience 2024 Greg DeShields.pptx
Authentic Travel Experience 2024 Greg DeShields.pptxGregory DeShields
 
Moroccan Architecture presentation ( Omar & Yasine ).pptx
Moroccan Architecture presentation ( Omar & Yasine ).pptxMoroccan Architecture presentation ( Omar & Yasine ).pptx
Moroccan Architecture presentation ( Omar & Yasine ).pptxOmarOuazzani1
 
Italia Lucca 1 Un tesoro nascosto tra le sue mura
Italia Lucca 1 Un tesoro nascosto tra le sue muraItalia Lucca 1 Un tesoro nascosto tra le sue mura
Italia Lucca 1 Un tesoro nascosto tra le sue murasandamichaela *
 
Where to Stay in Lagos, Portugal.pptxasd
Where to Stay in Lagos, Portugal.pptxasdWhere to Stay in Lagos, Portugal.pptxasd
Where to Stay in Lagos, Portugal.pptxasdusmanghaniwixpatriot
 
Apply Indian E-Visa Process Online (Evisa)
Apply Indian E-Visa Process Online (Evisa)Apply Indian E-Visa Process Online (Evisa)
Apply Indian E-Visa Process Online (Evisa)RanjeetKumar108130
 

Último (20)

"Fly with Ease: Booking Your Flights with Air Europa"
"Fly with Ease: Booking Your Flights with Air Europa""Fly with Ease: Booking Your Flights with Air Europa"
"Fly with Ease: Booking Your Flights with Air Europa"
 
Haitian culture and stuff and places and food and travel.pptx
Haitian culture and stuff and places and food and travel.pptxHaitian culture and stuff and places and food and travel.pptx
Haitian culture and stuff and places and food and travel.pptx
 
Inspirational Quotes About Italy and Food
Inspirational Quotes About Italy and FoodInspirational Quotes About Italy and Food
Inspirational Quotes About Italy and Food
 
question 2: airplane vocabulary presentation
question 2: airplane vocabulary presentationquestion 2: airplane vocabulary presentation
question 2: airplane vocabulary presentation
 
Enjoy ➥8448380779▻ Call Girls In Sector 62 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 62 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 62 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 62 Noida Escorts Delhi NCR
 
Exploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideExploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel Guide
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
 
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsx
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsxHoi An Ancient Town, Vietnam (越南 會安古鎮).ppsx
Hoi An Ancient Town, Vietnam (越南 會安古鎮).ppsx
 
Enjoy ➥8448380779▻ Call Girls In Sector 74 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 74 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 74 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 74 Noida Escorts Delhi NCR
 
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)
69 Girls ✠ 9599264170 ✠ Call Girls In East Of Kailash (VIP)
 
Aeromexico Airlines Flight Name Change Policy
Aeromexico Airlines Flight Name Change PolicyAeromexico Airlines Flight Name Change Policy
Aeromexico Airlines Flight Name Change Policy
 
How Safe Is It To Witness Whales In Maui’s Waters
How Safe Is It To Witness Whales In Maui’s WatersHow Safe Is It To Witness Whales In Maui’s Waters
How Safe Is It To Witness Whales In Maui’s Waters
 
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big JuicyDubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
 
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR
(8264348440) 🔝 Call Girls In Nand Nagri 🔝 Delhi NCR
 
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR
8377087607 Full Enjoy @24/7 Call Girls in INA Market Dilli Hatt Delhi NCR
 
Authentic Travel Experience 2024 Greg DeShields.pptx
Authentic Travel Experience 2024 Greg DeShields.pptxAuthentic Travel Experience 2024 Greg DeShields.pptx
Authentic Travel Experience 2024 Greg DeShields.pptx
 
Moroccan Architecture presentation ( Omar & Yasine ).pptx
Moroccan Architecture presentation ( Omar & Yasine ).pptxMoroccan Architecture presentation ( Omar & Yasine ).pptx
Moroccan Architecture presentation ( Omar & Yasine ).pptx
 
Italia Lucca 1 Un tesoro nascosto tra le sue mura
Italia Lucca 1 Un tesoro nascosto tra le sue muraItalia Lucca 1 Un tesoro nascosto tra le sue mura
Italia Lucca 1 Un tesoro nascosto tra le sue mura
 
Where to Stay in Lagos, Portugal.pptxasd
Where to Stay in Lagos, Portugal.pptxasdWhere to Stay in Lagos, Portugal.pptxasd
Where to Stay in Lagos, Portugal.pptxasd
 
Apply Indian E-Visa Process Online (Evisa)
Apply Indian E-Visa Process Online (Evisa)Apply Indian E-Visa Process Online (Evisa)
Apply Indian E-Visa Process Online (Evisa)
 

os lacture

  • 1. Operating Systems Lecture 18 Syed Mansoor Sarwar
  • 2. Agenda for Today  Review of previous lecture  UNIX System V scheduling  Algorithm evaluation  Process synchronization  Recap of lecture 19 September 2012 © Copyright Virtual University of Pakistan
  • 3. Review of Lecture 17  Multi-level queues scheduling  Multi-level feedback queues scheduling  UNIX System V scheduling algorithm 19 September 2012 © Copyright Virtual University of Pakistan
  • 4. UNIX System V Scheduling Algorithm  Every second, the priority number of all those processes that are in the main memory and ready to run is updated by using the following formula: Priority# = (Recent CPU Usage)/2 + Thr. Pri.+ nice  Threshold priority and nice values are always positive to prevent a user from migrating out of its assigned group 19 September 2012 © Copyright Virtual University of Pakistan
  • 5. UNIX System V Example PA PB PC CPU CPU CPU Time Priority Count Priority Count Priority Count 60 0 60 0 0 60 0 1 … 60 75 30 60 0 1 1 60 0 … 30 60 2 67 15 75 30 60 0 1 … 30 15 60 3 63 7 67 75 8 30 … 67 30 4 76 33 63 7 8 67 15 … 67 68 19 September 2012 5 16© Copyright Virtual University of 76 33 7 63 Pakistan
  • 6. Round Robin Scheduling and Process Priorities 60 Higher Priority B B A A A 1 2 3 B A B B A runs first A 19 September 2012 © Copyright Virtual University of 4 Pakistan 5 6
  • 7. Algorithm Evaluation  Analytic Evaluation  The algorithm and some system workload are used to produce a formula or number which gives the performance of the algorithm for that workload.  Deterministic modeling  Queuing models  Implementation 19 September 2012 © Copyright Virtual University of Pakistan
  • 8. Deterministic Modeling  Predetermined workload and performance of each algorithm for that workload. Use of Gantt charts.  Simple and fast  Exact numbers for comparison  Requires exact input  Performance figures may not be true in general 19 September 2012 © Copyright Virtual University of Pakistan
  • 9. Deterministic Modeling  Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  Gantt chart P1 P2 P3 P2 P4 P1 0 2 4 5 7 11 16 19Average waiting time =University of1 + 0 +2)/4 = 3 September 2012 © Copyright Virtual (9 + Pakistan
  • 10. Queuing Modeling  Computer system viewed as a network of queues and servers: ready queue, I/O queue, event queues, CPUs, I/O device controllers, etc.  Input: Arrival and service rates  Output: CPU utilization, average queue length, average waiting time, … 19 September 2012 © Copyright Virtual University of Pakistan
  • 11. Queuing Modeling Little’s Formula: n = λ* W where n = average queue length λ = average arrival rate W = average waiting time in a queue 19 September 2012 © Copyright Virtual University of Pakistan
  • 12. Queuing Modeling Let the average job arrival rate be 0.5 Algorithm Average Wait Average Queue Time Length(n) W=tw FCFS 4.6 2.3 SJF 3.6 1.8 SRTF 3.2 1.6 RR (q=1) 7.0 3.5 RR (q=4) 19 September 2012 6.0 © Copyright Virtual University of 3.0 Pakistan
  • 13. Queuing Modeling  Complicated mathematics  Distributions (Poisson, uniform, exponential, etc) for the arrival and departure rates can be difficult to work with  Assumptions may not be accurate  Approximation of the real system 19 September 2012 © Copyright Virtual University of Pakistan
  • 14. Simulation  Programming model for the computer system  Workload generated by assuming some distribution and a random number generator, or by collecting data from the actual system. 19 September 2012 © Copyright Virtual University of Pakistan
  • 15. Simulation  Characteristics Expensive: hours of programming and execution time May be erroneous because of the assumptions about distributions 19 September 2012 © Copyright Virtual University of Pakistan
  • 16. Simulation 19 September 2012 © Copyright Virtual University of Pakistan
  • 17. Implementation  Best  Most expensive  Good option due to Open Source kernels such as Linux 19 September 2012 © Copyright Virtual University of Pakistan
  • 18. Process Synchronization  Concurrent access to shared data may result in data inconsistency.  Maintaining data consistency requires mechanisms to ensure that cooperating processes access shared data sequentially. 19 September 2012 © Copyright Virtual University of Pakistan
  • 19. Bounded-Buffer Problem Shared data #define BUFFER_SIZE 10 typedef struct { ... } item; item buffer[BUFFER_SIZE]; int in = 0, out = 0; int counter = 0; 19 September 2012 © Copyright Virtual University of Pakistan
  • 20. Bounded-Buffer Problem Producer process item nextProduced; … while (1) { while (counter == BUFFER_SIZE) ; buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++; } 19 September 2012 © Copyright Virtual University of Pakistan
  • 21. Bounded-Buffer Problem Consumer process item nextConsumed; while (1) { while (counter == 0) ; nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; } 19 September 2012 © Copyright Virtual University of Pakistan
  • 22. Bounded-Buffer Problem  “counter++” in assembly language MOV R1, counter INC R1 MOV counter, R1  “counter--” in assembly language MOV R2, counter DEC R2 MOV counter, R2 19 September 2012 © Copyright Virtual University of Pakistan
  • 23. Bounded-Buffer Problem  If both the producer and consumer attempt to update the buffer concurrently, the machine language statements may get interleaved.  Interleaving depends upon how the producer and consumer processes are scheduled. 19 September 2012 © Copyright Virtual University of Pakistan
  • 24. Bounded-Buffer Problem  Assume counter is initially 5. One interleaving of statements is: producer: MOV R1, counter (R1 = 5) INC R1 (R1 = 6) consumer: MOV R2, counter (R2 = 5) DEC R2 (R2 = 4) producer: MOV counter, R1 (counter = 6) consumer: MOV counter, R2 (counter = 4)  The value of count may be either 4 or 6, where the correct resultofshould be 5. 19 September 2012 © Copyright Virtual University Pakistan
  • 25. Process Synchronization  Race Condition: The situation where several processes access and manipulate shared data concurrently, the final value of the data depends on which process finishes last. 19 September 2012 © Copyright Virtual University of Pakistan
  • 26. Process Synchronization  Critical Section: A piece of code in a cooperating process in which the process may updates shared data (variable, file, database, etc.).  Critical Section Problem: Serialize executions of critical sections in cooperating processes 19 September 2012 © Copyright Virtual University of Pakistan
  • 27. Solution of the Critical Problem  Software based solutions  Hardware based solutions  Operating system based solution 19 September 2012 © Copyright Virtual University of Pakistan
  • 28. Structure of Solution do { entry section critical section exit section reminder section } while (1); 19 September 2012 © Copyright Virtual University of Pakistan
  • 29. Recap of Lecture  UNIX System V scheduling  Algorithm evaluation  Process synchronization  Recap of lecture 19 September 2012 © Copyright Virtual University of Pakistan
  • 30. Operating Systems Lecture 18 Syed Mansoor Sarwar