Synthesis A Lock-Free Multiprocessor OS Kernel Josh Triplett April - - PowerPoint PPT Presentation

synthesis
SMART_READER_LITE
LIVE PREVIEW

Synthesis A Lock-Free Multiprocessor OS Kernel Josh Triplett April - - PowerPoint PPT Presentation

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary Synthesis A Lock-Free Multiprocessor OS Kernel Josh Triplett April 19, 2006 Locking a Linked List Implementing a Spinlock Atomic


slide-1
SLIDE 1

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synthesis

A Lock-Free Multiprocessor OS Kernel Josh Triplett April 19, 2006

slide-2
SLIDE 2

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Typical OS data structure code

Prepend an element to a linked list: node->next = head; head = node;

slide-3
SLIDE 3

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Typical OS data structure code

Prepend an element to a linked list: node->next = head; head = node;

slide-4
SLIDE 4

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Typical OS data structure code

Prepend an element to a linked list: node->next = head; head = node;

slide-5
SLIDE 5

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 node->next = head; node->next = head; head = node; head = node;

slide-6
SLIDE 6

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 node->next = head; node->next = head; head = node; head = node;

slide-7
SLIDE 7

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 node->next = head; node->next = head; head = node; head = node;

slide-8
SLIDE 8

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 node->next = head; node->next = head; head = node; head = node;

slide-9
SLIDE 9

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 node->next = head; node->next = head; head = node; head = node;

slide-10
SLIDE 10

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-11
SLIDE 11

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-12
SLIDE 12

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-13
SLIDE 13

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-14
SLIDE 14

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-15
SLIDE 15

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable interrupts

local_irq_disable(); node->next = head; head = node; local_irq_enable();

  • Incredibly cheap
  • Couple of instructions
slide-16
SLIDE 16

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-17
SLIDE 17

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-18
SLIDE 18

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-19
SLIDE 19

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-20
SLIDE 20

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-21
SLIDE 21

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-22
SLIDE 22

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling interrupts

  • Only for short critical sections
  • Leave them off too long:
  • Losing hardware interrupts
  • “Why does my clock run slow?”
  • Coarse-grained (only one “lock”)
  • Insufficient for multiprocessors
  • Still need real synchronization
slide-23
SLIDE 23

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-24
SLIDE 24

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-25
SLIDE 25

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-26
SLIDE 26

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-27
SLIDE 27

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-28
SLIDE 28

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-29
SLIDE 29

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Disable software interrupts

local_bh_disable(); node->next = head; head = node; local_bh_enable();

  • Queue up interrupts
  • Handle when re-enabled
  • Don’t lose hardware interrupts
slide-30
SLIDE 30

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-31
SLIDE 31

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-32
SLIDE 32

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-33
SLIDE 33

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-34
SLIDE 34

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-35
SLIDE 35

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-36
SLIDE 36

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-37
SLIDE 37

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Problems with disabling software interrupts

  • More expensive
  • Queue maintenance
  • Doesn’t protect against access from hardware interrupts
  • Still only for short critical sections
  • Can cause process hangs if not released
  • Coarse-grained (still only one “lock”)
  • Still insufficient for multiprocessors
  • Still need real synchronization
slide-38
SLIDE 38

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-39
SLIDE 39

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-40
SLIDE 40

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-41
SLIDE 41

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-42
SLIDE 42

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-43
SLIDE 43

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-44
SLIDE 44

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-45
SLIDE 45

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-46
SLIDE 46

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Busywaiting with a spinlock

static DEFINE_SPINLOCK(list_lock); spin_lock(&list_lock); node->next = head; head = node; spin_unlock(&list_lock);

  • Assumes every thread has a processor
  • Nothing better to do than wait
  • Spinning impacts other processors
  • Variants reduce impact, add queuing overhead
slide-47
SLIDE 47

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-48
SLIDE 48

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-49
SLIDE 49

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-50
SLIDE 50

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-51
SLIDE 51

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-52
SLIDE 52

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-53
SLIDE 53

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-54
SLIDE 54

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Blocking with a semaphore

static DECLARE_MUTEX(list_lock); while(down_interruptible(&list_lock) == -EINTR) ; node->next = head; head = node; up(&list_lock);

  • Queuing overhead
  • Goes through scheduler
  • Can block
slide-55
SLIDE 55

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential Correctness Problems with Mutual Exclusion

  • Deadlocks
  • Priority Inversion
slide-56
SLIDE 56

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential Correctness Problems with Mutual Exclusion

  • Deadlocks
  • Priority Inversion
