首页 > 解决方案 > Linux 中 x86 架构的 IPI 类型

问题描述

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

在 Daniel P. Bovet 的《Understanding the Linux Kernel, 3rd Edition》中,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()。switch case 用于找出哪个 IPI。

标签: linux-kernelx86-64interruptinterrupt-handlingsmp

解决方案


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

IPI传递方式和向量场

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

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

您找到的中断向量用于此目的。您可能想在entry_64.S和 guard中查看它们的 64 位对应项#ifdef CONFIG_SMPand只是用第二个参数定义标签的宏,
用第一个参数(向量号) NOTted 调用并调用第三个参数中命名的函数。 请注意,32 位模拟会与目标函数名称进行一些讨厌的前缀连接。acpiinterruptacpiinterrupt3interrupt_entry

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中定义,它们可能是最接近 ARMhandle_IPI处理程序的东西。

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


推荐阅读