Try   HackMD

Linux Interrupt /Interrupt Service Routune (ISR)

Hardware Interrupt
Maskable Interrupt (multiplexing interrupts)
non-maskable interrupt,NMI (e.g., watchdog )

Software Interrupt, e.g., int 0x80~system call

Interrupt, ISR, top half, bottom half and multiplexing

入門級 Mouse Linux Kernel Driver
How to Write Linux Mouse Drivers, by Alan Cox
GPIO Linux Device Driver (GPIO Interrupt) – Linux Device Driver Tutorial Part 36
Using Kernel Timer In Linux Device Driver – Linux Device Driver Tutorial Part 26

SLR:

Code executing from interrupt context cannot do the following:

  1. Go to sleep or relinquish the processor
  2. Acquire a mutex
  3. Perform time-consuming tasks
  4. Access user space virtual memory

What if, I want to do a huge amount of work upon receiving interrupts? So it is a problem, right? If we take more time to process, this will happen.

While the highest priority ISR is running, it doesn’t let other interrupts to run.
Interrupts with the same type will be missed.
To eliminate that problem, the processing of interrupts is split into two parts or halves:

Top halves
Bottom halves

There are 4 bottom half mechanisms are available in Linux:

  1. Workqueue~ Executed in a process context.
  2. Threaded IRQs
  3. Softirq (最要不要使用這個, 除非真的需要)~Executed in an atomic context.
  4. Tasklets~Executed in an atomic context.

Atomic context is an execution state of the Linux kernel in which kernel code monopolizes a CPU core. In this state, the Linux kernel may only perform operations that cannot sleep, as otherwise a system hang or crash may occur.

linux/interrupt.h

struct softirq_action
{
void (*action)(struct softirq_action *); //softirq handler
};

enum
{
HI_SOFTIRQ=0,
TIMER_SOFTIRQ,
NET_TX_SOFTIRQ,
NET_RX_SOFTIRQ,
BLOCK_SOFTIRQ,
IRQ_POLL_SOFTIRQ,
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ,
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */

NR_SOFTIRQS
};

static struct softirq_action softirq_vec[NR_SOFTIRQS];