slide-57
SLIDE 57

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-58
SLIDE 58

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-59
SLIDE 59

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-60
SLIDE 60

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-61
SLIDE 61

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-62
SLIDE 62

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking summary

  • Provides correctness (if used correctly)
  • Adds overhead
  • Causes problems
  • Various different tradeoffs
  • Alternatives?
  • Shared data structures need synchronization, right?
slide-63
SLIDE 63

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Spinlock implementation

A first attempt: void spin_lock(spinlock_t *lock) { while(lock->counter != 0) ; lock->counter = 1; }

slide-64
SLIDE 64

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Spinlock implementation

A first attempt: void spin_lock(spinlock_t *lock) { while(lock->counter != 0) ; lock->counter = 1; }

slide-65
SLIDE 65

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Spinlock implementation

A first attempt: void spin_lock(spinlock_t *lock) { while(lock->counter != 0) ; lock->counter = 1; }

slide-66
SLIDE 66

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 while(lock->counter != 0) ; while(lock->counter != 0) ; lock->counter = 1; lock->counter = 1;

slide-67
SLIDE 67

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 while(lock->counter != 0) ; while(lock->counter != 0) ; lock->counter = 1; lock->counter = 1;

slide-68
SLIDE 68

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 while(lock->counter != 0) ; while(lock->counter != 0) ; lock->counter = 1; lock->counter = 1;

slide-69
SLIDE 69

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 while(lock->counter != 0) ; while(lock->counter != 0) ; lock->counter = 1; lock->counter = 1;

slide-70
SLIDE 70

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Potential race condition

Thread 1 Thread 2 while(lock->counter != 0) ; while(lock->counter != 0) ; lock->counter = 1; lock->counter = 1;

slide-71
SLIDE 71

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Fixing this race condition?

  • Can’t just disable interrupts: insufficient for multiprocessors
  • Can’t use semaphores: we don’t want to block
slide-72
SLIDE 72

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Fixing this race condition?

  • Can’t just disable interrupts: insufficient for multiprocessors
  • Can’t use semaphores: we don’t want to block
slide-73
SLIDE 73

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking the lock

void spin_lock(spinlock_t *lock) { spin_lock(lock->lock); while(lock->counter != 0) ; lock->counter = 1; spin_unlock(lock->lock); }

slide-74
SLIDE 74

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Locking the lock

void spin_lock(spinlock_t *lock) { spin_lock(lock->lock); while(lock->counter != 0) ; lock->counter = 1; spin_unlock(lock->lock); } Something wrong here!

slide-75
SLIDE 75

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Fixing the semaphore

  • Alternatives?
  • Shared data structures need synchronization, right?
slide-76
SLIDE 76

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Fixing the semaphore

  • Alternatives?
  • Shared data structures need synchronization, right?
slide-77
SLIDE 77

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Atomic instructions

  • One instruction, indivisible
  • Bus locking protocols
  • No interleaving
  • What do we have available?
slide-78
SLIDE 78

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Atomic instructions

  • One instruction, indivisible
  • Bus locking protocols
  • No interleaving
  • What do we have available?
slide-79
SLIDE 79

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Atomic instructions

  • One instruction, indivisible
  • Bus locking protocols
  • No interleaving
  • What do we have available?
slide-80
SLIDE 80

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Atomic instructions

  • One instruction, indivisible
  • Bus locking protocols
  • No interleaving
  • What do we have available?
slide-81
SLIDE 81

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Test and set

  • Set value to 1, return previous value

void spin_lock(spinlock_t *lock) { while(atomic_test_and_set(lock->counter)) ; }

slide-82
SLIDE 82

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Exchange

  • Swap two values atomically
  • Can implement test and set with exchange:
  • Exchange with variable containing 1
  • Return variable
slide-83
SLIDE 83

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Exchange

  • Swap two values atomically
  • Can implement test and set with exchange:
  • Exchange with variable containing 1
  • Return variable
slide-84
SLIDE 84

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Exchange

  • Swap two values atomically
  • Can implement test and set with exchange:
  • Exchange with variable containing 1
  • Return variable
slide-85
SLIDE 85

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Exchange

  • Swap two values atomically
  • Can implement test and set with exchange:
  • Exchange with variable containing 1
  • Return variable
slide-86
SLIDE 86

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synchronization from atomic instructions

  • Fundamental synchronization mechanism
  • Build synchronization abstractions on them
  • Build OS data structures on the synchronization abstractions
slide-87
SLIDE 87

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synchronization from atomic instructions

  • Fundamental synchronization mechanism
  • Build synchronization abstractions on them
  • Build OS data structures on the synchronization abstractions
slide-88
SLIDE 88

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synchronization from atomic instructions

  • Fundamental synchronization mechanism
  • Build synchronization abstractions on them
  • Build OS data structures on the synchronization abstractions
