linux-kernel - Linux 中 x86 架构的 IPI 种类

标签 linux-kernel x86-64 interrupt interrupt-handling smp

我想知道在 Linux 中可用于 x86_64 的不同类型的 IPI 有哪些。特别是,我想找出 IPI 中断的不同中断处理程序。

了解 Linux 内核,第 3 版,作者:Daniel P. Bovet,Marco Cesati https://www.oreilly.com/library/view/understanding-the-linux/0596005652/ch04s06.html 列出三种 IPI:

CALL_FUNCTION_VECTOR
RESCHEDULE_VECTOR
INVALIDATE_TLB_VECTOR

但是在最新的内核中,我在 arch/x86/include/asm/entry_arch.h 中找到了下面的注释。

 * This file is designed to contain the BUILD_INTERRUPT specifications for
 * all of the extra named interrupt vectors used by the architecture.
 * Usually this is the Inter Process Interrupts (IPIs)
 */

/*
 * The following vectors are part of the Linux architecture, there
 * is no hardware IRQ pin equivalent for them, they are triggered
 * through the ICC by us (IPIs)

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/include/asm/entry_arch.h?h=v5.6.15

有人可以确认文件中列出的所有向量是否都是 x86_64 的不同类型的 IPI。 对于 ARM,我可以为所有 IPI 找到一个统一的处理程序 - handle_IPI()。开关盒用于找出哪个 IPI。

最佳答案

在 x86 上,任何中断向量都可以由 IPI 触发,因此没有(或没有)指定的中断向量。

The IPI delivery mode and vector field

上图描述了用于发送 IPI 的寄存器的格式,Fixed 模式使用 Vector 字段使 objective-c PU 执行与相关的中断服务例程那个向量。这就像在目标中执行了一条 int vector 指令。

因此理论上,Linux 可以直接调用任何其他 CPU 上的任何中断。
然而,内核模块通常需要在特定的 CPU 上运行一个函数;所以 Linux 有一组实用函数,如 smp_call_function_single这将使程序员的生活变得轻松。
这些功能是通过一种机制实现的,它本身就值得一章,现在我不知道细节,但不难想象背后的基本思想:有一个要执行的函数的全局队列和一个中断向量,一旦被调用, 出列一个项目并执行它。
通过使用 IPI 调用该中断向量,Linux 可以使 objective-c PU 执行给定的函数。

您找到的中断向量用于此目的。您可能想在 entry_64.S 中查看它们的 64 位副本并在守卫 #ifdef CONFIG_SMP 之下。
acpiinterrupt and acpiinterrupt3只是用第二个参数定义标签的宏,用第一个参数(向量编号)调用 interrupt_entry NOTted 并调用第三个参数中指定的函数。
请注意,32 位模拟与目标函数名称进行了一些令人讨厌的前缀连接。

apicinterrupt CALL_FUNCTION_SINGLE_VECTOR call_function_single_interrupt smp_call_function_single_interrupt 大致等同于定义函数:

;Metadata stuff (e.g. section placement)

call_function_single_interrupt:               ;<-- first arg
  push ~CALL_FUNCTION_SINGLE_VECTOR           ;<-- second arg
  call interrupt_entry

  ;other stuff (tracing, flags, etc)
  call smp_call_function_single_interrupt     ;<-- third arg

  ;other stuff (like above, plus returning)

矢量编号在 irq_vectors.h 中定义当然,也用于 idt.c对于 IDT。

目标函数(中断处理程序)大部分(全部?我没检查)在smp.c 中定义它们可能是最接近 ARM 的 handle_IPI 处理程序的东西。

这些似乎是唯一通过 IPI 调用的向量。

关于linux-kernel - Linux 中 x86 架构的 IPI 种类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62068750/

相关文章:

c - Linux内核模式字符串复制

c - Linux 内核 : how to traverse physical pages in mem_map from user space using/dev/mem?

c - 读取另一个线程的寄存器或线程局部变量

架构 x86_64 : "function_name" referenced from 的 c++ undefined symbol

c++ - 32 位应用程序中的 64 位功能?

c - STM32 条件中断处理

Linux CFS(完全公平调度程序)延迟

android - fork() 返回现有进程的 pid

java - 无法在 Java 中停止线程

c - 在 C 中使用 BIOS 显示数据