linux - 中断子系统分析(1) -- GICv3硬件架构

目录

1. 参考文档

2. GIC Version History

3. Interrup Types

4. Interrupt State Machine

5. Programmer's Model

6. How interrupts are signaled to the interrupt controller

7. Affinity routing


引用博客:


1. 参考文档

  1. 《Cortex-A53 TRM》介绍了GIC CPU Interface
  2. 《ARMv8-A Architecture Profile》提供了GIC CPU Interface的细节
  3. 《GIC-500 TRM》介绍了GICv3的一个实现。https://developer.arm.com/docs/ddi0516/e
  4. 《GICv3/4 Architecture Specification》介绍了GIC架构细节规范。https://developer.arm.com/docs/dai0492/b

2. GIC Version History

3. Interrup Types

  • SGI: software generated interrupt 通过软件写寄存器来触发中断,通常用于多核间通信。
  • PPI: private peripheral interrupt 每个cpu core的石油中断。PPI会被送到指定的CPU上。
  • SPI: shared peripheral interrupt 公用的外部设备中断,也被称为共享中断,可以多个cpu处理。
  • LPI: locality-specific peripheral interrupt GICv3的新特性,是基于消息的中断,它们的配置保存在表中而不是在寄存器中。例如 pcie的MSI/MSI-x中断。

4. Interrupt State Machine

      The interrupt controller maintains a state machine for each SPI, PPI and SGI interrupt source. This
state machine consists of four states:

  注:LPIs没有这些状态。

  • Inactive: 中断源没有被触发。(即没有active, 也没有pending)
  • Pending: 中断源已经被触发,但是,还没有被CPU 应答。(即由于外设硬件产生了中断事件(或者软件触发)该中断事件已经通过硬件信号通知到GIC,等待GIC分配的那个CPU进行处理)
  • Active: 中断源已经被触发,并且,中断已经被cpu应答。
  • Active and Pending: 一次中断已经被应答,另外还有一次中断在pending中。

状态机关系

中断的生命周期

5. Programmer's Model

  • Distributor

SPI中断的管理,检测各个interrupt source的状态,控制各个interrupt source的行为,分发各个interrupt source产生的中断事件分发到指定的一个或者多个CPU interface上。虽然Distributor可以管理多个interrupt source,但是它总是把优先级最高的那个interrupt请求送往CPU interface

Distributor对中断的控制包括:
    (1)中断enable或者disable的控制。Distributor对中断的控制分成两个级别。一个是全局中断的控制(GIC_DIST_CTRL)。一旦disable了全局的中断,那么任何的interrupt source产生的interrupt event都不会被传递到CPU interface。另外一个级别是对针对各个interrupt source进行控制(GIC_DIST_ENABLE_CLEAR),disable某一个interrupt source会导致该interrupt event不会分发到CPU interface,但不影响其他interrupt source产生interrupt event的分发。
    (2)控制将当前优先级最高的中断事件分发到一个或者一组CPU interface。当一个中断事件分发到多个CPU interface的时候,GIC的内部逻辑应该保证只assert 一个CPU。
    (3)优先级控制。
    (4)interrupt属性设定。例如是level-sensitive还是edge-triggered
    (5)interrupt group的设定
      Distributor可以管理若干个interrupt source,这些interrupt source用ID来标识,我们称之interrupt ID。
 

  • Redistributor

PPI, SGI, LPI中断的管理,将中断发送给cpu interface。对于每个连接的PE,都有一个Redistributor.

该block的主要功能包括:
    (1)启用和禁用SGI和PPI。
    (2)设置SGI和PPI的优先级。
    (3)将每个PPI设置为电平触发或边缘触发。
    (4)将每个SGI和PPI分配给中断组。
    (5)控制SGI和PPI的状态。
    (6)内存中数据结构的基址控制,支持LPI的相关中断属性和挂起状态。
    (7)电源管理支持。
 

  • CPU Interface

传输中断给CPU core。

该block的主要功能包括:
    (1)enable或者disable CPU interface向连接的CPU assert中断事件。对于ARM,CPU interface block和CPU之间的中断信号线是nIRQCPU和nFIQCPU。如果disable了中断,那么即便是Distributor分发了一个中断事件到CPU interface,但是也不会assert指定的nIRQ或者nFIQ通知processor。
    (2)ackowledging中断。processor会向CPU interface block应答中断(应答当前优先级最高的那个中断),中断一旦被应答,Distributor就会把该中断的状态从pending状态修改成active或者pending and active(这是和该interrupt source的信号有关,例如如果是电平中断并且保持了该asserted电平,那么就是pending and active)。processor ack了中断之后,CPU interface就会deassert nIRQCPU和nFIQCPU信号线。
    (3)中断处理完毕的通知。当interrupt handler处理完了一个中断的时候,会向写CPU interface的寄存器从而通知GIC CPU已经处理完该中断。做这个动作一方面是通知Distributor将中断状态修改为deactive,另外一方面,CPU interface会priority drop,从而允许其他的pending的interrupt向CPU提交。
    (4)设定priority mask。通过priority mask,可以mask掉一些优先级比较低的中断,这些中断不会通知到CPU。
    (5)设定preemption的策略
    (6)在多个中断事件同时到来的时候,选择一个优先级最高的通知processor
 

  • ITS

interrupt translation service 用于解析LPI中断。

注:cpu interface是实现在core内部的,distributor,redistributor,ITS是实现在gic内部的。

GICv3的架构

  • SPI类型的中断需要 Distributor进行仲裁分发。

6. How interrupts are signaled to the interrupt controller

中断通知到中断控制器的两种方式:

1. 基于信号的(传统的方式,不便于添加或者修改中断。)

2. 基于消息的(新的方式,可减少中断线的个数,且在GICv3中,SPI可以基于消息的。)

7. Affinity routing

  • <affinity level 3>.<affinity level 2>.<affinity level 1>.<affinity level 0> 组成一个PE的路由。

       每一个core的affnity值可以通过MPDIR_EL1寄存器获取, 每一个affinity占用8bit.
       配置对应core的MPIDR值,可以将中断路由到该core上。

  • 各个affinity的定义是根据SOC自己的定义

       比如可能affinity3代表socketid,affinity2 代表clusterid, affnity1代表coreid, affnity0代表thread id.

  • 中断亲和性的设置的通用函数为irq_set_affinity。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值