CS 162 Midterm 2 Review

lecture 10: scheduling

thread life cycle

Screen Shot 2022-10-23 at 10.19.03 PM.png

Screen Shot 2022-10-23 at 10.20.36 PM.png

performance metrics

other useful metrics

assumptions

scheduling policies

Screen Shot 2022-10-25 at 3.39.08 PM.png

lecture 11: scheduling

scheduling policy goals

  1. minimize average waiting time for IO/interactive tasks (tasks with short CPU bursts)
  2. minimize average completion time
  3. maximize throughput (including minimizing context switching)
  4. remain fair/starvation-free

nice

strict priority scheduling

Screen Shot 2022-10-25 at 10.03.53 PM.png

Screen Shot 2022-10-25 at 10.12.30 PM.png

multi-level feedback queue

rules:

  1. if priority(a) > priority(b), a runs
  2. if == priority, a and b run RR using quantum of queue
  3. a new job always starts at the top of the queue
  4. once the job uses up the time allotment, it moves down a priority (regardless of how many times it gave up the CPU)
    1. prevents gaming the system by inserting IO request just before time quanta to stay on that priority level/queue
  5. after some time, move all the jobs back to the topmost queue (prevents starvation)

lec 12: scheduling - core concepts and classic policies

Linux O(n)

Linux O(1)

Real Time Scheduling

Screen Shot 2022-10-06 at 4.12.34 PM.png

stride scheduling

completely fair scheduler (cfs)

CFS: proportional fair sharing

lecture 13: deadlock

Screen Shot 2022-10-26 at 4.54.33 PM.png

definition

deadlock example

four requirements

  1. mutual exclusion and bounded resources
    1. only one thread at a time can use a resource
  2. hold and wait
    1. thread holding at least one resource is waiting to acquire additional resources held by other threads
  3. no preemption
    1. resources are released only voluntarily by the thread holding the resource, after thread is finished with it
  4. circular wait
    1. there exists a set ${T_1, …, T_n}$ of waiting threads, where T1 waits on T2, T2 waits on T3, …, Tn waits on T1

resource allocation graph

set of threads: $T_1, T_2, …, T_n$

resource types: $R_1, R_2, …, Rn$ with $W_i$ instances

each thread uses:

Screen Shot 2022-10-26 at 5.31.36 PM.png

deadlock detection algorithm

Screen Shot 2022-10-26 at 5.53.37 PM.png

deadlock solutions

deadlock prevention

conditions for success!

  1. provide sufficient resources (mutual exclusion and bounded resources)
    1. virtually infinite memory
  2. abort requests or acquire requests atomically (hold and wait)
    1. request resources atomically

      Screen Shot 2022-10-26 at 5.59.18 PM.png

  3. preempt threads (no preemption)
    1. force threads to give up resources
    2. use database aborts (all of the actions are undone and the transaction is retried) or just retry at a new time
  4. order resources and always acquire resources in the same way (circular wait)
    1. force threads to always request resources in the same order, like x.Acquire() THEN y.Acquire()

deadlock avoidance

three states

banker’s algorithm