midterm

Document Sample
midterm Powered By Docstoc
					                    CSE522
           Advanced Operating Systems
                Midterm Review


                       Fred Kuhns
    (fredk@cse.wustl.edu, http://www.arl.wustl.edu/~fredk)
         Applied Research Laboratory
Department of Computer Science and Engineering
      Washington University in St. Louis
                                  Background


          Central Processing Unit (CPU)
                Arithmetic-Logical Unit
                        (ALU)                   Control Unit




                                                 Device Controller
                    Primary Memory                Device Controller
                                                      Device
                                                   Device Controller
                                                       Device
                                                     Device Controller
                                                         Device
                                                          Device




Fred Kuhns ()                CSE522S: Advanced Operating Systems
                   Example (Simplified) Systems

                            CPU
                             PC       register file
                     L1
                    cache     IR
                                                        ALU
                   (SRAM)
                             PSW
           Cache                                                System               Memory
            Bus                                                  Bus                  Bus              Main
L2 cache                                                                  I/O
                    Bus Interface                                                                    Memory
(SRAM)                                                                   Bridge
                                                                                                     (DRAM)




                                                         I/O Bus                               expansion slots
   Instructions:
     load
     store
     add
     jump                                USB                  Graphics              disk
     I/O read                          controller             adapter             controller
     I/O write

                                             keyboard
                                                                                    disk
                                    mouse

                                                              monitor


 Fred Kuhns ()                      CSE522S: Advanced Operating Systems
                Instruction Cycle with Interrupts

                     Fetch Cycle             Execute Cycle                 Interrupt Cycle




                                             Interrupts
                                              Disabled




                                                              Interrupts
                                                                            Check for &




                                                               Enabled
                     Fetch Next                 Execute
START                                                                         Process
                     Instruction               Instruction
                                                                             Interrupts




                                                 HALT



Fred Kuhns ()           CSE522S: Advanced Operating Systems
                               I/O and Devices

        Processor
                                Device table
              dispatcher                                Device Driver
         (interrupt handler)           X




                                                                 Bus

         command       status          data 0
                                       data 1
           Device Controller
         (firmware and logic)          ...
          Device X                   data N-1




Fred Kuhns ()              CSE522S: Advanced Operating Systems
                          Multi-Processor
• Motivation: Enhanced Performance, Fault Tolerance
• Shared-memory multiprocessor: UMA, NUMA;
    communication using shared memory
• Distributed memory, Multicomputer
    message passing, tightly coupled, high-speed interconnect, No Remote
     Memory Access (NORMA)
• Distributed System
    message passing, loosely coupled, networked computers NORMA
• Interconnection technology
    Bus, cross-bar, network
• Caching - Cache Coherence Problem.
    Write-update, Write-invalidate, Bus snooping
• Structure
    Separate Supervisor, Master/Slave, SMP

   Fred Kuhns ()         CSE522S: Advanced Operating Systems
                            Multi-Processor
• Design issues: Process/Thread model; Expressing and
  controlling concurrency; Kernel Synchronization; Task
  Scheduling; Memory Management; Reliability; Fault
  Tolerance
                     CPU                 CPU                     CPU              CPU
        500MHz    cache   MMU         cache   MMU             cache   MMU      cache   MMU



                                      System/Memory Bus
                                                                                  I/O
   Issues:                                    Main      50ns
                                              Memory                  Bridge   subsystem
   • Memory contention          INT
   • Limited bus BW                                                            ether
                                        System Functions
   • I/O contention                    (timer, BIOS, reset)
   • Cache coherence                                                            scsi
                            Traditional I/O Bus:                               video
                            • 33MHz/32bit (132MB/s)
                            • 66MHz/64bit (528MB/s)
  Fred Kuhns ()            CSE522S: Advanced Operating Systems
                            OS Function
• Functions of an OS:
    Resource management: time and space management; synchronization and
     deadlock handling; accounting and status information
    User Environment: Execution environment; error detection and handling;
     protection and security; fault tolerance and failure recovery
    User friendly Interface: System API
• Three driving concepts:
    Abstraction
    Virtualization
    Resource management
• Design Goals: Manage complexity, Separation of policy and
  mechanism
• Design Approaches: Layered, Monolithic kernel, Microkernel

   Fred Kuhns ()        CSE522S: Advanced Operating Systems
Historical Perspective: UNIX and Monolithic Kernels
  execution
  environment                  application
                   trap                                libraries
   user
   kernel                           System call interface

    System                File subsystem                          IPC
                                                       Process
    Services                 Buffer cache              control scheduler
                                                      subsystem
                   char block                                   memory
                   Device drivers
                                          hardware
   Fred Kuhns ()             CSE522S: Advanced Operating Systems
                    Basic Concepts and Terminology
•   Kernel:
        trusted software component, a privileged address space and direct access to hardware.
•   Process:
        Fundamental abstraction; untrusted application software; assigned own "protected" address space,
         assigned virtualized resource abstractions.
        User credentials: user id and group id.
•   Two privilege levels, or modes: user and system


                                                                            Privileged
                                          mode            user                system
                              context
                                                    Application           System calls
                                  process
                                                    (user code)           Exceptions
                system                                    X                Interrupts
                                   kernel
                space                                not allowed          System tasks


    Fred Kuhns ()                     CSE522S: Advanced Operating Systems
                       Processing Model
• Trap and Interrupt processing
     mechanism for changing from an unprivileged to privileged
      mode (user to system mode)
     indicates both synchronous and asynchronous events
     fundamentally important for I/O
• Synchronization
     re-entrant kernels, interrupt blocking, blocking operations
•   Synchronous versus asynchronous operations
•   Scheduling policies
•   Process event notification
•   Process life cycle
    Fred Kuhns ()      CSE522S: Advanced Operating Systems
        Traditional Address Space Assignments

kernel memory

                             proc struct



kernel stack/u area     kernel stack/u area                 kernel stack/u area
       Stack                   Stack                               Stack


      Data                      Data                              Data
   Text (shared)             Text (shared)                     Text (shared)

  Fred Kuhns ()       CSE522S: Advanced Operating Systems
                                 Process States
                                                                              fork
                                   USER
                                 RUNNING
                                                                        INITIAL
                                                                          IDLE
                   system call,
                                        return
                     interrupt
                                                                       fork
                          exit              swtch()
                                 KERNEL
                ZOMBIE                                  RUNNABLE
                                 RUNNING
                                            swtch()
           wait          sleep()                                       continue
                                                          stop
                                wakeup
                                                stop


                    ASLEEP       stop                              STOPPED


                         continue STOPPED        wakeup
                                    ASLEEP


Fred Kuhns ()                CSE522S: Advanced Operating Systems
Historical Perspective: THE and Layered Systems
• Layered Approach
      Processor Allocation
      Segment controller
      Message Interpreter
      Stream Buffer
      User programs
      Operator and Keyboard
• Relied on semaphores for concurrency control
• Clean interfaces and isolation between layers
• Simplified verification and debugging


  Fred Kuhns ()       CSE522S: Advanced Operating Systems
Historical Perspective: UNIX and Monolithic Kernels
 • See earlier discussion




   Fred Kuhns ()    CSE522S: Advanced Operating Systems
Historical Perspective: RC 4000 and Microkernels
• Hansen and the RC 4000 (The Nucleus of a Multi-programming
  System)
• Dynamic creation of process hierarchies
• System nucleus
    Unambiguous definition of the process abstraction
    Synchronization and IPC
    Rules governing the dynamic creation, termination and control of
     processes
• System services (aka policies) implemented by use level
  processes.
• Primitive operations implemented by trusted kernel
• Communication by message passing between processes (internal
  and external)

   Fred Kuhns ()         CSE522S: Advanced Operating Systems
Historical Perspective: Objects, Protection and Policy
• Hydra
• Development of a system software framework for
  defining and implementing operating systems on multi-
  processor systems
• Generalized the notion of a resource as an object, name
  space, operations and user capabilities (for access and
  control)
• Goal is to create a basic set of facilities to allow for the
  specification and construction of flexible, efficient and
  reliable systems.


   Fred Kuhns ()     CSE522S: Advanced Operating Systems
                              Concurrency
• Properties: Safety, Liveness
• Independent processes: Two processes are independent if the write
  set of each is disjoint from both the read and write sets of the other.
• Race condition: If two or more process access and modify shared
  data concurrently, and the final value of the shared data depends on
  the order in which it was accessed.
• Critical reference: reference to a variable changed by another
  process. Assume the variable is written or read atomically.
• Critical assertion: A pre/post condition that is not in a critical
  section.
• Noninterference: An assignment a and its precondition pre(a) in
  process A does not interfere with a critical assertion C in another
  process if the following is always true.
        {C ^ pre(a)} a {C}
  That is, C is not affected by the execution of a when pre(a) is
  true.

     Fred Kuhns ()        CSE522S: Advanced Operating Systems
                    Avoiding Race Conditions

•    At-Most-Once property:

     If the assignment statement x = e satisfies
    1) e contains at most one critical reference and x is not read by
       another process or
    2) e contains no critical references, in which case x may be
       read by another process.


     In other words, there can be at most one critical
     reference within the expression S: x = e


    Fred Kuhns ()       CSE522S: Advanced Operating Systems
                                                   Critical Section Problem
                       •         Entry/exit protocol satisfies:
                       1.        Mutual Exclusion: At most one process may be
                                 active within the CS                                        Assumption: A process that
                       2.        Absence of deadlock (livelock): if two or more              enters its critical section will
                                 processes attempt to enter CS, at least one will            eventually exit.
                                 succeed.
                                   2 or more processes must not enter into infinite loops