slide-89
SLIDE 89

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Abstractions?

From the Exokernel paper: The exokernel architecture is founded on and motivated by a single, simple, and old observation: the lower the level of a primitive, the more efficiently it can be implemented, and the more latitude it grants to implementors of higher-level abstractions.

slide-90
SLIDE 90

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Using atomic instructions directly?

  • Skip implementing synchronization abstractions
  • Build OS data structures on atomic instructions
slide-91
SLIDE 91

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Using atomic instructions directly?

  • Skip implementing synchronization abstractions
  • Build OS data structures on atomic instructions
slide-92
SLIDE 92

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list revisited

Prepend an element to a linked list: node->next = head; head = node;

  • What would work here?
  • Atomic arithmetic doesn’t help
  • Atomic test and set doesn’t help
  • Would atomic exchange work?
slide-93
SLIDE 93

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list revisited

Prepend an element to a linked list: node->next = head; head = node;

  • What would work here?
  • Atomic arithmetic doesn’t help
  • Atomic test and set doesn’t help
  • Would atomic exchange work?
slide-94
SLIDE 94

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list revisited

Prepend an element to a linked list: node->next = head; head = node;

  • What would work here?
  • Atomic arithmetic doesn’t help
  • Atomic test and set doesn’t help
  • Would atomic exchange work?
slide-95
SLIDE 95

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list revisited

Prepend an element to a linked list: node->next = head; head = node;

  • What would work here?
  • Atomic arithmetic doesn’t help
  • Atomic test and set doesn’t help
  • Would atomic exchange work?
slide-96
SLIDE 96

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list with exchange?

node->next = node; atomic_exchange(node->next, head)

  • This won’t work.
  • It references two memory operands
  • Atomic exchange can only handle one memory operand
slide-97
SLIDE 97

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list with exchange?

node->next = node; atomic_exchange(node->next, head)

  • This won’t work.
  • It references two memory operands
  • Atomic exchange can only handle one memory operand
slide-98
SLIDE 98

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list with exchange?

node->next = node; atomic_exchange(node->next, head)

  • This won’t work.
  • It references two memory operands
  • Atomic exchange can only handle one memory operand
slide-99
SLIDE 99

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list with exchange?

node->next = node; atomic_exchange(node->next, head)

  • This won’t work.
  • It references two memory operands
  • Atomic exchange can only handle one memory operand
slide-100
SLIDE 100

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Linked list with exchange?

node->next = node; atomic_exchange(node->next, head)

  • This won’t work.
  • It references two memory operands
  • Atomic exchange can only handle one memory operand
slide-101
SLIDE 101

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

How to fix linked list?

  • Can’t reference two memory operands
  • Need to change head in memory
  • Need to verify head still has previous value
  • If we load head separately, we can race
  • How can we do this with one instruction?
slide-102
SLIDE 102

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

How to fix linked list?

  • Can’t reference two memory operands
  • Need to change head in memory
  • Need to verify head still has previous value
  • If we load head separately, we can race
  • How can we do this with one instruction?
slide-103
SLIDE 103

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

How to fix linked list?

  • Can’t reference two memory operands
  • Need to change head in memory
  • Need to verify head still has previous value
  • If we load head separately, we can race
  • How can we do this with one instruction?
slide-104
SLIDE 104

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

How to fix linked list?

  • Can’t reference two memory operands
  • Need to change head in memory
  • Need to verify head still has previous value
  • If we load head separately, we can race
  • How can we do this with one instruction?
slide-105
SLIDE 105

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

How to fix linked list?

  • Can’t reference two memory operands
  • Need to change head in memory
  • Need to verify head still has previous value
  • If we load head separately, we can race
  • How can we do this with one instruction?
slide-106
SLIDE 106

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-107
SLIDE 107

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-108
SLIDE 108

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-109
SLIDE 109

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-110
SLIDE 110

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-111
SLIDE 111

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-112
SLIDE 112

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-113
SLIDE 113

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Swap

Atomically: CAS(register old, register new, memory location) { if(*location == old) { *location = new; return SUCCEED; } return FAIL; }

slide-114
SLIDE 114

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free linked list

do { node->next = old_head = head; } while(CAS(old_head, node, &head) == FAIL);

slide-115
SLIDE 115

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free linked list

do { node->next = old_head = head; } while(CAS(old_head, node, &head) == FAIL);

slide-116
SLIDE 116

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synthesis

  • Completely lock-free operating system
  • Data structures and OS services build on compare and swap
slide-117
SLIDE 117

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Synthesis

  • Completely lock-free operating system
  • Data structures and OS services build on compare and swap
