Concurrency concerns within the Linux kernel
Recognizing critical sections within a piece of kernel code is of critical importance; how can you protect it if you can’t even see it? The following are a few guidelines to help you, as a budding kernel/driver developer, recognize where concurrency concerns – and thus critical sections – may arise:
- The presence of Symmetric Multi-Processor (SMP) systems (
CONFIG_SMP=y
) - The presence of a preemptible kernel (
CONFIG_PREEMPTION=y
) - Blocking I/O
- Hardware interrupts (on both SMP and/or UP systems)
These are critical points to understand, and we will discuss each in this section.
Multicore SMP systems and data races
This first point is pretty obvious; take a look at the pseudocode shown in Figure 12.6:
Figure 12.6: Pseudocode – a critical section (time t2 to t3) within a (fictional) driver’s read method; it’s potentially buggy as there’s no locking...