Safety Properties




                                    or other forms of deadlock/livelock.
                                                                                             Task A {
                       3.        Absence of Unnecessary delay: If a process                    while (True) {
                                 attempts to enter CS and the other processes are                entry protocol;
                                 either in their non-critical sections or have                   critical section;
                                 terminated then the process is not prevented from               exit protocol;
                                 entering the CS.                                                non-critical section;
                                                                                                }
                                   processes neither operating in or attempting to enter
                                                                                             }
                                    CS can prevent another process from entering CS.
                       4.        Eventual entry (no starvation, more a function of
   Liveness Property




                                 scheduling): A process attempting to enter CS will
                                 eventually succeed.
                                   One process may not repeatedly enter CS while
                                    another process waits
                            Fred Kuhns ()                  CSE522S: Advanced Operating Systems
                            Mutual Exclusion
• Single Processor versus Multi-processor
    Locked/Waiting (Blocking)
    Wait channels
• Multi-Processor
    Hardware support for atomic operations
    spin-locks and Busy waiting
    Semaphores: mutual exclusion; event notification; and resource counting.
          As locks: ownership transfers to thread when woken.
• Considerations
      Efficiency of synchronization operations/abstractions
      Lost wakeup problem
      Thundering heard problem
      Convoys
• Know example implementations
   Fred Kuhns ()            CSE522S: Advanced Operating Systems
        Synchronization Mechanisms - continued
