Thursday, April 22, 2010

LDD3 notes: Concurrency

My notes while reading Linux Device Drivers 3rd edition.

Reasons to pay attention to concurrency

  • Early kernels had no SMP, no pre-emption -> enough to protect from interrupts
  • SMP and pre-emption both pose similar concurrency requirements, even though you'd be willing to ignore the other one.
  • shared resources -> avoid


semaphores: sema_init, up, down (declare_mutex)

  • read/write semaphore pairs: init_rwsem, [up|down]_[read|write], downgrade_write, trylock
  • semaphores are dangerous as automatic variables


Completions

  • init_completion, wait_for_completion (uninterruptible), complete, complete_all, complete_and_exit (thread)

Spinlocks

  • higher performance than semaphores
  • disables pre-emption on current cpu
  • may not sleep while holding one
  • mutual exclusion with interrupts ok with spin_lock_irqsave, within one function

R/W spinlocks


Lockless data structures: kfifo generic circular buffer


atomic_t, an 24bit integer


atomic bit operations set_bit, clear_bit, change_bit, test_bit, test_and_set


seqlock: data structure versioning and retry on collision


RCU's


SGI lockmeter to measure time spent waiting on locks


No comments:

Post a Comment