Producer Consumer Examples by fhy50518

VIEWS: 16 PAGES: 6

									                                                                                                 FIFO’s

                                                             •  Useful interface
                                                                  provide slack to decouple producer and consumer rates
                                                                  provides order preserving buffering
                      CS/ECE 6780/5780                             »  for the case where all produced values are important
                                                                       •  alternative – single memory location
                          Al Davis                                         –  for the case when only the most recent value is needed

                                                                  circular queue is a useful buffered I/O interface
                                                                   »  statically allocated global memory
                                                                       •  aids in controlling memory footprint when resources are limited
                        Today’s topics:                                    –  e.g. as in your lab kits

       • FIFO’s 6812 style                                             •  can be shared by main and ISR’s
                                                                           –  access must be carefully controlled to get it right however
           • hopefully a review?




School of Computing                                             School of Computing
University of Utah
                                1         CS 5780               University of Utah
                                                                                                         2                              CS 5780




      Producer Consumer Examples                                           FIFO w/ Infinite Memory




School of Computing                                             School of Computing
University of Utah
                                3         CS 5780               University of Utah
                                                                                                         4                              CS 5780




                                                    Page 1
                  Basic Code Model                                        2-pointer Finite FIFO Initialization

•  Not robust however




                             What’s missing?

   School of Computing                                                 School of Computing
   University of Utah
                             5                      CS 5780            University of Utah
                                                                                                   6            CS 5780




                 Atomicity Functions                                       Put for a 2-pointer Circular FIFO




                                                                                             Is this correct?
                         What is another way to do this?

   School of Computing                                                 School of Computing
   University of Utah
                             7                      CS 5780            University of Utah
                                                                                                   8            CS 5780




                                                              Page 2
                      Put Example                                            Put Example

     Initially




School of Computing                                    School of Computing
University of Utah
                            9       CS 5780            University of Utah
                                                                                   10      CS 5780




                      Put Example                          Get for a 2-pointer Circular FIFO




School of Computing                                    School of Computing
University of Utah
                            11      CS 5780            University of Utah
                                                                                   12      CS 5780




                                              Page 3
           2-pointer vs. Counter FIFO’s                                      Initialization of a 2-pointer Counter FIFO

•  2 pointer version
     implicit number of elements
       »  how do you calculate how many values are in the queue?
•  Alternative is explicit store of current size
     2-pointer counter FIFO
       »  requires an extra variable – e.g. Size

       »  but has compensating advantages




   School of Computing                                                        School of Computing
   University of Utah
                                      13                  CS 5780             University of Utah
                                                                                                             14                    CS 5780




                         Put Function                                                               Get Function




                                                                                               What advantages come from the Size variable?

   School of Computing                                                        School of Computing
   University of Utah
                                      15                  CS 5780             University of Utah
                                                                                                             16                    CS 5780




                                                                    Page 4
             Yet Another FIFO Option                                       Index FIFO Initialization

•  First two options
     used pointers                                            Same basic idea but w/o pointer weirdness

•  Index FIFO
     accesses elements via array indices




   School of Computing                                         School of Computing
   University of Utah
                                17          CS 5780            University of Utah
                                                                                                18         CS 5780




                       Index FIFO Put                                             Index FIFO Get




   School of Computing                                         School of Computing
   University of Utah
                                19          CS 5780            University of Utah
                                                                                                20         CS 5780




                                                      Page 5
                         FIFO Dynamics                                              SCI Data Flow Graph w/ Two FIFOs




   School of Computing                                                            School of Computing
   University of Utah
                                       21                      CS 5780            University of Utah
                                                                                                        22      CS 5780




                  Concluding Remarks

•  Basic FIFO service
     decouple rate of production from rate of consumption
     ideal size depends on maximum slack between the rates
•  Cost
     some RAM utilization and a few CPU cycles
     note crtical section occupancy
      »  if it’s longer the tp or tc then there is a problem
          •  solution?
•  Real systems have FIFO’s everywhere
     main reason why this lecture had such a narrow focus
     what’s the fundamental reason for this?
•  FIFO’s are concurrent data structures
     touched by main + ISRs or threads
•  Writing correct concurrent data structures can be hard
     if done right then using them is easy

   School of Computing
   University of Utah
                                       23                      CS 5780




                                                                         Page 6

								
To top