• Condition variables – event notification, usually has an
  associated predicate and lock to protect predicate. Know proper
  use, example implementation and the difference between signal-
  and-wait and signal-and-continue semantics.
• Read/Write Locks – Understand the different possible behaviors
  with respect to readers and writes.
• Reference Counting – Protects object when there are outstanding
  references
• Considerations
    Deadlock avoidance; Recursive Locks; Adaptive Locks (Mutex)
    Protecting invariants, predicates, data, operations (monitors).
    Granularity and Duration.



   Fred Kuhns ()         CSE522S: Advanced Operating Systems
                   Inter-Process Communication
• Mechanisms: message passing; shared memory
• Message passing
     Processes must establish a communication channel
     Communication channel can be thought of as a queue of messages that have been
      sent but not yet read
     Message passing facility defines two operations on a communication channel:
      send(channel, message) and recv(channel, message)
• Methods for implementing a logical communication link and primitives
  (send/receive):
       Direct or Indirect communications (Naming)
       Symmetric or Asymmetric communications
       Automatic or Explicit buffering
       Send-by-copy or send-by-reference
       fixed or variable sized messages
• Purposes of IPC: Data Transfer: Sharing Data; Event notification; Resource
  Sharing; Process Control
• Review MACH IPC

   Fred Kuhns ()             CSE522S: Advanced Operating Systems
                Universal IPC Facilities


                   handler




   user
   kernel
                                 pipe
                                                      stop
    handle event




Fred Kuhns ()          CSE522S: Advanced Operating Systems
                                  Threads
• Process: encompasses
    set of threads (computational entities)
    collection of resources (i.e. resource ownership)
• Thread: Dynamic object representing an execution path and
  computational state.
    separate the notion of execution from the Process abstraction
• Advantages:
    Exploit multi-processor environments
    Expressing the intrinsic concurrency of a program regardless of resulting
     performance
• Three types: User threads, kernel threads and Light Weight
  Processes (LWP)
• Mach Continuations
• Events versus Threads

   Fred Kuhns ()          CSE522S: Advanced Operating Systems
                                      Scheduling
•   Multiprogrammed Operating System
      maximize utilization by multiplexing the CPU among competing processes.
      goal is to always have some process running
      one process runs until it must wait for some event at which point the OS inserts another
       “ready” process onto the CPU
      In preemptive schemes a process may also be involuntarily suspended so another process
       may be scheduled in its place.
•   Overview of scheduling module:
      Basic Concepts – burst cycle, scheduler, preemption, dispatcher
      Scheduling Criteria: utilization; Throughput; Turnaround time; Waiting time; Response time
      Scheduling Algorithms: FIFO (head-of-line blocking); Shortest-Job-First (SJF); Priority-
       based; Round-robin; Multilevel Queue; Multilevel feedback queue
      Scheduling Issues, Implementations and Mechanisms: Interrupt letancy, clock resolution;
       cost of context switch;
