Synchronization/Overview

From Linux Kernel
Revision as of 02:36, 24 September 2016 by Kai (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Understanding the concurrency of contexts

Mainly, there are three types of contexts that any Linux kernel code runs.

  1. Hardware interrupt context (aka top half): Hardware interrupt handler that does not have any relation with current process. in_irq() is true.
  2. Software interrupt context (aka bottom half): Deferred handler such as softirq, tasklet, bottom half, timer, etc. in_softirq() is true.
  3. User context (aka process context): Code runs in the context of kernel mode or user mode processes. in_interrupt() is false.

The term 'interrupt context' is used for both hardware interrupt context and software interrupt context. In this context, in_interrupt() returns true.

Hardware interrupt context

When an interrupt happens, the kernel calls appropriate interrupt handler. While doing this, the kernel disables the interrupt line that is is serving. Thus the same interrupt handler is not executed simultaneously, also the interrupt handler cannot be nested.

  • An interrupt handler does not run simultaneously in multi-processor environment.
  • An interrupt handler is not reentrant.
  • An interrupt handler can be preempted by other interrupt handler.
  • Different interrupt handlers may run simultaneously.

Hardware interrupt handlers

If a data structure is used by only one interrupt handler, it does not need protection.

If a data structure is accessed by multiple interrupt handlers, it needs protection.

  • Use spin_lock_irq() variant.

Hardware interrupt and software interrupt

A hardware interrupt handler is not preempted by software interrupt handler in UP. However, they may run simultaneously in SMP.

= Interrupt

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox