Documente Academic
Documente Profesional
Documente Cultură
Synchronization
with material from
Understanding the Linux
Kernel (O’Reilly)
Past lectures:
¾ Synchronization constructs
Today’s lecture:
¾ What does this stuff look like in an OS?
¾ We have source code for Linux…
¾ We mostly run on x86 platforms
¾ Lets look at some specifics.
2
Disabling Interrupts
Key observations:
¾ On a uni-processor, an operation is atomic if no context-
switch is allowed in the middle of the operation
p
¾ Context switch occurs because of:
Internal events: system calls and exceptions
External events: interrupts
¾ Mutual exclusion can be achieved by preventing context
switch
4
Disabling Interrupts in Linux
6
Entering Linux
8
Scope of Synch Primitives
Atomic Operations
10
Memory Barriers
Spin Locks
12
R/W Spin Locks – space optimized data structure
Semaphores
14
Linux Use of Semaphores
15
Completions
Solving race condition with temporary Semaphores
free(S) up(S)
p( ) and free(S)
up(S) ( ) execute concurrently.
y
¾ lock only protects sleep queue, not whole semaphore
Lock protects entire Completion.
¾ Slower, but safer.
16
Local Interrupt Disable
local_irq_disable()/local_irq_enable()
¾ Disables and reenables interrupts
¾ Executes cli/sti on x86
But interrupts can be nested, so what interrupt
level to we return to?
¾ unsigned long flags;
¾ local_irq_disable(flags);
¾ …Read or update a data structure…
¾ local_irq_enable(flags);
Disable clears the IF flag of the eflags register,
and saves register in variable. Enable restores
previous register value.
17
18