•   General considerations
      Hidden scheduling; Priority Inversion
•   Know BSD scheduler
•   Gang Scheduling on Mach: dedicate one processor per thread; Minimize barrier
    synchronization delay




    Fred Kuhns ()                CSE522S: Advanced Operating Systems
                              Priority Inheritance
• Solaris:
     Each thread has a global and inherited priority.
     Object must keep a reference to the owner
     If requester priority > owner, then owner priority raised to that of the requesters
     This works with Mutexes since owner always known; but not for semaphores or
      condition variables
     For reader/writer,
          owner of record inherits priority, only partial solution
• Mach:
     Inherited base scheduling priority which is combined with a CPU usage factor
     CPU usage factor decayed 5/8 each second inactive
     threads set own priority after waking up.
     Clock handler charges current thread.
     Every 2 seconds, system thread scans run queue and recomputes priorities
      (addresses starvation)
     Fixed quantums, preemptive scheduling
     handoff scheduling - used by IPC


   Fred Kuhns ()                 CSE522S: Advanced Operating Systems
                     Real-Time: Terminology
• Timing constraint: constraint imposed on timing behavior of a job: hard or soft.
• Release Time: Instant of time job becomes available for execution. If all jobs
  are released when the system begins execution, then there is said to be no
  release time.
• Deadline: Instant of time a job's execution is required to be completed. If
  deadline is infinity, then job has no deadline. Absolute deadline is equal to
  release time plus relative deadline.
• Response time: Length of time from release time to instant job completes.
• Hard: failure to meet constraint is a fatal fault. Validated system always meets
  timing constraints (deterministic, probabilistic, utility function)
• Soft: late completion is undesirable but generally not fatal. No validation or
  only demonstrate jobs meet some statistical constraint. Occasional missed
  deadlines or aborted execution is (usually) considered tolerable. Often specified
  in probabilistic terms
• Validation: Demonstration by a provably correct, efficient procedure or by
  exhaustive simulation and testing. Involves three steps: consistent timing
  constraints; individual components in isolation can meet their contraints;
  scheduling algorithm produces valid schedule.

    Fred Kuhns ()          CSE522S: Advanced Operating Systems
                         Real-Time: System Model
•   Modeling the system to focus on timing properties and resource requirements:
      Workload model - describes supported applications
          Task model and Temporal parameters
          Precedence constraints and dependencies
          Functional parameters
      Resource model - describes available system resources
          Modeling resources (Processors and Resources)
          Resource parameters
      Algorithms - how application uses resources at all times
          Scheduling Hierarchy
•   Resources divided into two classes:
      Active resources, or Processors (Pi), execute jobs. Examples include CPUs and data links.
      Passive resource or simply Resource (Ri), are generally managed by the system.
•   Tasks and Jobs:
      Task (Ti): Set of related jobs jointly provide function.
      Job (Jij): Unit of work, scheduled and executed by system. characterized by Temporal
       parameters, Functional parameters, Resource parameters, Interconnection parameters
•   Sporadic Tasks: stream of aperiodic or sporadic jobs.
      Jobs within a task have similar statistical behavior and timing requirements
      Assumed system is stationary within the hyperperiod
      jobs have hard deadlines
•   Aperiodic Tasks: jobs have soft or no deadlines. Generally desire responsiveness.
     Fred Kuhns ()                CSE522S: Advanced Operating Systems
                        Task/Job Parameters
• Assume periodic task model
    The number and parameters of all tasks with hard timing constraints is
     known at all times.
• Task Ti is a serious of periodic Jobs Jij.
      i - phase of Task Ti, equal to ri1
      rij - release time of the jth Job in Task i (Jij in Ti).
      pi - period, minimum inter-release interval between jobs in Task Ti.
      ei - maximum execution time for jobs in task Ti.
      Di - relative deadline
      di - absolute deadline
      (ri, di] - feasible interval
      ui - utilization of Task Ti and is equal to ei/pi.
• System Parameters
    H - Hyperperiod = Least Common Multiple of pi for all i: H =
     lcm(pi), for all i. The number of jobs in a hyperperiod is equal to the
     sum of (H/pi) over all i.
    U - Total utilization = Sum over all ui.

   Fred Kuhns ()           CSE522S: Advanced Operating Systems
                       Task/Job Parameters
• Functional Parameters:
      Preemptivity
      Criticality (Useful during overload)
      Optional Executions (Useful during overload)
      Laxity (Useful during overload)
