zoukankan      html  css  js  c++  java
  • linux中软件触发中断SGI(IPI)的使用【转】

    转自:https://blog.csdn.net/qq_23274715/article/details/103524515

    软件触发中断SGI的使用
    什么是SGI
    SGI:软件触发中断(Software Generated Interrupt)。在arm处理器中,SGI共有16个,硬件中断号分别为ID0~ID15。它通常用于多核间通讯。SGI在Linux内核中通常被用作IPI中断(inter-processor interrupts).
    在linux内核中,已经定义了如下的IPI中断,所以用户使用自定义的IPI中断时,建议使用8~15这些未用的中断。

    //archarmkernelsmp.c
    enum ipi_msg_type {
    IPI_WAKEUP,
    IPI_TIMER,
    IPI_RESCHEDULE,
    IPI_CALL_FUNC,
    IPI_CPU_STOP,
    IPI_IRQ_WORK,
    IPI_COMPLETION,
    IPI_CPU_BACKTRACE,
    /*
    * SGI8-15 can be reserved by secure firmware, and thus may
    * not be usable by the kernel. Please keep the above limited
    * to at most 8 entries.
    */
    };

    linux驱动中如何使用SGI
    相关函数
    void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
    描述:释放一个软件中断
    mask: 使用cpumask_of(number),传递要控制的cpu.
    irq: 中断号。0~15.
    eg: gic_raise_softirq(cpumask_of(1), 14).给cpu1发送14号SGI.
    int set_ipi_handler(int ipinr, void *handler, char *desc)
    描述: 申请并设置SGI的中断回调函数。
    ipinr: 中断号。0~15。
    handler: 中断函数指针。需要的中断函数类型为void handler_name(void).
    desc: 名称。如"sgi14handler".
    return: 成功返回0.
    eg: set_ipi_handler(14, ipi_kick,"sgi14handler").
    clear_ipi_handler(int ipinr)
    描述: 清除申请的中断。
    ipinr: 中断号。0~15。
    eg: clear_ipi_handler(14).
    使用步骤
    在驱动初始化时使用set_ipi_handler()函数注册要使用的SGI中断号以及回调函数。
    在驱动卸载时使用clear_ipi_handler()函数注销。
    在驱动中合适的地方调用gic_raise_softirq()触发一个软中断。
    启动linux后,使用insmod挂载编写好的驱动。
    挂载成功后可以使用cat /proc/interrupts来查看中断是否申请成功。
    驱动的部分程序如下:

    /* 1. 使用的软件中断号 */
    #define REV_SGI_ID 14

    /* 2. sgi 回调函数,由set_ipi_handler()函数在初始化时回调 */
    static void ipi_kick(void)
    {
    printk("ipi_kick:%d ",++kickcount);
    }

    /* 3. 模块初始化部分程序 */
    static int __init char_init(void)
    {
    ...
    /* 申请加初始化软中断 */
    int ret = 0;
    ret = set_ipi_handler(REV_SGI_ID, ipi_kick,"Firmware kick");
    if(ret){
    printk("ipi(%d) error. ",REV_SGI_ID);
    }
    ...
    }

    /* 4. 模块注销部分程序 */
    static void __exit char_exit(void)
    {
    ...
    /* 注销中断 */
    clear_ipi_handler(REV_SGI_ID);
    ...
    }

    /* 5. 写函数部分程序,用户触发软中断使用 */
    static ssize_t char_write(struct file *filp,const char __user *buf,size_t cnt,loff_t *offt)
    {
    int revalue = 0;
    char tempbuff[2];

    revalue = copy_from_user(tempbuff,buf,2);
    if(revalue == 0){
    /* 触发软中断。
    1. eg: tempbuff[0] = 0,tempbuff[1] =14; 则触发cpu0的14号中断
    1. eg: tempbuff[0] = 1,tempbuff[1] =13; 则触发cpu1的13号中断
    */
    gic_raise_softirq(cpumask_of(tempbuff[0]), tempbuff[1]);
    }

    return 0;
    }

    关于技术交流
    此处后的文字已经和题目内容无关,可以不看。
    qq群:825695030
    微信公众号:嵌入式的日常
    如果上面的文章对你有用,欢迎打赏、点赞、评论。

    点赞 2
    ————————————————
    版权声明:本文为CSDN博主「theboynoName」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_23274715/java/article/details/103524515

  • 相关阅读:
    [转]nmake命令(windows下的makefile)
    [转]Visual Studio 2010 C++ 工程文件解读
    [转]开源库的编译
    强软弱虚引用试验
    ArtHas JVM在线排查工具
    JVM常用参数
    CMS两个常见问题
    jvisual vm连接
    jconsole连接
    JVM调优
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/12753298.html
Copyright © 2011-2022 走看看