slide-118
SLIDE 118

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free vs wait-free

  • Lock-free not the same as wait-free
  • Lock-free, or non-blocking, allows starvation
  • Wait-free prevents starvation
  • Wait-free has higher cost
  • Authors argued improbability of starvation
slide-119
SLIDE 119

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free vs wait-free

  • Lock-free not the same as wait-free
  • Lock-free, or non-blocking, allows starvation
  • Wait-free prevents starvation
  • Wait-free has higher cost
  • Authors argued improbability of starvation
slide-120
SLIDE 120

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free vs wait-free

  • Lock-free not the same as wait-free
  • Lock-free, or non-blocking, allows starvation
  • Wait-free prevents starvation
  • Wait-free has higher cost
  • Authors argued improbability of starvation
slide-121
SLIDE 121

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free vs wait-free

  • Lock-free not the same as wait-free
  • Lock-free, or non-blocking, allows starvation
  • Wait-free prevents starvation
  • Wait-free has higher cost
  • Authors argued improbability of starvation
slide-122
SLIDE 122

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free vs wait-free

  • Lock-free not the same as wait-free
  • Lock-free, or non-blocking, allows starvation
  • Wait-free prevents starvation
  • Wait-free has higher cost
  • Authors argued improbability of starvation
slide-123
SLIDE 123

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free structures in Synthesis

  • Lists: insertion, deletion, traversal
  • Recognizes the problem of freeing elements currently in use
  • Uses reference counts to defer destruction
  • Stacks
  • Queues
slide-124
SLIDE 124

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free structures in Synthesis

  • Lists: insertion, deletion, traversal
  • Recognizes the problem of freeing elements currently in use
  • Uses reference counts to defer destruction
  • Stacks
  • Queues
slide-125
SLIDE 125

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free structures in Synthesis

  • Lists: insertion, deletion, traversal
  • Recognizes the problem of freeing elements currently in use
  • Uses reference counts to defer destruction
  • Stacks
  • Queues
slide-126
SLIDE 126

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free structures in Synthesis

  • Lists: insertion, deletion, traversal
  • Recognizes the problem of freeing elements currently in use
  • Uses reference counts to defer destruction
  • Stacks
  • Queues
slide-127
SLIDE 127

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free structures in Synthesis

  • Lists: insertion, deletion, traversal
  • Recognizes the problem of freeing elements currently in use
  • Uses reference counts to defer destruction
  • Stacks
  • Queues
slide-128
SLIDE 128

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free OS abstractions in Synthesis

  • Threads
  • Virtual memory
  • Console I/O
  • File system I/O
slide-129
SLIDE 129

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free OS abstractions in Synthesis

  • Threads
  • Virtual memory
  • Console I/O
  • File system I/O
slide-130
SLIDE 130

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free OS abstractions in Synthesis

  • Threads
  • Virtual memory
  • Console I/O
  • File system I/O
slide-131
SLIDE 131

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free OS abstractions in Synthesis

  • Threads
  • Virtual memory
  • Console I/O
  • File system I/O
slide-132
SLIDE 132

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-133
SLIDE 133

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-134
SLIDE 134

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-135
SLIDE 135

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-136
SLIDE 136

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-137
SLIDE 137

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-138
SLIDE 138

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Lock-free threading

  • Each thread has a Thread Table Entry (TTE)
  • Run queue for each priority
  • Fixed number of run queues
  • Allocates timeslices to queues in defined pattern

(0,1,0,2,0,1,0,3,. . . )

  • Uses compare and swap to mark a TTE as in-use
  • Other CPUs skip in-use TTEs
  • Thread operations (suspend, resume, signalling) use lock-free

flags in the TTEs

slide-139
SLIDE 139

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-140
SLIDE 140

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-141
SLIDE 141

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-142
SLIDE 142

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-143
SLIDE 143

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-144
SLIDE 144

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-145
SLIDE 145

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-146
SLIDE 146

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Compare and Double Swap

  • Two compare and swap instructions in one
  • Two old values, two new values, and two memory locations
  • Used for several key algorithms in Synthesis:
  • List element deletion
  • List traversal with reference counts
  • Stack array push
  • Thread signalling
  • Not supported on any modern architecture
slide-147
SLIDE 147

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-148
SLIDE 148

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-149
SLIDE 149

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-150
SLIDE 150

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-151
SLIDE 151

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-152
SLIDE 152

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available
slide-153
SLIDE 153

Locking a Linked List Implementing a Spinlock Atomic Instructions Linked list revisited Synthesis Summary

Summary

  • Need to protect shared OS structures
  • Synchronization abstractions build on atomic instructions
  • Cut out the middleman
  • Implement OS structures with atomic instructions
  • Achieves good performance
  • Compare and swap works well
  • Compare and double swap helps, but not generally available