博客
关于我
中断管理基础学习笔记 - 5.2 ARM64高层中断处理
阅读量:174 次
发布时间:2019-02-28

本文共 2758 字,大约阅读时间需要 9 分钟。

gic_handle_irq 与 中断 处理流程

前言

本专题主要介绍ARM64架构下的中断管理机制,重点分析Linux内核中gic_handle_irq函数的处理流程。以下将从gic_handle_irq的实现细节、中断处理机制以及相关优化措施等方面展开讨论。

gic_handle_irq 函数

gic_handle_irq是ARM64体系结构下处理中断的核心函数。该函数主要负责从底层硬件中断处理进入内核中断处理逻辑,并通过调用handle_domain_irq完成中断的上下文切换。

gic_handle_irq 内部逻辑

gic_handle_irq的实现代码如下:

static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs){    struct gic_chip_data *gic = &gic_data[0];    void __iomem *cpu_base = gic_data_cpu_base(gic);    do {        irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK);        irqnr = irqstat & GICC_IAR_INT_ID_MASK;        if (unlikely(irqnr >= 1020))            break;        if (static_branch_likely(&supports_deactivate_key))            writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI);        isb();        if (irqnr <= 15)            smp_rmb();        this_cpu_write(sgi_intid, irqstat);        handle_domain_irq(gic->domain, irqnr, regs);    } while (1);}

while 循环退出条件

while (1) 循环的退出条件基于以下逻辑:当GIC的GICC_IAR寄存器中的所有位都为1时,中断处理完成,进入下一个中断处理阶段。

handle_domain_irq 调用

handle_domain_irq 是一个通用的中断处理函数,主要负责将硬中断转换为软中断,并根据中断类型(如SGI中断或普通中断)分别调用相应的处理函数。

handle_domain_irq 实现

int handle_domain_irq(struct irq_domain *domain, unsigned int hwirq, struct pt_regs *regs){    __handle_domain_irq(domain, hwirq, true, regs);    unsigned int irq = hwirq;    irq_enter();    irq = irq_find_mapping(domain, hwirq);    generic_handle_irq(irq);    irq_exit();}

中断处理流程

  • 读取GICC_IAR寄存器:通过readl_relaxed读取中断状态,完成中断的ACK操作。
  • 处理SGI中断:对于SGI中断(ID <= 15),执行taskletworkqueue等处理。
  • 调用domain的处理函数:将硬中断转换为软中断,并调用对应的中断处理函数。
  • irq_enter 与 irq_exit

    irq_enterirq_exit 分别用于进入和退出中断上下文。

    irq_enter

    void irq_enter(void){    rcu_irq_enter();    irq_enter_rcu();    if (is_idle_task(current) && !in_interrupt())    {        local_bh_disable();        tick_irq_enter();        _local_bh_enable();    }    __irq_enter();    account_irq_enter_time(current);    preempt_count_add(HARDIRQ_OFFSET);    __preempt_count_add(val);    u32 pc = READ_ONCE(current_thread_info()->preempt.count);    pc += val;    WRITE_ONCE(current_thread_info()->preempt.count, pc);    lockdep_hardirq_enter();}

    irq_exit

    void irq_exit(void){    __irq_exit_rcu();    local_irq_disable();    account_irq_exit_time(current);    preempt_count_sub(HARDIRQ_OFFSET);    if (!in_interrupt() && local_softirq_pending())    {        invoke_softirq();    }    tick_irq_exit();    rcu_irq_exit();    lockdep_hardirq_exit();}

    中断管理优化

    软中断管理

    local_softirq_pending 用于检查是否有软中断(如taskletworkqueue)等待处理。通过检查local_softirq_pending_ref,可以快速判断中断状态。

    中断上下文管理

    irq_enterirq_exit 函数通过修改preempt.count来管理中断上下文。preempt_count_addpreempt_count_sub 用于递增和递减硬中断计数,同时local_bh_disablelocal_bh_enable 用于管理软中断。

    总结

    通过分析gic_handle_irq函数及其相关处理流程,可以清晰地了解ARM64体系结构下的中断管理机制。从硬中断到软中断的转换,再到中断上下文的管理,都体现了Linux内核对中断处理的高效设计。

    转载地址:http://csqd.baihongyu.com/

    你可能感兴趣的文章
    nexus上传jar
    查看>>
    Nexus指南中的更新强调集成和透明度的重要性
    查看>>
    Nexus指南已经发布
    查看>>
    Nexus(1):Nexus的安装与配置
    查看>>
    NFinal学习笔记 02—NFinalBuild
    查看>>
    NFS
    查看>>
    NFS Server及Client配置与挂载详解
    查看>>
    NFS 服务配置篇
    查看>>
    NFS共享文件系统搭建
    查看>>
    nfs复习
    查看>>
    NFS安装配置
    查看>>
    NFS服务器配置-服务启动与停止
    查看>>
    NFS的安装以及windows/linux挂载linux网络文件系统NFS
    查看>>
    NFS的常用挂载参数
    查看>>
    NFS网络文件系统
    查看>>
    NFS远程目录挂载
    查看>>
    nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
    查看>>
    NFV商用可行新华三vBRAS方案实践验证
    查看>>
    ng build --aot --prod生成文件报错
    查看>>
    ng 指令的自定义、使用
    查看>>