linux-kernel - 当内核代码被中断时会发生什么?

标签 linux-kernel critical-section interrupt

我正在阅读《操作系统概念》(Silberschatz、Galvin、Gagne),第 6 版,第 20 章。 据我所知,Linux 内核代码是不可抢占的(2.6 版本之前)。但它可以被硬件中断打断。如果内核处于临界区中间并且发生中断并且它也执行了临界区,会发生什么?

根据我在书中读到的内容:

The second protection scheme that Linux uses applies to critical sections that occur in the interrupt service routines. The basic tool is the processor interrupt control hardware...

好的,当 ISR 有临界区时使用此方案。但它只会禁用进一步的中断。首先被这个中断中断的内核代码怎么样?

最佳答案

But it will only disble further interrupts. What about the kernel code which was interrupted by this interrupt in the first place?

如果中断处理程序和其他内核代码需要访问相同的数据,您需要防止这种情况的发生,这通常是由spinlock来完成的。 ,必须非常小心,你不想引入死锁,并且必须确保这样的自旋锁不会保持太长时间。对于硬件中断处理程序中使用的自旋锁,您必须在保持锁定的同时禁用该处理器上的中断 - 在 Linux 中这是通过函数 spin_lock_irqsave() 完成的。

(虽然有点过时,但您可以阅读有关概念 here )

关于linux-kernel - 当内核代码被中断时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152168/

相关文章:

c - setjmp.h 在内核空间中?

c++ - 使用 Windbg 进行临界区挂起分析

c - 通过中断例程的多个文件传递全局指针

c - 在 C 中访问进程的 PCB

performance - 我看不到用于测量功耗的 perf 的 power/energy-cores 选项

multithreading - 如何使用MFC CriticalSection?

c++ - 使函数异常安全

java - Java中的线程中断

java - 中断长工作线程

C结构还是函数?