COMP 3511: Lecture 12

Date: 2024-10-15 14:35:33

Reviewed:

Topic / Chapter:

summary

❓Questions

Notes

CPU Scheduling Algorithms (cont.)
gantt
    A task          :a1, 1, 30s
    Another task    :a2, after a1, 20s
    Another task    :a3, after a2, 20s
    Another task    :a4, after a3, 20s
    axisFormat %S
  • SJF: can either be preemptive / non=preemptive

  • what if: new process arrives while another is executing?

    • CPU: might switch to new process (if w/ shorter remaining time)
  • SRJF: SJF, but preemptive

  • example

    processarrivalburst
    08
    14
    29
    35
    • 01_SRJF_chart
    • average waiting time:
  • SJF/SRTF and FCFS comparison

    • possible: results in starving
      • process w/ long burst time might keep delayed
    - 
    
  • Priority scheduling

    • priority no.: associated w each process
    • CPU: allocated to process w/ highest priority (= smallest integer)
      • preemptive
      • non-preemptive
    • equal-priority process: scheduled in FCFS
    • SJF: special case of priority scheduling algorithm
      • priority: inverse of predicted next CPU burst
    • problem: starvation: low priority process never executing
    • solution: aging: as time progresses, priority process
      • other solutions exist
      • 👨‍🏫 or: periodically update the priority
    • example
      processburstpriority
      103
      11
      24
      15
      52
      • 02_priority
      • average waiting time: 8.2 msec
      • when 2 ms quantum applied, w/ RR:
        • 👨‍🏫 combination between priority and RR!
        • 03_priority_RR
  • Multilevel queue

    • multilevel queue scheduling: can be extension of priority scheduling
      • e.g. priority assigned statically
      • process: remains in the same queue for duration of runtime
      • 04_priority_mlq
    • partition processes: depending on process type
      • scheduling among queues: commonly implemented w/ fixed priority preemptive scheduling
        • each queue w/ certain CPU time / time-slice
  • Multilevel feedback queue (MLFQ)

    • process: move between various guess
      • aging: implemented this way
      • supports flexibility
    • following parameters
      • no. of queues
      • scheduling algorithms for each queue
      • method to determine when to upgrade / demote a process
      • method to determining which queue to enqueue process
    • example
      • three queues
        • : RR w/ ms
        • : RR w/ ms
        • : FCFS
      • scheduling
        • new job entering : served FCFS
          • preempts jobs from if they are running
          • if it doesn't finish in 8 ms: enqueue process to
        • : served FCFS and receives 16 ms
          • if it doesn't complete: enqueue process to
        • if: a job from : preemptive by a new job of higher queue
          • remains at the front of that queue (w/ remaining quantum)
      • approximates SRTF
        • CPU bound jobs: drop quickly
        • short-running IO bound: stays near top
      • 👨‍🏫 running on a CPU: means that queues above are empty
        • upon preemption: interrupted process still stays front of the queue
        • when prioritized process ends: (i.e. priority returns to second queue)
          • then the interrupted process continues its remaining time quantum
  • Computation

    • turnaround time: termination time - arrival time
    • waiting time: turnaround time - CPU burst time
---
  displayMode: compact
  ---
  gantt
      axisFormat  %S
      Requirements  :a1, 1, 4s
      Design  :a2, after a1, 4s
      Development  :a3, after a2, 4s
      Test  :a4, after a3, 4s
  • MLFQ: Remarks

    • MLFQ: commonly used in many systems (unix, Solaris, Windows, etc.)
    • w/ distinctive advantages
      • no need for prediction of CPU burst time
      • handles interactive jobs well
        • better than RR in terms of response time
        • i.e. first quantum
      • produces similar performance w/ SJF / SRTF
        • short jobs: finish at Q0
        • SJF / SRTF: theoretical & optimal
          • MLFQ: practical & approximates
        • fair: on performance for CPU-bound jobs
          • no "complete" starvation
      • possible starvation: handled by reshuffling jobs to different queues
        • e.g. after some period: move all jobs to top queue
        • 👨‍🎓 shake!
      • 👨‍🏫 wonderful (& best) principle!
        • no, or very little overhead!
    • ❓ is there any criteria for quantum 1, 2, etc. in MLFQ?
      • first quantum: 7-80%
      • second: somewhat of a buffering - until it goes to FCFS
      • design: must be considered carefully
        • 2 level: may be better than 3-4
        • CPU intensive environment, e.g. ML, has different consideration w/ DB query handler
Other Scheduling
  • Thread scheduling

    • user thread: handled by programs
    • no scheduler needed for on-to-one mapping
    • yet: many-to-one or many-to-(smaller) many: requires scheduling on thread
      • i.e. which task is mapped to thread currently?
    • OS: uses intermediate data structure: lightweight process (LWP)
      • between user threads & kernel threads
    • programmer: assigns thread priority in program
  • Multiple-processor scheduling

    • asymmetric: not to be discussed
      • i.e. when one processor acts as a master
    • symmetric multiprocessing (SMP)
      • each processor: either self-scheduling or w/ one common ready queue
        • e.g. one line for all counter (airport) / each counter (supermarket)
        • both are common for SMP
      • 05_multicore_ready_queue