• Precedence Constraints and Task Graphs
    Jobs are either precedence constrained or independent.
• Precedence relation: partial ordering operator <
    Ji<Jk:Ji is predecessor of Jk, Jk is successor of Ji
    A job is ready when both the time >= its release time and all predecessors
     have completed.
• Resource Parameters:
    Job resource parameters indicate processor and resource requirements
    Preemptivity of resources.
    Resource Graph:



   Fred Kuhns ()          CSE522S: Advanced Operating Systems
                             RT-Scheduling
• Scheduling Paradigms
    static table-driven - static analysis and explicit schedule (table).
    static priority driven - static analysis, no explicit schedule, priorities used
     at runtime.
    dynamic planning based - feasibility check at run-time, schedule
     produced. Result includes schedule.
    dynamic best effort - No feasibility check, attempts to meet deadlines but
     no guarantee.
• Scheduling Algorithms
    Most instances, scheduling problem is intractable
    Resource constrained scheduling is NP-complete. Precedence constraints
     aggravate the problem.
    Heuristics and approximation techniques used to handle tasks with
     complex requirements.


   Fred Kuhns ()           CSE522S: Advanced Operating Systems
                  Earliest Deadline First (EDF)
• EDF: priority driven scheduling algorithm with
  dynamic task (fixed job) priority assignment.
    earlier the deadline, higher the priority
    priorities are assigned on job release
    Jobs placed in run queue by priority
• Assumptions:
    Tasks are preemptable and independent
    Tasks have arbitrary release times, arbitrary deadlines
    Single Processor
• Optimal: EDF can produce a feasible schedule for a set
  of Jobs J if and only if J has a feasible schedule.

  Fred Kuhns ()         CSE522S: Advanced Operating Systems
                  Latest Release Time (LRT)
• Goes "backwards" in time: Treats release times as
  deadlines and deadlines as release times.
    job with latest release time has highest priority
• Assume jobs are preemptable
• May leave processor idle when jobs are ready, so not a
  priority-driven algorithm.
• Optimal: LRT can produce feasible schedule for a set of
  jobs J if and only if feasible schedules for J exist.




  Fred Kuhns ()        CSE522S: Advanced Operating Systems
                  Least Slack Time First (LST)
• LST or Maximum Laxity First (MLF)
• Dispatch job with minimum slack time: smaller slack
  time, higher priority.
• Optimal: Can produce feasible schedules for J if and
  only if feasible schedules for J exist.
• Requires knowledge of execution times, while EDF
  does not.
   Consequently may underutilize processor when using
    maximum (worst-case) analysis.




  Fred Kuhns ()        CSE522S: Advanced Operating Systems
                                       Static Strategies
•   Table Driven
      Typically applied to systems with safety critical requirements.
           Resources preallocated to tasks so that they can meet their deadlines
      Assume tasks are periodic
           feasible schedule iff there exists a feasible schedule for the Hyperperiod
      Rate monotonic (RM) or Earliest deadline first (EDF) scheduling algorithms can be used for
       systems with simple characteristics.
      Complicated by resource requirements along with precedence, exclusion, communication
       and replication constraints.
•   Priority-Driven
      Assigning priority based on RM and EDF.
             single processor, periodic tasks, preemption
             RM: static priorities based on period.
             EDF: dynamic priority based on deadline.
             Advantage is that schedulability analysis based only on utilization constraints.
      May assign priority based on laxity, LLF: Least Laxity First
      May assign priority based on any of the tasks parameters
      Preemptive scheduling may simplify analysis but overhead needs to be considered.
           scheduling algorithm
           task dispatcher
           context switch overhead




    Fred Kuhns ()                     CSE522S: Advanced Operating Systems
                           Dynamic Strategies
• Planning based (for example priority driven):
     Dynamic feasibility checks
     Must consider worst case execution times, resource requirements, timing
      constraints, periodic tasks, preemption, precedence constraints, importance levels
      and fault tolerance
     If task arrival times are not known a priori, cannot guarantee performance
     Various heuristic algorithms for scheduling tasks in a distributed environment.
• Best-effort based (for example Weighted Round Robin)
     Used by many systems: system computes task priorities and schedules
      accordingly. Extensive simulations are used to gain confidence in behavior
     May compensate for other priority driven algorithms (RM) which perform poorly
      in overload conditions
     May use a value function to schedule during overload: maximize sum of task
      values. May also discard low value tasks
     Priority-driven preemptive scheduling
     shortest processing time, EDF, least laxity first, FCFS, random selection,.
     Discard tasks with lowest value function


   Fred Kuhns ()             CSE522S: Advanced Operating Systems
                                   Clock Driven
