[CSE]  Advanced Operating Systems 
 COMP9242 2002/S2 
UNSW

PRINTER Printer-Friendly Version
Administration               
- Notices
- Course Intro
- Consultations
# On-line Survey (closed)
- Survey Results
 
Work
- Lectures
- Milestone 0
- Project Admin
- Project Spec
- Project FAQ
- Exam
 
Documentation
- ASysT Lab
- L4 source browser
- Sulima ISA Simulator
R4x00 ISA Summary 
MIPS R4700 ReferenceMIPS R4000 User Manual 
- Network Driver
- GT64111
 
Related Info
- Aurema OS Prize
- OS Hall of Fame
 
History
- 2000
- 1999
- 1998
 
Staff
- Gernot Heiser (LiC)

 
Valid HTML 4.0!
next up previous
Next: Locking: Performance Considerations Up: 10-smp Previous: Spin locks

Subsections

Dangers of Locking: Priority Inversion


  • Assume \({\mbox{prio}}(P_1)<{\mbox{prio}}(P_2)<{\mbox{prio}}(P_3)\), all running on same CPU.

    lock-pi


  • \(P_2\) prevents higher-priority process \(P_3\) from executing.

  • Solution: Avoid preempting processes holding a kernel lock.
    • How?

Solution: Priority inheritance


  • Blocked high-prio process helps locker by donating time slices.


    lock-wf


  • Also called wait-free locking[CSL$^+$87].
    • Everything needs to be prioritised.
    • Need to record holder of lock.
    • No good if \(P_1\) holds lock too long.

Wait-free synch. of long critical sections:

  • Multiprocessor priority-inheritance protocol [HH01]
    • cross-CPU helping: \(B\) holds lock, \(A\) helps \(B\)

    • remote helping: \(A\) migrates to \(B\)'s CPU
      • only works if \(A\) becomes highest-prio on \(B\)'s CPU
      • need global ``end-to-end'' prio scheme
      • otherwise not wait-free
      • race condition: \(A\) migrates to \(B\), \(B\) migrates away...

    • local helping: \(A\) execute's \(B\)'s code on own CPU
      • \(B\)'s state must migrate to \(A\)'s CPU
      • totally wait-free: highest-prio always makes progress

Alternative: Lock-free synchronisation:

  • Ensure all data is always consistent
  • Perform changes on shadow copies
  • When completed, perform atomic swap
    • eg swap pointers with atomic compare-and-swap instruction
    • use mp_spinlock if no such instruction
  • practically limited to simple data structures (linked lists)

Best to avoid long critical sections in kernel!

What to lock?

Giant lock:
lock whole kernel.
  • Only one process can execute in kernel.
  • Similar to dedicated OS processor.
Coarse-grain locks:
lock whole subsystems.
  • E.g., all TCBs, file system.
  • Marginal improvement over giant lock, not scalable.
Fine-grain locks:
lock as little as possible at a time.
  • Potential for large amount of parallelism.
  • Only suitable approach for large numbers of CPUs.

All but giant locks can lead to deadlocks!

  • Usual deadlock-avoidance schemes apply (numbering locks).
  • May not always know in advance which locks are needed.
    • Release lock temporarily to obtain lower-numbered one.
    • Must leave DS consistent when releasing.
    • Must recheck state after reacquiring.


next up previous
Next: Locking: Performance Considerations Up: 10-smp Previous: Spin locks
Gernot Heiser 2002-10-11