中断处理程序使用哪个堆栈 - Linux [英] Which stack is used by Interrupt Handler - Linux

查看:18
本文介绍了中断处理程序使用哪个堆栈 - Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多任务系统中,当任何硬件对特定 CPU 产生中断时,CPU 可以执行以下任一情况,除非它已经在为 ISR 提供​​服务:

In a multitasking system when any hardware generates a interrupt to a particular CPU, where CPU can be performing either of below cases unless it is already serving a ISR:

  1. 用户态进程正在 CPU 上执行
  2. 内核模式进程正在 CPU 上执行

想知道在上述两种情况下中断处理程序使用哪个堆栈以及为什么?

Would like to know which stack is used by interrupt handler in above two situations and why ?

推荐答案

所有中断都由内核处理.这是由为该特定中断编写的中断处理程序完成的.对于中断处理程序,有 IRQ 堆栈.中断处理程序堆栈的设置是配置选项.内核堆栈的大小可能并不总是足以满足内核工作和内核所需的空间IRQ 处理例程.因此,2 堆栈出现了.

All interrupts are handled by kernel. That is done by interrupt handler written for that particular interrupt. For Interrupt handler there is IRQ stack. The setup of an interrupt handler’s stacks is configuration option. The size of the kernel stack might not always be enough for the kernel work and the space required by IRQ processing routines. Hence 2 stack comes into picture.

  1. 硬件 IRQ 堆栈.
  2. 软件 IRQ 堆栈.

与按进程分配的常规内核堆栈相比,每个 CPU 分配两个额外的堆栈.每当发生硬件中断(或处理 softIRQ)时,内核需要切换到适当的堆栈.从历史上看,中断处理程序没有收到自己的堆栈.相反,中断处理程序将共享正在运行的进程的堆栈,它们会中断.内核堆栈大小为两页;通常,在 32 位架构上为 8KB,在 64 位架构上为 16KB.因为在这种设置中,中断处理程序共享堆栈,所以它们必须非常节俭地分配在那里的数据.当然,内核堆栈开始是有限的,所以所有内核代码都应该谨慎.

In contrast to the regular kernel stack that is allocated per process, the two additional stacks are allocated per CPU. Whenever a hardware interrupt occurs (or a softIRQ is processed), the kernel needs to switch to the appropriate stack. Historically, interrupt handlers did not receive their own stacks. Instead, interrupt handlers would share the stack of the running process, they interrupted. The kernel stack is two pages in size; typically, that is 8KB on 32-bit architectures and 16KB on 64-bit architectures. Because in this setup interrupt handlers share the stack, they must be exceptionally frugal with what data they allocate there. Of course, the kernel stack is limited to begin with, so all kernel code should be cautious.

这篇关于中断处理程序使用哪个堆栈 - Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