•     Know advantages and disadvantages
•     Know example implementation of cyclic executive
•     Know how to calculate the Hyperperiod
      1) f ≥ max(ei), 1≤i≤ n
      2) f divides pi for at least one value of i
      3) Between the release time and deadline of every job there is at
      least one frame 2f - gcd(pi, f) ≤ Di

                                        Major Cycle

         Minor Cycle (frame)

              T1 T3 T2          T1 T4             ...                      T1 T3 T2
         f1                f2                                         fn
Cyclic Executive runs in response to a tick event, bar shows time to execute scheduler

    Fred Kuhns ()               CSE522S: Advanced Operating Systems
                            Slack Stealing
• Scheduling aperiodic jobs with periodic jobs
    Foreground jobs => periodic jobs already discussed
    background jobs => aperiodic jobs
    Aperiodic jobs executed within the idle blocks and are preemptable
• May optimize response time by scheduling within slack time
  (slack stealing).
    Slack = f – xk where
     xk = total time allocated to periodic tasks in frame k and
     f = frame size
• Requirements may include some minimal aperiodic arrival rate
• Cyclic Exec executes aperiodic jobs as long as there is slack in
  the schedule. Periodic jobs must complete by deadline.



   Fred Kuhns ()          CSE522S: Advanced Operating Systems
                         Sporadic Jobs
• Sporadic jobs: S(d,e): d = deadline, e = execution time
    hard deadlines, minimum interrelease times and maximum
     execution time are not known in advance
    maximum execution time is known on release
    jobs are preemptable
• Apply an acceptance test at run time
    When job is released, determine if there is a feasible schedule
     that includes this sporadic job
    If no feasible schedule, then reject job and notify application
     of rejection



  Fred Kuhns ()       CSE522S: Advanced Operating Systems
                                        Acceptance test
•   Calculating the available slack time: released in (x - 1), deadline in frame (y + 1)
•   Original slack time between all frame pairs within one major cycle, Q(x, y) for x, y in H.
•   Step 1:
        Assume x is in major cycle j and y is in major cycle k
     Q(x,y) = Q(x,F) + Q(1,y) + [(k - 1) - j]Q(1,F); k > j
     Q(x, y) is known if k = j, y > x.
        Decrease available slack time by required exectime of higher priority jobs:
     Qc(x, y) = Q(x, y) - Sum[dkd; (ek - e'k)]
        If S is accepted, Slack before new sporadic job's deadline:
     Qs = Qc(x, y) – e
     if (Qs < 0) then reject
     else store Qs and continue
•   Step 2:
        Check all jobs with deadlines after d to verify they will not miss their deadlines.
     d = deadline of new sporadic task; e = execution time of new sporadic task
        Let Sk = accepted sporadic task with deadline dk > d.
        Let Qk = calculated slack for sporadic tasks in Sk
        Accept if Step one is valid and the following condition is valid
     Qk - e  0 for all sporadic jobs with dk>d
     If Task is accepted then update Qk of all lower priority jobs.
•   Accept if Steps 1 and 2 are tur
    Fred Kuhns ()                     CSE522S: Advanced Operating Systems
                       Periodic Real-Time
• Event-driven, work-conserving schedulers
• Jobs assigned explicit or implicit priorities
• Algorithm defined by priorities used and a set of rules
  (preemption, priority changes etc).
• Algorithms that consider a jobs urgency generally perform better
  than those that do not.
• Static versus Dynamic assignment of workloads
    for now we only consider the case where a set of tasks are statically
     assigned to a processor.
• Fixed versus Dynamic priority assignment.
    Fixed priority: RM and DM
    Dynamic Task, Fixed Job: EDF
    Dynamic Job: LST (Least Slack First)

  Fred Kuhns ()          CSE522S: Advanced Operating Systems
                            Periodic Concepts
• Schedulable Utilization
    A scheduling algorithm can feasibly schedule any set of periodic tasks
     on a processor if the total utilization of the tasks is equal to or less than
     the schedulable utilization of the algorithm
    Schedulable utilization is necessarily <= 1
• While dynamic priority algorithms have better average
  performance, they are less predictable during overload.
• Schedulable Utilizations of EDF
    if Dk  pk then density = Δ = U, utilization test is both necessary
     and sufficient.
    if Dk < pk for some k then the test is only a sufficient condition.

                                     n
                                           ek
                   Density                       1
                                 k 1 min( Dk , pk )

   Fred Kuhns ()            CSE522S: Advanced Operating Systems
                        Fixed Priority Algorithms
• Rate Monotonic (RM)
     Priorities based on Task period: smaller periods have higher priority.
     if pi < pk (rate of Ti > rate of Tk), then i > k
• Deadline Monotonic (DM)
     Priority based on task deadline: smaller relative deadline, higher priority.
     if Di < Dk, then i > k
• No fixed priority algorithm                              1
                                                                  
                                       (n  1)    1   1, for   2,3,...
                                                         
                                                            n 1

  is optimal                                                 
• Among fixed-priority                                          
                                       
                       U RM (n,  )   n 2 n  1  1   , for 0.5    1
                                                 1
  algorithms, DM                                      
  is optimal                                        
                                              ,           for 0    0.5
• Under special                       
  cases can achieve                   
                                      
   a utilization of 1
                           Sufficient Utilization bounds for RM, Dk =
      Fred Kuhns ()
                           pk
                             CSE522S: Advanced Operating Systems
                                       Concepts
• Central concept for fixed priority systems
    A critical instant of a task is the "instant" in time when a job (in Ti) has
     its maximum response time.
    If a task can be scheduled in its critical instant then it will not miss a
     deadline.
    Occurs when a job in Ti is released concurrently with all higher priority
     jobs.
• Time demand analysis
    Computes total demand for processor time by a job released at a critical
     instant of the task and all higher priority tasks.
    If this worst case response time is less than or equal to the jobs deadline,
     then it is schedulable.
                          i-1
                                     t
           wi(t) = ei +                      ek             w(t)
                          k=1
                                     pk
                   for 0 < t  pi                                     t

   Fred Kuhns ()                CSE522S: Advanced Operating Systems
             Critical Instant: Time demand analysis

 W                                           Decreasing the phase k shifts the
                                             graph up thus increasing the
                               wk,1 = t      response time. Likewise, decreasing
                                             the phases of higher priority jobs
                                             (j) will also increase the job’s
                                             response time. Therefore, the
                                             maximum response time of a job
k                                           occurs when all jobs are in phase.


                                   t
            j

                                       t  j  
                     wk ,1  ek               e j   k
                                      
                                  j k  p j 
                                                        
                                                       

     Fred Kuhns ()          CSE522S: Advanced Operating Systems
               Practical Considerations
• Blocking due to Non-Preemptive: Higher priority job is
  blocked by a lower priority job during a nonpreemptive
  interval resulting in a priority inversion.
• Self Suspension: If higher priority job self-suspends
  then its computation time may be deferred until
  the feasible interval for some other job
• Context Switches
• Limited Priority Levels: N task priorities, S system
  priorities and N != S, then must provide a mapping.
• Tick scheduling: A job may wait on scheduling queue
  when runnable
• Variable priority CSE522S: Advanced Operating Systems
   Fred Kuhns ()
                    Practical Considerations
• Context Switch, assume fixed job priorities.
     we can account for this by increasing a jobs execution time by 2*CS or
      2(K+1)CS if self-suspend K times.
• Updating our tests (must be true for every i):


      bi  bi ( ss )  ( K i  1)bi (np)  2( K i  1)CS
                     n
                           ek              bi
      Deadline :                                    1
                 k 1 min( Dk , pk )   min( Di , pi )
                                                 t  i 1
      Fixed priority : wi (t )  ei  bi     ek
                                           k 1  pk 



   Fred Kuhns ()          CSE522S: Advanced Operating Systems
                    Resource Access Control
• Goals:
   Bound delay due to Priority Inversion and Timing Anomalies
   Prevent Deadlock
• Three Examples:
   Nonpreemptive Critical Sections
         If Ji holds a resource it effectively has the highest priority in the
          system: i.e. it will not be preempted while holding a resource.
         No deadlock, No uncontrolled Priority Inversion
   Priority Inheritance Protocol
         Deadlock, No uncontrolled Priority Inversion
   Priority Ceiling Protocol
         No deadlock, No uncontrolled Priority Inversion


  Fred Kuhns ()            CSE522S: Advanced Operating Systems
                    Priority Inheritance Rules (PI)
• Priority-Inheritance Rule:
    if Ji  Rk  Jm and m(t1-) < i(t1)
    then m(t1+) = i(t1)
    until Jm releases Rk when m(t2+) = m(t1-)
• Assessment:
    simple and works with any priority driven scheduler. Does not
     require foreknowledge. When no deadlock, no unbounded delay.
    Two types of blocking: Direct and Priority Inheritance blocking
    Has the transitive property.
    Does not result in minimal blocking time
    Does not prevent deadlock


    Fred Kuhns ()         CSE522S: Advanced Operating Systems
                    Basic Priority Ceiling Rules
• Extends PI to prevent deadlock and reduce blocking time
• Assumptions:
   – fixed assigned priorities; resource requirements of tasks known
   – priority ceiling for Rk = (Rk)= max(i) for all Ji requiring Rk
   – System priority ceiling = (t) = max[(Rk)] for all Rk in use at time t.
      If no resource in use then (Rk) = 
• Allocation Rule (Ji requests Rk at time t = t1):
   – if Ji  Rk  Jm at t = t1 then block Ji (no change)
   – else (Rk free at t1)
        if i(t1) > (t), then Rk  Ji
        else if for some Rx  Ji and (Rx) = (t1), then Rk  Ji
        else deny and block (Ji  Rk)
• Priority-Inheritance Rule:
   – if Ji blocks on resource Rk held by Jm (Ji  Rk)
        (note: RkJm and m(t1-)=priority of Jm at t = t1-)
      then m(t1+) = i(t1) (inherited priority) until Jm releases all Rx with
      (Rx)(t1) at t = t2 , m(t2+) = m(t1-)

    Fred Kuhns ()         CSE522S: Advanced Operating Systems
           Stack-Based Priority Ceiling Protocol
• Update Current Ceiling in the usual manner
    When no resources are held the (t) = 
    otherwise,
     (t) = max[(Rk)] for all Rk in use at time t.
• Scheduling Rule:
    when Ji released it is blocked until its assigned priority
     i(t) > (t)
    When not blocked jobs are scheduled in a priority-driven,
     preemptive manner according to their assigned priorities.
• Allocation Rule:
    Allocate when requested

  Fred Kuhns ()       CSE522S: Advanced Operating Systems
                   Stack-based Priority Ceiling
• Assume jobs never self suspend
• After a job is released, when it begins to execute all the
  resources it needs are free
• no job is ever blocked once its execution begins
• when a job is preempted, all the resources needed by
  the preempting job are available
• deadlock will not occur
• Has the same worst-case performance as the basic
  priority ceiling protocol



   Fred Kuhns ()        CSE522S: Advanced Operating Systems
                   Terminology for WFQ
• Generalized Processor Sharing (GPS)
    provides server an infinitesimally small time slice of length
     proportional to server size.
    Not practical
• Density of a sporadic job Ji:
      ei = maximum execution time;
      ri = release time;
      di = deadline, density = ei/(di-ri);
      active in feasible interval (ri, di]
• Instantaneous utilization of a sporadic task
    ũi = maxj(eij/pij)
• independent, preemptable sporadic jobs are schedulable
  by EDF if total density <= 1
  Fred Kuhns ()       CSE522S: Advanced Operating Systems
                    Fairness and Starvation
• Fairness
    Consider a system of n servers.
    let wi(t1,t2) equal the processor time used by server Si (i.e. allocated
     processor time) in interval I = (t1, t2] for t2 > t1.
    Normalized service = wi(t1,t2)/ũi; fair if the normalized service of
     all servers differ by no more than a fairness threshold FR>0.
   w i(t1, t2) w j(t1, t2)                     w (t , t )  u
                           FR, if FR  0 then i 1 2  i
       ui          uj                          w j(t1, t2) uj

• Goal is to provide fair access to processor while permitting jobs
  to use an idle processor
• Non-preemptive version used for network packet scheduling
• Jobs are assigned a finish number that represents the round in
  which its deadline occurs (think of this as virtual time).

   Fred Kuhns ()         CSE522S: Advanced Operating Systems
                  Weighted fair queuing: preemptive
• FN = system finish number, Ub = backlogged utilization
• Scheduling
     A server is eligible when it has budget and an assigned finish number
     Priority assigned to eligible servers based on finish number: Server with smallest finish time has
      highest priority
 • Consumption:
       Consume only when running
 • Initialization
       I1: Idle system,
          set FN=0, Ub=0, t-1 = 0; ei,fni = 0 for all i.
       I2: first job arrives to an Idle system for some server FQk
          set t-1 = t, Ub = uk,
          budget ek = e and fnk = e/uk
 • Updating current finish number and replenishment
       R1: job arrives at an idle server FQi, then
         1: increment system FN: FN += (t-t-1)/Ub
         2: set t-1 = t and increment Ub += ui
         3: update FQi: ei = e; fni = FN + e/ui and place in ready queue
       R2: FQi completes a job, remove it from the queue
         if still backlogged: ei = e; fni += e/ui
         else (idle): FN += (t - t-1)/Ub, set t-1 = t; decrement Ub -= ui

      Fred Kuhns ()                CSE522S: Advanced Operating Systems

				
DOCUMENT INFO